Archive for category Ruby

Speed up shell scripting

Once again the book Practical Ruby for System Administration by Ben Hamou taught me some pretty clever Ruby sysadmin scripting tricks.
One of the scripts that the author used was to automatically populate the path to the Ruby interpreter, update the permissions to 755, and open the script in vi, all during the same process.

I took that same concept and enhanced the script to also auto populate the settings if the scripts is written in Bash, Perl, PHP, or Python.

Download rnew.rb

-Copy rnew.rb to somewhere within your system PATH.
cp rnew.rb /usr/local/bin

-This should give the ability to use rnew.rb from anywhere you’re working on.
rnew.rb koolscript.php



-Happy Hacking :-)

watch command line utility for alternative for Mac OS X

I recently purchased the book Practical Ruby for System Administration by Ben Hamou and one of the cool Ruby one-liner command line expressions is one that mimics the watch command.
ruby -e 'system "clear; df -h" while sleep 1'

Just like the author, for quite a while I’ve been kind of annoyed by the fact that Apple doesn’t include this really useful command line utility. So inspired by the one-liner script, I hacked a small watch command line alternative for OS X.

Download watch.rb
sudo cp watch.rb /usr/local/bin
wacht.rb ‘UNIX command

Automating re-encoding for my iPhone

I wrote a short ruby script to fully automate video re-encoding for my iPhone. Given that my media collection is about 35 GBs and that HandBreak is multi-threaded, I’m looking forward on how long the entire process will be if I decided to re-encode all of it at once.

The script should work on ruby 1.8.7 or above and it’s only been tested on Snow Leopard.

iphone_encoding.rb

HandBreak (Command Line Interface)

mod_ruby and eRuby

I finally had some time to install mod_ruby and eRuby on my server.

Prerequisites:
httpd-devel ruby ruby-devel eruby
yum install httpd-devel ruby ruby-devel eruby

Installing mod_ruby was pretty confusing, as module default compilation is intended for Apache 1.3 (not why this is the case)

If you’re running Apache 2.0 or higher, I managed to successfully compiled mod_ruby as the following:
./configure.rb –with-apr-includes=/usr/include/apr-1
make
make install

After the install, then its a matter of just adding the custom ruby http conf file to httpd conf.d directory.

SAMPLE:

AddType text/html .rhtml
LoadModule ruby_module modules/mod_ruby.so


RubyRequire apache/ruby-run
#RubyRequire apache/ruby-debug

RubyRequire apache/eruby-run
#RubyRequire apache/eruby-debug

# Execute *.rbx files as Ruby scripts

Options ExecCGI
SetHandler ruby-object
RubyHandler Apache::RubyRun.instance
#RubyHandler Apache::RubyDebug.instance

# Handle *.rhtml files as eRuby files

SetHandler ruby-object
RubyHandler Apache::ERubyRun.instance
RubyHandler Apache::ERubyDebug.instance


Now I can embed Ruby code on standard html pages serving and running natively using Apache and eRuby. :-)
Hence, perlninja.pl

References:
http://www.modruby.net/en/
http://www.ptwit.ac.th/seksan/blog/?p=59

New domain name registered: perlninja.pl

I may not be a perl ninja (just yet) but the domain name kicks ass.

perlninja.pl