21 Jan

Firefox 3.6 with full HTML 5 API support

As the latest firfox came up was were happy to read the below in there site :

"Currently, an entirely new spec is being drafted for file objects and handling within HTML5. It will provide a much more robust interface for accessing content in local files, in addition to extending functionality for file objects within Javascript/DOM. The primary additions include:

* Drag n' drop of local files into a web page.
* Asynchronous file data access via callback methods.
* Sending file objects via XMLHttpRequest.

19 Jan

MySQL DB Synchronization.

in

DB replication/reflection is on the most import process while achieving a distributed system, which helps in the DB synchronization between remote hosts.

The concept is pretty simple :

1.Setting up the Master.

2.Setting up the Slave.

3.Let the Slave receive events from master and update DB.

Synchronize remote hosts

  1. A simple script to sync remote hosts, steps to achieve it :
  2.  
  3. 1.Avoid SCP prompting for password [ local host ] =>
  4. ssh-keygen -t dsa -b 2048 -f ~/key.pub
  5.  
  6. 2.SCP the key for the first time to the [ remote host ] =>
  7.  
  8. scp ~/key.pub remoteuser@remotehost:/home/remoteuser/
  9.  
  10. 3. In remote host :
  11. [ Authorize the Host from which key was received ]
  12.  
  13. if [ ! -d .ssh ]; then
  14. mkdir .ssh
  15. chmod 700 .ssh
  16. fi
  17. mv key.pub .ssh/
  18. cd .ssh/
  19. if [ ! -f authorized_keys ]; then
  20. touch authorized_keys
  21. chmod 600 authorized_keys ;
  22. fi
  23. cat key.pub >> authorized_keys

Send mail to Gmail programatically with Python

  1. #!/usr/bin/python
  2.  
  3. import smtplib
  4. from email.MIMEMultipart import MIMEMultipart
  5. from email.MIMEBase import MIMEBase
  6. from email.MIMEText import MIMEText
  7. from email import Encoders
  8. import os
  9.  
  10. gmail_user = "xyz@gmail.com"
  11. gmail_pwd = "*******"
  12.  
  13. def mail(to, subject, text,
  14. attach=[]):
  15. msg = MIMEMultipart()
  16.  
  17. msg['From'] = gmail_user
  18. msg['To'] = to
  19. msg['Subject'] = subject
  20.  
  21. msg.attach(MIMEText(text))
  22.  
  23. for file in files:
  24. part = MIMEBase('application', "octet-stream")
  25. part.set_payload( open(file,"rb").read() )
  26. Encoders.encode_base64(part)

Reseting htpasswd with PHP

<?php

function load_htpasswd($file)
{
    if(
file_exists($file) && filesize($file) > 0)
    {
        
$htpasswd file($file);
        
$auth = array();
        foreach(
$htpasswd as $h)
        {
            
$array explode(':',$h);
            
$user $array[0];
            
$pass chop($array[1]);
            
$auth[$user] = $pass;
        }
        return 
$auth;
    }
    else
        return array();
}

function 
sha1_htpasswd($pass)
{
    return 
'{SHA}' base64_encode(pack('H*'sha1($pass)));
}

function 
valid_user($userpass$user$pass){

    if(!isset(
$userpass[$user])){
        echo 
"User Password is not set.?>
06 Jan

Synchronizing SVN with an HTTPS URL

Creating a read-only mirror of a repository from a HTTPS which is in sync helps to maintain an local repo which is in sync with the global and is much faster and reliable for a group working locally.
Achieving this is pretty simple,svnsync - Subversion repository synchronization tool which makes the job easier.

The idea is pretty simple, the steps followed are :

1.Setting up a mirror repository.
2.Initialize (init) the sync.
3.Synchronizing the data.
4.Making a sync job.

Setting up a mirror repository:

#Create a mirror repository

31 Dec

Generic file extracter

Simple but effective and handy utility for people dealing with hell lot of zips.

# Test if the program is installed
type -P $1 &>/dev/null || echo $1 not installed! ; exit 1;
# Try to extract
Switch for the appropriate case.

Check out the attached file, place it in /usr/bin or any appropriate location with the PATH exported for the same.

24 Dec

Bash made better with shopt

1.Enable automatic typo correction for directory names
shopt -s cdspell
Testing

hemanth@ubuntu:/var/log$ cd /tp
/tmp
hemanth@ubuntu:/tmp$

hemanth@ubuntu:/$ cd /hom
/home
hemanth@ubuntu:/home$

hemanth@ubuntu:/home$ cd /mt
/mnt
hemanth@ubuntu:/mnt$

2.Enable ** to expand files recursively (>=bash-4.0)
shopt -s globstar
3.Avoiding history file to be overwritten
shopt -s histappend
4.Enable cd by variable names
shopt -s cdable_vars

24 Dec

Auto completion in Bash for Maven

Step 1 : Check if bash_completion in enabled in your .bashrc.
Step 2 : Add the file attached to /etc/bash_completion.d/m2.
Step 3 : Enjoy auto-completion for Maven.

The Code Lines :
complete -F _m2_complete -o filenames mvn Indicates to apply _m2_complete for command following mvn
compgenGenerate possible completion matches for word according to the options.

12 Dec

Plotting performance graph of a GNU/Linux box

in

Easy and fun
Things needed :
dstat
GNUPlot
This post, is not elaborating on dstat or GNUplot but rather focusing directly on how to plotting performance graph of a GNU/Linux box.

I have written a small script to plot the performance of the machine considering CPU,Memory and Network into picture.

#!/bin/bash