Monday, June 8, 2009

Build social applications on Facebook Platform

Building an app is easy

The web is social. Developers just like you have built applications on Facebook Platform that millions of people use everyday. Join developer community and help make the web even more social.

Go
Usefile link

Currency Exchange Rate from Europian Cental Bank (PHP)


// Define a context for HTTP.
$aContext = array(
'http' => array(
'proxy' => 'tcp://192.168.0.5:3128', // This needs to be the server and the port of the NTLM Authentication Proxy Server.
'request_fulluri' => True,
),
);
$cxContext = stream_context_create($aContext);

// Now all file stream functions can use this context.

//$sFile = file_get_contents("http://www.php.net", False, $cxContext);

//This is a PHP (4/5) script example on how eurofxref-daily.xml can be parsed

//Read eurofxref-daily.xml file in memory
$XMLContent= file("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml",False,$cxContext);
//the file is updated daily between 2.15 p.m. and 3.00 p.m. CET

foreach ($XMLContent as $line) {
if (ereg("currency='([[:alpha:]]+)'",$line,$currencyCode)) {
if (ereg("rate='([[:graph:]]+)'",$line,$rate)) {
//Output the value of 1 EUR for a currency code
echo '1 € = '.$rate[1].' '.$currencyCode[1].'
';

//--------------------------------------------------
// Here you can add your code for inserting
// $rate[1] and $currencyCode[1] into your database
//--------------------------------------------------
}
}
}
?>

csv file to an array

$row = 1;
$handle = fopen("test.csv", "r");
while ((
$data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo
"

$num fields in line $row:

\n"
;
$row++;
for (
$c=0; $c < $num; $c++) {
echo
$data[$c] . "
\n"
;
}
}
fclose($handle);
?>

Wednesday, June 3, 2009

Adding NTFS support to Linux

Usually most of the linux distributions come without NTFS support. For adding NTFS support to linux we use NTFS-3G driver. The NTFS-3G driver is a free and commercially available and supported read/write NTFS driver for unix-type (Linux) operating systems. It provides safe and fast handling of the Windows XP, Windows Server 2003, Windows 2000, Windows Vista, Windows Server 2008 and Windows 7 file systems.
The latest stable version of NTFS-3G can be found at http://www.ntfs-3g.org/

NTFS-3G uses FUSE lib ( Filesystem in Userspace ). FUSE provides set of functions to implement file system in a userspace program.
The latest version of FUSE can be found at http://fuse.sourceforge.net/

Installation:

Download NTFS-3G and FUSE from above links
Untar FUSE
Install fuse with following command

#./configure
# make
# make install

Untar NTFS-3G package then type

#./configure
# make
# make install

If there is no error in the installation, ntfs drive can be mounted in read/write mode
mount the drive with -t ntfs-3g option as follows:

# mount /dev/sda1 -t ntfs-3g /mnt/win

Tuesday, June 2, 2009

SSH connection PHP


define("SSH_IP", "127.0.0.1");
define("SSH_PORT", "22");
define("SSH_USER", "someuser");
define("SSH_PASS", "somepass");
define("SSH_IS_SET_FP", true); // true if set fingerprint
define("SSH_FINGER_PRINT", "123adfes54e5451254d587");

/**
* @package ssh modul class
* @author $Author: Lukas Mestan $
* @version $Id: class_ssh2.php,v 0.1.5 2008/12/12 15:58:15 Lukas Mestan Exp $
* @since v.0.1.5
* @copyright (c) Lukas Mestan
*/
class SSH2_Connect
{
/**
* Condition for command
* @var string
* @access private
*/
private $con=NULL;

/**
* Shell script to execute
* @var string
* @access public
*/
public $script="";

/**
* Array list of negotiated
* @var array
* @access public
*/
public $info=array();

/**
* Destructor
* @access public
* @return void
*/
function __destruct() {
if(function_exists('ssh2_disconnect')){
ssh2_disconnect($this->con);
}else{
@fclose($this->con);
unset($this->con);
}
return NULL;
}

/**
* Constructor - Conect to ssh
* @access public
* @return bool
*/
function __construct(){
if(!function_exists("ssh2_connect")){
throw new Exception("ERROR: Function ssh2_connect not exist");
}
if(!($this->con = ssh2_connect(SSH_IP, SSH_PORT))){
throw new Exception("ERROR: Invalid connect to ssh");
}else{
if(SSH_IS_SET_FP){
$fingerprint = ssh2_fingerprint($this->con, SSH2_FINGERPRINT_MD5 | SSH2_FINGERPRINT_HEX);
if($fingerprint != SSH_FINGER_PRINT){
throw new Exception("ERROR: Invalid hostkey hash");
}
}
if(!ssh2_auth_password($this->con, SSH_USER, SSH_PASS)){
throw new Exception("ERROR: Invalid authentification");
}else{
return true;
}
}
}

/**
* Returns list of negotiated methods.
* @access public
* @return array
*/
public function GetSSHInfo(){
$this->info = ssh2_methods_negotiated($this->con);
return $this->info;
}

/**
* Send File via ssh
* @access public
* @param string $from
* @param string $to
* @param string $chmod
* @return bool
*/
public function SendFile($from,$to,$chmod="0644"){
if(ssh2_scp_send($this->con, $from, $to, $chmod)){
return true
}else{
throw new Exception("ERROR: Could not send file");
}
}

/**
* Recive File via ssh
* @access public
* @param string $from
* @param string $to
* @return bool
*/
public function ReciveFile($from,$to){
if(ssh2_scp_recv($this->con, $from, $to)){
return true
}else{
throw new Exception("ERROR: Could not recive file");
}
}

/**
* Execute shell script (without output)
* @param string $script
* @access public
* @return bool
*/
public function SSH_Start_Script($script,$setnull=true){
$this->script =& strval($script);
if($this->script==""){
throw new Exception("ERROR: Parameters script is empty");
}
if($this->SSH_to_Connect()){
if(!($stream = ssh2_exec($this->con, $this->script.($setnull?" > /dev/null 2>&1":"")))){
throw new Exception("ERROR in ssh2_exec");
}else{
return true;
}
}else{
throw new Exception("ERROR: Invalid connect to ssh");
}
}
}

?>

LinkWithin

Related Posts with Thumbnails