Archive for the 'Code' Category

Get the Plain Text Version of a Web Page

This command fetches a web page, converts it to text and shows it.


lynx -dump http://www.example.com/

Share Current Folder over the Web

Want to show something on your machine to someone over the web? Don’t copy it or upload it somewhere. Just run “webshare” and the current directory and everything beneath it will be served from a new web server listening on port 8000. When your pal is finished, hit control-c.


python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"

For a slightly more advanced version of this server, see this article(Warning: German Article - but code is self explaining)

Perl Joke

Just a joke - no offense intended…


perl -e '$a="etbjxntqrdke";$a=~s/(.)/chr(ord($1)+1)/eg;print $a'

A Shell Script to Create a Build of Firefox Extension

This shell script will create a build of a firefox extension in linux. This is created according to my details(eg, the guid has @binnyva.com in it) - but you can modify it and use it yourself.


app=$1
folder=$2

if [ $# -eq 0 ] ; then
	echo "Useage: sh build.sh  []"

elif [ $# -eq 1 ] ; then
	folder="$1@binnyva.com/"
fi

rm $app.xpi
cp -r $folder temp
cd temp
rm -rf .git

zip -r $app.xpi .>/dev/null
mv $app.xpi ..
cd ..
rm -rf temp
echo "Built $app successfully"

Force Download Dialog with PHP using octect-stream

Use this code to force a download of any type of content with PHP


header("Content-type:application/octect-stream");
header('Content-Disposition: attachment; filename=filename_' . date('Y-m-d') . '.sql');
print "Hello World";

Creating a SVN Tag

Creating a tag in SVN means that you copy the entire trunk to another folder in the ‘tags’ folder…


svn copy trunk/ tags/TAG_NAME

Install CPAN in Fedora

If you are getting a ‘Can’t locate CPAN.pm in @INC’ error while opening cpan, you have not installed Bundle::Cpan. You can do that without Cpan - using yum


yum install perl-CPAN

Remove Empty Lines and Comments

Remove comments and blank lines from example.pl


sed '/ *#/d; /^$/d' example.pl

Merging a Branch with the Master Branch in git

The commands needed to merge two branches in git.


git checkout master
git merge BrachName
git commit -m "Merged" -a

Stop crond When mysqld is Down

A perl script to stop crond if mysqld is down


#!/usr/bin/perl

# See if MySQL server is alive or not
$mysql_status = `/etc/init.d/mysqld status`;
print "MySQL Status: $mysql_status\n";
unless($mysql_status =~ /running/) {
	print "Stopping Cron... ";
	#If MySQL is not running, kill the crond
	$cron = `/etc/init.d/crond stop`;
	print $cron;
}

print "\n";