Twitter Ruby function to find all friends and followers of a user

Posted by chad on March 22, 2009

The twitter gem doesn’t do a good job of allowing unauthenticated queries, so I have to make a specific request to the twitter API to do this.

If you pass in Scrap.friendsandfollowers(‘rubyrescue’) you’ll get about 6000 ids. Anything better than a depth of ’1′ and you’ll need an un-rate-limited account w/Twitter as it will take more than 100 requests and they limit requests to 100/hour.

require 'twitter'
require 'net/http'
require 'json'

class Scrap

  def self.friendsandfollowers(users,depth=0,type = :all)
    users = [users] unless users.is_a?(Array)

    puts "at level #{depth}"

    newusers = []
    [:friends,:followers].each do |t|
      if [:all,t].include?(type)
        users.each() do |u|
          puts "looking for #{t.to_s.pluralize} of #{u}"
          newusers += JSON.parse(Net::HTTP.get(URI.parse("http://twitter.com/#{t}/ids/#{u}.json")))
        end
      end
    end

    newusers.uniq!

    if depth == 0
      return newusers
    else
      newusers.each() do |u|
        users += self.friendsandfollowers(u,depth-1,type)
      end
      return users.uniq
    end

  end

end

Locos X Rails 2009 – Buenos Aires – April 3 & 4

Posted by chad on March 10, 2009

http://locosxrails.com

I’m going… Anyone from Brazil other than Akita On Rails?

released my first gem – wordpress on rails (wp_on_rails)

Posted by chad on December 20, 2008

A skeleton (but functional) ruby gem that allows manipulation of a WordPress database from rails, using activerecord. WordPress on Rails

rake aborts with closed stream running rake test 3

Posted by chad on December 11, 2008

Why does rake abort?

chadd@ubuntu:~/myproj$ rake test:units
(in /home/chadd/myproj)
rake aborted!
closed stream
(See full trace by running task with –trace)

 

SOLVED – just do a rake db:schema:dump. If that has never been done, and the database was originally built without a migration (even though I have a full set of migrations that SHOULD create the database properly in the test db), this cryptic error occurs. 

poolparty.rb and the immaturity of cloud computing 2

Posted by chad on December 05, 2008

Poolparty.rb is a very promising ec2 management tool. But it’s down right now. (see below) Based on the documentation, poolparty is self-hosting, which is not an advertisement for relying on ec2 as the primary tool to host a site. As reserve capacity it makes sense, but when it’s the only server, it seems expensive and not necessarily reliable. We use ec2 instances for a number of tasks, mostly for data processing, but the unreliability of using a cloud in this way is related to the immaturity of the toolset to manage the cloud. While the instances are an incredible time savings over provisioning and maintaining the physical hardware, I’m finding that I underestimate the time needed to build and manage the tools to manage the cloud. As tools like poolparty improve, i’m sure this will go down, but it’s significant at this point.

Note: downforeveryoneorjustme.com says it’s not even a site on the internet. This is probably related to the way DNS is managed for the site, which is exactly my point. Odds are the instances are running just fine.

post rails summit 1

Posted by chad on December 01, 2008

You never know when you’ll get photographed with 10 beer cans in front of you.

Ruby one-liners

Posted by chad on October 20, 2008

Dave Thomas has a great list of one-liners that are handy for command line jobs in ruby. Today I needed to setup a cron job to find all backup files that match a specific regular expression and delete them when they are 15 days old. Here’s the way I did it (yes some versions of find can do pretty much the same thing but the version that is on the RedHat server i’m using doesn’t seem to do what I want).

find | sort | ruby -pe 'next unless $_ =~ /MYFILTER/; f=$_.gsub(/n/,"");next unless File.mtime(f) < Time.now - 24*60*60*10;File.delete(f) '

Splitting a BaseCamp account into two separate accounts

Posted by chad on October 20, 2008

I have a number of projects in my BaseCamp account and my main client wants to have a different URL for those projects. Additionally, I was paying for the BaseCamp fees but now I’m going to switch to having him pay directly. So, I want to split the account into two accounts and take some projects into the new account and keep some projects in the old account. I emailed 37signals support and Sara responded promptly with this:

Hi Chad,Unfortunately it’s not possible to transfer data between projects or accounts in Basecamp.

- Sarah

Which leads me to wonder if someone wrote a script using the BaseCamp API to do this?

Obie Fernandez Reveals All the Secrets That Make HashRocket Successful

Posted by chad on October 16, 2008

I talked with Obie’s girlfriend and co-worker at HashRocket, Desi McAdam, and she said he would reveal all their secrets during his closing keynote. He has a lot of good information on running a consulting business on his blog that seems to cover a lot of his material here. A good talk.

  • TAFT- Test All the *** Time
  • Rspec – even show this to your clients to prove that their software works
  • Build the Minimum Viable Product
  • Small Releases
  • Write ‘stories’
    • Turn requirements into stories, called ‘storycarding’
    • It takes 3-5 days to do this
  • Schedule using ‘relative’ units of work
    • Estimate each story
  • Have standup meetings

Open Source Brunettes or GitHub as a repository for non-code resources

Posted by chad on October 16, 2008

Seeing as I have been reporting on other Rails events during the conference, I can’t leave this part out. Rails Summit Latin America has been a test tube mix of skinny geeks and beautiful latin women paid to keep them in line. After 48 hours, one SurgeWorks developer, who asked me not to name him, created an open source project to further study the data. In English the name of the project translates to ‘open source brunettes’, and the git tree has been forked already.