Insights on Ruby, Git, jQuery, Cappuccino, WordPress, Debian and OS X. Please subscribe if you find something useful!

Expand Your Twitter Network In Less Than 15 Lines of Ruby

Posted: May 17th, 2009 | Author: Jerod | Filed under: Ruby | Tags: , | View Comments

A great way to meet new people on Twitter is by checking out the people your friends are interacting with. We can assume that if many of your friends follow somebody, that person has a high likelihood of being interesting to you (or it is Ashton Kutcher). Let’s use Ruby to generate a list of people highly followed by our friends.
Read the rest of this entry »


See Which Twitterers Don’t Follow You Back In Less Than 15 Lines of Ruby

Posted: May 12th, 2009 | Author: Jerod | Filed under: Ruby | Tags: , | View Comments

The asynchronous nature of Twitter is one of its keys to success. No friend requests. Awesome.

A lot of the people I follow on Twitter have no business following me. I did’t get upset when DHH, _why, and alexalbrecht did not reciprocate interest. Why would they? They don’t know me from Adam (even though I’m waayyy cooler than that dude…).

However, sometimes it is interesting to see all the jerks people who you follow that do not follow you back. There’s probably a web application out there that does this, but who needs a web app when this is a perfectly good excuse to play with Ruby?

The twitter gem by John Nunemaker makes this task so easy it’s retarded. First, get the gem if you don’t already have it:

sudo gem install twitter

Now. The script:
Read the rest of this entry »


Dreamy: Now With 100% API Coverage

Posted: May 2nd, 2009 | Author: Jerod | Filed under: Projects, Ruby | Tags: , | Comments Off

The folks at DreamHost were gracious enough to provide me with a complimentary Private Server account so I could expand Dreamy’s functionality. What a nice surprise that was!

So, to ensure they got their money’s worth, I added all the Private Server API calls to Dreamy! This means that Dreamy now covers the entire DreamHost API. Check out all the new commands added to “dh” (the accompanying command-line tool):

ps                                 # list private servers
ps:add <web|mysql> <yes|no>        # adds a private server of type <web|mysql>
ps:pending                         # list private servers scheduled to be created
ps:reboots <name>                  # list historical reboots for <name>
ps:reboot <name> now!              # reboot <name> now! (proceed with caution)
ps:remove                          # removes all pending private servers
ps:settings <name>                 # list settings for private server <name>
ps:set <name> <setting> <value>    # change <setting> on <name> to <value>
ps:size <name>                     # list historical memory sizes for <name>
ps:size <name> <value>             # set new memory <value> for <name>
ps:usage <name>                    # list historical memory & CPU usage for <name>

You’ll need version 0.4.2 of the Dreamy gem to use the new functionality. To upgrade your gem, simply run the following:

sudo gem update sant0sk1-dreamy

That’s all for now!


So Dreamy!

Posted: April 18th, 2009 | Author: Jerod | Filed under: Projects, Ruby | Tags: , , | View Comments

DreamHost is running a kick-off competition in support of their newly released API. It seems like their developer community could use a little productivity boost, so I thought I’d create a Ruby library to interact with their API.

The resulting Ruby Gem, available on GitHub, is called “Dreamy” and includes a library and a command-line tool.

Why a command-line tool? Because sometimes you wanna see what’s going on with your DH account without having to pop open the control panel (also, as an example of how to use the library). Here is some sample output returning all DNS records for domains matching the string “rachel” (my wife’s name):

dreamy_output

Isn’t that table-based formatting dreamy?!?! Next up, a listing of all domains on the account and their availability. If one of the domains is down, it will ping the domain’s host server to determine if the problem is system-wide or not:
dh_domain_status

There are many more things you can do with the command-line tool, but you can check out those by installing the gem and running:

dh help

How do you install the gem? It’s super-simple (if you already have Ruby and RubyGems installed):

gem sources -a http://gems.github.com (only needed if you've never run this before)
gem install sant0sk1-dreamy

Booyah!

How do you use the library? Well, you just require it into your Ruby program and hit the ground running!

require 'rubygems'
require 'dreamy'
 
account = Dreamy::Base.new(username, api_key)
 
# get an array of Domain objects
account.domains
# get an array of User objects
account.users
# get an array of DNS objects
account.dns
# get an array of Subcribers to "my_list@example.com"
account.announce_list("my_list","example.com")
# add a subscriber to "my_list@example.com"
account.announce_add("my_list","example.com","guy@gmail.com")
# remove a subscriber to "my_list@example.com"
account.announce_remove("my_list","example.com","guy@gmail.com")

The Domain, User, DNS, and Subscriber objects that are returned in the arrays include all the data that DreamHost exposes about them from their API. For instance, I can print the attributes of the Domain object like so:

account.domains.first.instance_variables

Which returns:

["@www_or_not", "@user", "@php", "@path", "@fastcgi", "@unique_ip", "@passenger", "@type", "@account_id", "@security", "@home", "@domain", "@outside_url", "@xcache", "@php_fcgid", "@hosting_type"]

To find out more about the library, head over to the project’s GitHub page and check out the README.

Let me know what you think!

UPDATE: Dreamy is now 100% API Compatible (and a whole lot cooler!) Check out my second blog post outlining the changes

NOTE #1: The DreamHost API is still young and in heavy development. Dreamy is nowhere near a comprehensive library, but I wanted to get it into the public so other developers could use it for their competition projects. Please, if you find any bugs or want to add functionality… please, please, please fork the project and help out!


New Gem: Rack-noIE6

Posted: April 18th, 2009 | Author: Jerod | Filed under: Projects, Ruby | Tags: , , | View Comments

Many web developers are discontinuing support for IE6. I, happily, am one of them (unless a client demands it). The other day I went searching for an IE6 detection and redirect solution to aide in my un-support of the browser. What I found was pretty rad.

Now that Rails is on Rack, dozens of useful middleware apps are being developed and can be plugged into Rails with ease. Thanks to a simple GitHub search, I found the rack-noie project by Julio Cesar.

His middleware did almost exactly what I wanted except for a few small things. First, I prefer using gems with Rails so dependencies can easily be managed using config.gem. Second, we’re just hating on IE6, not IE in general. Therefore, the name is a bit misleading.

So, in the spirit of open-source, I forked his project and molded it to my liking. You can see the shiny new rack-noie6 gem’s GitHub page here.

Its dead simple to integrate. First, install the gem

gem sources -a http://gems.github.com (only if you haven't yet)
gem install sant0sk1-rack-noie6

Next (if you’re using Rails), add the following to environment.rb inside the Rails::Initializer.run block:

config.gem 'sant0sk1-rack-noie6', :lib => 'noie6'
config.middleware.use "Rack::NoIE6"

As the IE6-BraveHeart would proclaim: FREEEEDOMMMM!