Archive for June, 2008

PHP Interacting with Google Maps - Points of Interest

Monday, June 30th, 2008

You need a key that will be bound to a domain.

Documentation

http://code.google.com/apis/maps/index.html

http://code.google.com/apis/maps/documentation/
http://code.google.com/apis/maps/documentation/staticmaps/

Interesting idea:

http://fullmeasure.co.uk/mashups/ecsitemap.htm

External Link

To find out the latitude and longitude of a point

  • Search for it on maps.google.com.
  • Be sure that is centered on the map.
  • In the address bar of the browser, insert this code:

    javascript:void(prompt(”,gApplication.getMap().getCenter()));

  • Press Enter

My code - A good example

This bit of code displays on the map all the points in the associative array called $points.

points_of_interest

PHP Obfuscator and Encoder

Monday, June 30th, 2008

Windows

http://www.raizlabs.com/software/phpobfuscator/

phpobfuscator_setup

Javascript - Confirmation Of a Link

Friday, June 27th, 2008

<a href=”#” onClick=”if( confirm(’Are you sure?’) ) document.location=’http://www.google.it/index.php?del={$points[index].pointID}’; return false;”>delete</a>

PHP - Display All The Defined Constants

Thursday, June 26th, 2008

get_defined_constants(true)

Identify a Font Face

Thursday, June 26th, 2008

http://www.myfonts.com/WhatTheFont/

http://www.identifont.com/

http://www.whatthefont.com

Linux - Getting Back a Deleted File

Wednesday, June 25th, 2008

You can get back deleted files if they are still loaded by any application. For example, let’s say I’ve deleted the file myfile by mistake but I have got it still open with vim. What I can do in order to have it back is as follows.

$ lsof | grep myfile
less 5000 dan 4r REG 3,65 23383 1433722 /home/dan/myfile (deleted)

The first column is the command associated with the process, the second column is the process id, and the fourth column is the file descriptor (the “r” means that it’s a regular file). Now you know that process 5000 still has the file open, and you know the file descriptor, that’s everything you have to know to copy it out of /proc. $ cp /proc/4158/fd/4 myfile.saved

Inspired by: http://www.linux.com/articles/58142

Linux - Search and Replace - Recursive and Over Multiple Files

Saturday, June 21st, 2008

find dir_name -exec perl -pi -w -e ’s/search_reg_exp/replace_reg_exp/g;’ {} \;

Be careful: search_reg_exp and replace_reg_exp are regular expressions then you may need to escape some special characters.

PHP - Run a script from the command line

Thursday, June 19th, 2008

You can do either:

  • php myscript.php
    In that case myscript.php will be like this:
    <?php
    echo "CIAO"
    ?>
  • ./myscript
    In that case myscript.php will be like this:
    #!/usr/bin/php
    <?php
    echo "CIAO"
    ?>

    In order to find out where the php executable lives, launch:
    which php

Remember to set the file as executable (chmod +x …)

Keep in mind that when the PHP interpreter is launched directly from the command line, a different configuration file (usually /etc/php5/cli/php.ini ) is used.

Automatic Batch Sftp With Expect

Wednesday, June 11th, 2008

Expect is a tool for automating interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, etc.

Expect FTP

This code helps use to understand how to use command line arguments and string concatenation with Expect and with any Tlc scripts.

/usr/bin/expect

# This line is if you want to use a file with the list of the commands.
# You'd need an authentication without password
# spawn sftp -b /home/daniele/Desktop/projects/pdf/script/cmdFile webdev@89.234.32.214

# This line is the simple login, instead
spawn sftp webdev@89.234.32.214
expect "assword:"

# You can send the password automatically if you feel confortable
# in writing it in this line
#send "My Password\n";

# Otherwise there is this more safe way (not automatic)
stty -echo
expect_user -re "(.*)\n"
send_user "\n"
send "$expect_out(1,string)\r"
stty echo

# At this point, we can expect two different replays
# depending if the password was correct or not.
expect {
# This line "catches" the case you write a wrong password
# In this case, we prefer to stop the process because the
# re-tried password could be output in cleartext
# Actually this issue could be handled in a better way
"ermission" {
puts "PLEASE, DON'T WRITE YOUR PASSWORD AGAIN"
puts "RE-RUN THE PROGRAM, INSTEAD"
exit
}
"sftp>" {
send "\n";
}
}
# Now the list of commands (in the case you are not using the first type of auth that is with the -b flag)
expect "sftp>"
send "cd /var/cc-pdfs/au-live/fault/\n";
expect "sftp>"
send "lcd /home/daniele/Desktop\n"

# command line argument
set in_arg [lindex $argv 0]
set get_command "get CC_$in_arg.pdf\n"
expect "sftp>"
send $get_command
expect "sftp>"
send "exit\n";

Firefox Plug-in Clear Cache Button

Wednesday, June 11th, 2008

Clear Cache Button

https://addons.mozilla.org/en-US/firefox/addon/1801