Archive for 2010 March

  • PERL: How to remove an element from hash or array?

    2010
    29
    Mar

    In order to remove an element from the array or hash, we have to use the delete keyword on perl. Using the delete keyword on the key of the hash or array (numeric keyed hash), we can delete elements of a hash or array.

    Example for deleting an element from a hash

    The following code deletes the key 'a' from the hash

    %hash

    .

    #!/usr/bin/perl
    $, = "\n"; # Fields separator
    my %hash = (
    'a' => 'aaa', 
    'b' => 'bbb',
    'c' => 'ccc',
    );
     
    print %hash;
    delete $hash{a}; #key value pair 'a' => 'aaa' would be deleted
    print %hash;

    Read More

  • Resolve Net::MySQL Hang problem if the database result has only 1 row or is empty

    2010
    26
    Mar

    Net::MySQL is a simple MySQL perl Client to connect to MySQL servers. But Net::MySQL hangs if your result set is having just one row.

    Sample Net::MySQL code

    #!/usr/bin/perl
     
    use Net::MySQL;
     
    $mysql = Net::MySQL->new(
    	hostname => 'localhost',
    	database => 'db',
    	user     => 'user',
    	password => 'password',
    );
     
    $gid = 1;
     
    $mysql->query('SELECT * FROM table WHERE id = 1');
     
    if ($mysql->has_selected_record) {
    	my $record_set = $mysql->create_record_iterator;
    	while(my $record = $record_set->each) {

    Read More

  • Solve Write Permission Denied on Files Windows 7

    2010
    26
    Mar

    Windows 7 file attributes and earlier versions of windows such as XP or 98 is very different. The difference is notable if you use NTFS file system which has more security features.

    On Windows 7 if you get "Write Permission Denied" on any file ,

    • Right Click > Properties
    • On the security tab, click on edit as highlighted in the screenshot below :
      Security Tab Solve Write Permission Denied
    Read More

  • How to Prevent my Computer from going to sleep when I am running big process ?

    2010
    25
    Mar

    By default on Windows 7, the computer sleeps after 30 minutes. Usually power plans and options are more required on laptops, but desktops also do use this setting. This is bad if you want to run some process which has to run for a long time like downloading from the internet or running torrents or running huge scripts. If you leave your computer unattended the computer sleeps after 30 minutes. This interrupts the process.

    In order to change the power settings, and to Prevent my Computer from going to sleep ,

    • Goto Control Panel\System and Security\Power Options
    Read More

  • Free Light weight Social media sharing javascript for Facebook, Twitter, Stumble Upon, Digg and Reddit

    2010
    25
    Mar

    Social Media Buttons or buttons that help you share the content on bookmarking websites such as Stumble Upon, Reddit or Digg or social networking Websites such as Facebook or Twitter. Adding the buttons helps you to expose your content to a broader audience.
    There are lots of social media button providers such as AddThis or ShareThis. I think it is overloaded with features that makes your page load slow as well as bring in unintentional 3rd party javascript code ( or flash tracker ) which runs on your blog.

    Read More

  • Error Installing PERL modules "unrecognized command line option -fstack -protector"

    2010
    24
    Mar
    4

    unrecognized command line option "-fstack-protector" error usually comes on Cygwin when installing PERL modules.
    For example when installing the DBI module or DBD::MySQL perl module, the following error comes on cygwin :

    cp lib/DBI/Gofer/Serializer/Base.pm blib/lib/DBI/Gofer/Serializer/Base.pm
    cp dbipport.h blib/arch/auto/DBI/dbipport.h
    cp lib/DBI/Gofer/Execute.pm blib/lib/DBI/Gofer/Execute.pm
    cp lib/DBI/DBD.pm blib/lib/DBI/DBD.pm
    cp lib/Win32/DBIODBC.pm blib/lib/Win32/DBIODBC.pm
    cp lib/DBI/PurePerl.pm blib/lib/DBI/PurePerl.pm

    Read More

  • Sprintf Function in Python

    2010
    21
    Mar

    The printf or sprintf function is used to format strings in PHP and C programming constructs. sprintf in php returns the formatted string whereas printf just prints the output.

    $variable = sprintf("%d %s %d = %d",4,"+",5,9);
    print $variable;
    //OR
    printf("%d %s %d = %d",4,"+",5,9);
     
    //Both lines are identical.
    //Prints 4 + 5 = 9

    On python, sprintf is handled using an operator instead of function. The % operator on a string does formatting.

    var = '%d %s %d = %d' % (4,'+',5,9)

    Read More

  • Enable two finger flick Forward and Back in Synaptics

    2010
    19
    Mar

    Two finger flick is a gesture that is used to move forward and backword in applications such as photo viewer software or a browser. This is a feature similar to the one available in Mac which is two touch scrolling. This post describers how to enable two finger flick on Windows just like in Macintosh.

    Two-Finger Flick

    Read More

  • Solve "Cannot modify header information - headers already sent by *.php"

    2010
    17
    Mar


    Warning: Cannot modify header information - headers already sent by somefile.php (output started at somefile.php:###) in somefile.php on line ###

    This Warning is shown by PHP when you use the header function to output headers or use the setcookie function to set cookies after any echo or content which is not inside PHP tag.

    echo "Hello World";
    header("Location: /redirect.php");

    Hello World !!! 
    <?php header("Location: /redirect.php");?>

    Read More

  • Change Network adapter MAC address on Windows 7

    2010
    15
    Mar
    1

    Most of us (atleast those who learned computer networking) grew up learning about the 7 layers of OSI ISO model or the simple 4 layer model. The lowest layer is the physical layer. In this layer all machines are assigned an address called the MAC address (Media Access Control Address) . The MAC Addresses come pre-assigned in the hardware and it is assigned by a standard authority so that the MAC addresses does not collide. Most of us thought we cant change it, but yes we can change the MAC address.

    Read More