Tuesday, June 21, 2011

sha2 encryption in ruby

require 'digest/sha2'; hash = Digest::SHA2.new; hash << "text to encrypt"; hash.to_s

<< basically adds the parameter to the object. 'f' << 'oo' # -> 'foo' and [1] << 2 # -> [1,2]

but it might be a left shift also ;) 2 << 3 # -> 16
it shifts the bit representation of a number. 0b001 << 1 # -> 0b010
with 0b001 == 1 and 0b010 == 2

Thursday, May 26, 2011

Web Developer Tools

General debugging tools:
Firebug -
Popular Firefox extension for web developers.
Web Developer - Another Firefox extension containing good set of tools.
JS Deminifier - Good for expending minified JS.
Firecookie - Cookie manager for Firebug.
JS beautifier -
Reformats JavaScript source code to make it more readable.
JS beautifier2 - Reformats JavaScript source code.

Web Application Testing Frameworks:
Watir - Ruby based framework for browser automation. examples
Webdriver - Browser automation framework.

Friday, May 6, 2011

Create Rails project with any version

gem list
rails (3.0.5,2.3.11)

rails -v
Rails 3.0.5

#Create a rails project with version 2.3.11
rails _2.3.11_ MyProject

Monday, February 7, 2011

MySql dump with Cronjob

0 0 * * 0 /usr/bin/mysqldump -uroot -p'PASS' DBName > /path/DB_backup/$(date +\%Y-\%m-\%d_\%Hh\%M).sql

example output file:
2011-02-06_00h00.sql

Wednesday, September 15, 2010

Sym Link to multiple CIFS mounts

A simple script that creates sym links to multiple cifs mounts and dumps them into a master folder.


#!/bin/bash

DIR="/media/MDrive/"
DIR2="/media/ZDrive/"
DIR3="$DIR $DIR2"
DIR4="masterDownloads"
#echo $DIR3

IFS=$'\n'

#for i in $(find $DIR -type f -printf "%f\n")
for i in $(find $DIR -type f)
do
echo "Processing... $i"
mkdir -p ./$DIR4/$(dirname $i)
ln -s $i ./$DIR4$i
clear
done