Friday, August 29, 2008
Understanding a Crazy Programmer
Found this on the net. If you have any problems with a programmer in your team, this article/blog might help.
Learning Lisp - Do you know any programmers that exhibit these personality traits?
Tuesday, August 5, 2008
Catching Ctrl+C in Ruby 1.9
Ctrl+C sends a SIGINT signal to the kernel.
To catch it and execute code we use:
Remember to call Kernel.exit if you want to terminate the execution of your ruby script. Kernel.trap can also catch other signals. For more information visit: Kernel.trap
To catch it and execute code we use:
Kernel.trap('INT') { code }
Remember to call Kernel.exit if you want to terminate the execution of your ruby script. Kernel.trap can also catch other signals. For more information visit: Kernel.trap
Saturday, August 2, 2008
Storing Passwords securely
The best way to store a password: Salt it then Hash it.
To salt it add random characters to the password entered by the user. Remember we are going to need those random characters later so save them somewhere you can retrieve them later. I would say insert them in fixed locations in the hash. To hash it use the md5 or sha1 function. You can find these functions in the encode ruby extension.
To authenticate the user, you will need to pull the hash associated with the username, retrieve the salt characters, apply them to the password entered by the user, hash it and compare.
Is there a better way?
Tuesday, July 29, 2008
Terminal Awesomeness
The best way to make your desktop look nice is to add true transparency to your terminals. I got urxvt with true transparency enabled working with xcompmgr and it looks wonderful.
xcompmgr is a lightweight composite window manager.
urxvt is an xterm-like terminal lightweight and fast.
I'm using openbox as a window manager and hsetroot to set my desktop wallpaper. These are the contents of my ~/.config/openbox/autostart.sh :
hsetroot -fill ~/Desktop/desktop.jpg &
xcompmgr &
rxvt &
docker &
"docker" takes care of the system tray.
To enable transparency in urxvt you need to add these lines to your ~/.Xresources file:
URxvt*depth: 32
urxvt*background: rgba:0000/0000/0000/cccc
URxvt*background: rgba:0000/0000/0000/cccc
URxvt*foreground: green
Change the background and foreground to whatever color you want.
I believe desktop managers like kde or gnome are overrated. Openbox is great and doesn't consume your precious resources so u can use them for more important things like compiling code.
Friday, July 25, 2008
More VIM stuff
Set tab size:
set tabstop=2
Quick Write and quit
:wq
If you press Ctrl+S while on a terminal and it freezes then press the following to unfreeze:
Ctrl+Q
Working with tabs
:tabe file # Opens File
:tabn # goes to next tab
:tabp # goes to previous tab
:q # closes current tab
gt # will take you to the next tab
gT # will take you to the previous tab
Auto completion
Ctrl+N Ctrl+P
You can also invoke make and grep within vim
:grep args
:make
If you work on windows (gvim.exe) place your vimrc file in the VIM exe directory. You might need to set the environment variable VIM to the path where gvim.exe. Name your vimrc file as _vimrc
Moving to VIM
I decided to make vim my default text editor. Here are a couple of tips:
To get syntax highlighting in vim, add the following to your ~/.vimrc file or enter while editing (command mode, remember to press ':' before entering):
set background=dark # if your console background is dark..
syntax on
To get line numbers:
set nu
To split the screen in 2
split
vsplit # Vertical Split
To Move from split windows
Ctrl+W+(direction)
Open a file
open file
Close a file
close
Search Reg Ex
/regex
Goto Line Number
:number
Search word under cursor
*
I will post more eventually... vim kicks emacs butt by the way.
Friday, July 18, 2008
Ruby 1.9 C API - Object Instances
To Create a new instance of an object with class Class we will do this:
VALUE obj;
obj = rb_obj_alloc(Class); // Allocate space and create new instance
rb_obj_call_init(obj, 0, 0); // We call the initialize method for the object
Remember rb_obj_alloc() does not initialize the object and will seg fault if you use any custom data types in the object.
The 2nd and 3rd parameters of rb_obj_call_init() are the argument count (argc) and the constructor parameters array ( VALUE* ).
Subscribe to:
Posts (Atom)