Code Shop

Code Shop

Abhi Yerra  //  An entity composed of reality and pseudo-reality who enjoys coding, news, history, photography and wasting time.

Jan 6 / 12:40pm

Fresh 0.9.2 activerecord-jdbc-adapter Release

$ jruby script/generate jdbc exists config/initializers create config/initializers/jdbc.rb exists lib/tasks create lib/tasks/jdbc.rak

Way to run JRuby on Rails. There was a change in how jdbc is called.

Filed under  //  jdbc   jruby  

Comments (0)

Dec 28 / 9:04am

Ruby EventMachine: a short introduction

EventMachine

EventMachine is a ruby implementation of event driven framework. It separates the networking logic and business logic. It allows consumers to concentrate on business logic and it takes care of all the issues related to sockets and networking layer. Because event driven frameworks are not tied to a single request, they usually have very good performance.

This is a really good introduction on how to use EventMachine and what it's about!

Comments (0)

Dec 24 / 4:12am

NASA Space Photos Download Script

NASA has some pretty sweet space photos which they update daily. Now
wouldn't it be great to download them and let them run as your
screensaver. Well now you can my good friend. Here is the script to do
just that. Run this as a cronjob daily and you have a self-updating
background images.

Filed under  //  bash   script  

Comments (0)

Dec 24 / 3:43am

basename and dirname Work for URLS

This code will work correctly!
 
site="http://antwrp.gsfc.nasa.gov/apod/archivepix.html" 
 
echo "`basename $site`" 
echo "`dirname $site`" 

Resulting in:

 
archivepix.html 
http://antwrp.gsfc.nasa.gov/apod 

Now, that's pretty sweet!

Filed under  //  bash   scripting  

Comments (0)

Dec 24 / 3:35am

Date Specifiers

I always forget the different date specifiers for the
date command so here they are in all their glory.

%% a literal %
%a locale’s abbreviated weekday name (e.g., Sun)
%A locale’s full weekday name (e.g., Sunday)
%b locale’s abbreviated month name (e.g., Jan)
%B locale’s full month name (e.g., January)
%c locale’s date and time (e.g., Thu Mar 3 23:05:25 2005)
%C century; like %Y, except omit last two digits (e.g., 21)
%d day of month (e.g, 01)
%D date; same as %m/%d/%y
%e day of month, space padded; same as %_d
%F full date; same as %Y-%m-%d
%g last two digits of year of ISO week number (see %G)
%G year of ISO week number (see %V); normally useful only with %V
%h same as %b
%H hour (00..23)
%I hour (01..12)
%j day of year (001..366)
%k hour ( 0..23)
%l hour ( 1..12)
%m month (01..12)
%M minute (00..59)
%n a newline
%N nanoseconds (000000000..999999999)
%p locale’s equivalent of either AM or PM; blank if not known
%P like %p, but lower case
%r locale’s 12-hour clock time (e.g., 11:11:04 PM)
%R 24-hour hour and minute; same as %H:%M
%s seconds since 1970-01-01 00:00:00 UTC
%S second (00..60)
%t a tab
%T time; same as %H:%M:%S
%u day of week (1..7); 1 is Monday
%U week number of year, with Sunday as first day of week (00..53)
%V ISO week number, with Monday as first day of week (01..53)
%w day of week (0..6); 0 is Sunday
%W week number of year, with Monday as first day of week (00..53)
%x locale’s date representation (e.g., 12/31/99)
%X locale’s time representation (e.g., 23:13:48)
%y last two digits of year (00..99)
%Y year
%z +hhmm numeric timezone (e.g., -0400)
%Z alphabetic time zone abbreviation (e.g., EDT)
Filed under  //  linux  

Comments (0)

Dec 22 / 8:28pm

Linode DNS for Home Machine

If you want to point your home computer to a domain or subdomain you own, instead of using something like DynDNS, you can use Linode. If you have Linode hosting your DNS the Linode API makes it a relative breeze to update. Here is the code:


You can ignore the myip.php code as that is the code running at http://www.ocf.berkeley.edu/~abhi/myip/. If you want to host your own myip.php code just copy it to your php enabled web server and change the myip_url to point to that page instead.

You need to enable and copy your Linode API key as well as a DomainID and ResourceID so the script knows which domain to update. The DomainID is the id associated with your domain you can find it in the url when you go to your domain in the DNS Manager. A ResourceID is the A Name DNS that will point to your home machine. Once you create the A name and click on the link to it you can find the ResourceID in the url. When creating an A Name set it to 5 or 30 mins as your modem might change it's ip. Further, set the script to be a cronjob updating every so often.

Edit:

Here is a shell script version of the code which doesn't require Ruby installed. You just need curl enabled with SSL.
Filed under  //  dns   linode   linux  

Comments (4)

Dec 20 / 11:40pm

Dropbox and dotfiles

I really like Dropbox. It's a convienient way to sync all your
computers without using rsync and what not. However, the thing that
bugs me the most is keeping my dotfiles in sync as I usualyl forget to
sync between computers when I change them. Thanksfully, Dropbox makes
this easier.

1. Create a directory in your Dropbox folder.
2. Move your dotfiles from $HOME to that folder. Change the prefix . with _.
3. Add this file (I named it dotfiler.sh, but you can name it whatever you want)

 
#!/bin/sh 
 
for file in _* 
do 
 ln -s -n -f `pwd`/$file $HOME/${file/#_/.} 
done 

4. chmod +x the new file. (Currently, executable flag doesn't move
from one machine to another. So probably have to do this on each
machine.)
5. Run the file in your not dotfiles directory.

This should keep all your dotfiles in sync whatever computer you are
using. If you also added .profile and .bashrc make sure that you take
your platform into account i.e., Linux, Mac OS X.

Run the script whenever you add a new dotfile.

Filed under  //  dropbox   linux   unix  

Comments (0)

Dec 20 / 9:56pm

Unix Job Control

Unix is a multitasking operating system (like most everyday operating systems nowadays) and as such it has and idea on how to do handle jobs. Jobs are executing which happen on a per shell basis as opposed to processes. Here is a summary of everything that you need to know about UNIX jobs. 

command &
When running a command with an ampersand at the end for example "ls &" that job is put into the background and runs which you execute other commands on the shell.

CTRL-c
If you want to kill a long running job press this combination to stop the job from running.

CTRL-z
Suspends a job, but does not kill it.

bg %num
If you suspend a job and want to run it in the background (or you forgot to put a job in the background and put it in the background) run this.

fg %num
Run this to bring to front a background job or to run a suspended job in the foreground.
 
kill %num
Kills a job number.

jobs
List all the active jobs on the shell. There can be multiple jobs with many running in the background.

set notify
Notifies immediately on the shell if there is change in the a background job.
Filed under  //  linux   unix  

Comments (1)

Oct 17 / 9:30pm

NFS on (Snow) Leopard

I setup NFS4 on my home server to host my mp3s for iTunes to access.
However, I had trouble getting the Mac GUI to mount the NFS drives. So
I instead decided to use the command line.

 
sudo /sbin/mount_nfs -o resvport krusty:/home/abhi/iTunes MusicMount/ 

This should mount a nfs mount. Just set that MusicMount to be where
you want iTunes to store your files. So far this has been working out
great.

Filed under  //  linux   mac   nfs  

Comments (2)

Oct 1 / 10:21pm

Simple Vim Posterous Plugin

I like writing in Vim! It is one of those things that I am so used to
that every other text editor feels unnatural and going against the
grain. So I thought I'd write a small plugin to post to Posterous. Add
the following code to your .vimrc. Also make sure you have python
enabled in vim as well as have markdown2 for python installed.

The following need to be changed: blog_email, blog_password, and
site_id. site_id can be grabbed by running the following on the
terminal:

 
curl -u my@email.com:mYpA$$W0RD http://posterous.com/api/getsites 

Substitute the email and password. You will get a list of your blogs
so choose the id of the blog you want to post to.

The format of the text should be as follows: the first line is the
title and the proceeding lines are the body:

 
This is the title of the post 
 
This is the body of the post. 

This code is pretty straightforward and sparse because I am using this
to post code snippets to a private blog. Check out the Posterous API to add more
options and whatnot. Also take this as a start and expand upon it.

Filed under  //  code   plugin   posterous   vim  

Comments (1)