Archive for the 'Code' Category

Double space a file using Ruby

Double space a file with Ruby using the command

ruby -pe 'puts' < file.txt

git push

Command to push the current repository in git to a online server

git push

Sort by Line Length

Sort file by line length. Original Article…

cat /etc/passwd | awk '{print length, $0}' | sort -n | awk '{$1=""; print $0 }'

Change shell

Change shell command


Random Password in PHP

A simple way to create a random password in PHP

$password = substr(md5(time()), 0, rand(4,8));

Finding the Factorial using Recursion

Finding the Factorial using Recursion in javascript.

function factorial(x) {
	if(x <= 1) return 1;
	return x*factorial(x-1);

Download Multiple URLs

Command to download a series of urls with zero padding files…

for ((i=1;i<20;i++))
do wget "`printf "%02d" $i`.jpg"; done

Remove www From URL using .htaccess in Apache

This htaccess code will remove the ‘www’ part from the url. It uses the mod_rewrite module of apache to re-write the url – so make sure that’s installed.

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

Remove a Folder from Git

Remove a given folder from a Git repository…

git rm -r cache/

Remove SVN Info from a Folder

This command removes the SVN data from a folder.

find -name .svn -exec rm -rf {} \;