Adsense

Saturday, April 9, 2016

A simple Python program that reads a textfile and creates 2-level folder structure based on the contents of the textfile



import os, sys

# If directory (path) doesn’t exist, create it
def createPath(path):
   if not os.path.isdir(path):
      os.mkdir(path)

f = open(r"F:\Folders.txt")

folder = "F:\\Documents\\"

## Read the first line
line = f.readline()

## If the file is not empty keep reading line one at a time till the file is empty

i=1
while line:
    #print(line)
    for char in '\n?.!/;:':
       line = line.replace(char,'')
    position = line.find("*")
    if position == 0:
      #print("line is {}" .format(line[1:]))
      folder2 = folder + str(i) + "." + line[1:]
      print(folder2)
      createPath(folder2)
      j=1
      i=i+1
    else:
      if len(line.strip()) != 0:
        folder3 = folder2 + "\\" + str(j) + "." + line
        print(folder3)
        createPath(folder3)
        j=j+1
    line = f.readline()
f.close()

Pin It

Thursday, February 12, 2015

Basic Skeleton for using the Facebook PHP SDK v.4.4.0


 

<? session_start();

require_once( 'Facebook/FacebookSession.php' );
require_once( 'Facebook/FacebookRedirectLoginHelper.php' );
require_once( 'Facebook/FacebookRequest.php' );
require_once( 'Facebook/FacebookResponse.php' );
require_once( 'Facebook/FacebookSDKException.php' );
require_once( 'Facebook/FacebookRequestException.php' );
require_once( 'Facebook/FacebookAuthorizationException.php' );
require_once( 'Facebook/GraphObject.php' );

use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;

// init app with app id (APPID) and secret (SECRET)
$appID = 'YOUR_APP_ID';
$appSecret = 'YOUR_APP_SECRET';
$appLoginURL = 'https://YOUR_APP_LOGIN_URL';
$appLogoutURL = 'https://YOUR_APP_LOGOUT_URL';

FacebookSession
::setDefaultApplication($appID, $appSecret);

$helper = new FacebookRedirectLoginHelper($appLoginURL ); // login helper with redirect_uri

try
{
$session = $helper->getSessionFromRedirect();
}
catch( FacebookRequestException $ex )
{
// When Facebook returns an error
}
catch( Exception $ex )
{
// When validation fails or other local issues
}


if ( isset( $session ) ) // see if we have a session
{
$request = new FacebookRequest( $session, 'GET', '/me' ); // graph api request for user data
$response = $request->execute();

$graphObject = $response->getGraphObject(); // get response
$graphObject_keys = array("id", "email", "first_name", "last_name", "gender", "link", "locale", "name", "timezone", "updated_time", "verified");
for ($i=0; $i<count($graphObject_keys); $i++){
echo $graphObject_keys[$i] . " : " . $graphObject->getProperty($graphObject_keys[$i]) . "<br/>";
}

$logoutURL = $appLogoutURL . '">Logout</a>';
echo '<a href="' . $helper->getLogoutUrl( $session, $logoutURL);
}
//end if
else
{
echo '<a href="' . $helper->getLoginUrl() . '">Login</a>'; // show login url
} //end else

?>
Pin It

Saturday, August 10, 2013

How to remove “Shared Folder Synchronization” from Windows 7 context menu


  1. Click “Start->Run->cmd” to open up a command prompt window
  2. Type the following commands in the command prompt
    cd C:\Program Files\Microsoft Office\Office14\
    regsvr32 /u GROOVEEX.DLL

  3. You should see the above "success" message to inform you that the DLL has been unregistered and you should no longer see the "Git" menu items on your context menu






Figure 1: Shared Folder Synchronization menu item still enabled
2013-08-11_114740
Figure 2: Deregistering the GrooveEx.dll file
2013-08-11_115505
Figure 3: Shared Folder Synchronization menu item no longer in context menu items
2013-08-11_115653

Pin It

How to remove “Git” from Windows 7 context menu


  1. Click “Start->Run->cmd” to open up a command prompt window
  2. Type the following commands in the command prompt
    Technorati Tags: ,,

    2013-08-11_113714

  3. You should see the above "success" message to inform you that the DLL has been unregistered and you should no longer see the "Git" menu items on your context menu
Pin It

Saturday, March 2, 2013

HOWTO in PHP: Retrieve a list of Facebook Pages you are the Administrator of using Graph API


Here's the code. I am assuming here that you have already logged in as a valid Facebook user with the "manage_pages" scope permission.

<?php

require_once("fbphpsdk/facebook.php");

$config = array();
$config['appId'] = 'YOUR_APP_ID';
$config['secret'] = 'YOUR_APP_SECRET';
$config['fileUpload'] = false; // optional

$facebook = new Facebook($config);

$uid = $facebook->getUser();
$accesstoken = $facebook->getAccessToken();
$params = array('access_token' => $accesstoken);

if ($uid) {
    try {
        $userprofile = $facebook->api('/me','GET');
        echo "Name: " . $userprofile['name'];
        $accounts = $facebook->api('/me/accounts', 'GET', $params);
        foreach($accounts['data'] as $account)
        {
           echo "<hr/>" . $account['name'] . " " . $account['id'] . "<br/>";
        }//end foreach
    }
    catch(FacebookApiException $e) {
        echo "Error accessing Facebook data";
    }   
}
else {
    echo "You are not logged in";    
}
?>

And here's the sample output generated by the code above when I logged in using my Facebook account

Pin It

Friday, March 1, 2013

How to get the Page ID of a Facebook Page from its username


It is very easy


Just type this in the addressbar of your browser and press enter.
http://graph.facebook.com/<pageurl>/

E.g. when I type the following URL of my own Facebook Page, I yield the results as in Figure 1 below.
http://graph.facebook.com/dorathetechplorer/ 

Hence, the Page ID of my page would be "157472464323620".
Figure 1: Output from typing "http://graph.facebook.com/dorathetechplorer"
Pin It

Sunday, January 13, 2013

How to retrieve posts from Facebook Page using Facebook Graph API and php


Here's a simple php script that will split out the latest 100 posts from a given Facebook Page.

Note that you will need to modify the code at lines 1 and 2 by:

Have fun trying it out! :)


<? 
 $access_token="&access_token=YOUR_ACCESS_TOKEN_HERE";
 $pageid="THE_PAGE_ID";
 $graph_query_url="https://graph.facebook.com/" . $pageid . "?fields=posts.limit(100)" .  $access_token;
 $graph_query_result = @file_get_contents($graph_query_url);
 $graph_query_obj = json_decode($graph_query_result,true);
  
 foreach($graph_query_obj[posts][data] as $p)
 {
    echo $p[from][name] . "<br/>";
    if ($p[story]) echo $p[story] . "<br/>";
    if ($p[message]) echo $p[message] . "<br/>";
    if ($p[picture]) echo "<img src='" . $p[picture] . "'><br/>";
    if ($p[likes][count]) echo "Likes:" . $p[likes][count] . "<br/>";
    echo date("Y-M-d D h:m",strtotime($p[created_time])) . "<br/>";
    echo "<hr/>";
 } // end foreach
?>
Pin It