Upload recipe using Net::SCP
Sharing a simple ruby recipe to automate uploads of static website, if rsync is giving you problems(like with my school web server). This script uses Net::SCP.
Net::SCP is a pure-Ruby implementation of the SCP protocol. This operates over SSH (and requires the Net::SSH library), and allows files and directory trees to copied to and from a remote server.
This solution lies somewhere between manually uploading and fully automation using Capistrano or Vlad.
November 1, 2009 1 Comment
Thinking of PHP, Apache, Ruby, MySQL and Unicode
In the last post, I mentioned meeting my old pal Tux.
Now back to coniguring the machine. I will be using the test server for Drupal websites, Rails projects and possibly Lift projects. Also, I love Punjabi and I love Unicode. So I’m going to try to make things as Unicode friendly as they can be.
Let’s start.
February 27, 2009 3 Comments
Jukebox in a single line
If you are like me, who starts starts iTunes with default library and realize you have heard the same song 8 times in the last week, here are two one-line-Jukebox scripts for you. The scripts randomly choose and play songs right from the command line.
Before using the script make sure you have an mp3 player installed. I have installed lightweight mpg123, however you can use any player. I would recommend mplayer for Linux.
While running the scripts, I pass ~/Music folder argument. Change the path to point to folder where you store your mp3s.
First one is in Ruby, and shamelessly inspired by Kevin Baird’s book.
Open a text editor and save this script. I named it shuffle_play.rb. (You need to have ruby installed on your system. Installed on Leopard and most Linux distributions by default.)
#!/usr/bin/env ruby -w
ARGV.sort_by{ rand }.each {|file| system("mpg123 \"#{file}\"")}
To run the jukebox
ruby shuffle_play.rb ~/Music/*.mp3
For the second, I ported above script to bash, which is even more simple and can run on any Linux or OS X. Lets name the script shuffle_play_shell.sh
#!/usr/bin/env bash
n=0;for songs in "$@" ; do song_array[n]=$songs ;((n++)) ; done; for ((i=0;i<$n;i+=1));do number=$RANDOM; let "number %= $n"; `mpg123 "${song_array[number]}"`; done
To run the jukebox
source shuffle_play_shell.sh ~/Music/*.mp3
Update: The second one is not completely random. It will choose n random songs out of n songs. However it does not checks if each song is played at-least once, thus chances of songs getting repeated. Any suggestions?
June 28, 2008 No Comments



