Archive

Archive for the ‘Uncategorized’ Category

Twitter + Jabber = Jitter?

February 9th, 2009 No comments

I’ve been playing with Twitter lately – I created a Booko Twitter account to reserve the account name while I consider using it. I’ve got my own Twitter account and I had a bit of a play around with it, but honestly using Twitter via the web seems like a drag. Yet another page to watch. Plus, I subscribed to the MelbTransport guy’s page and all I could think was “Can’t I filter this to show me only the updates I’m interested in?” – apparently no, you can’t. 

I had a look at the applications out there to manage your tweets but all I could think was “Man, another app to run, another distraction.”. I’ve already got email and IM, I don’t really want another app bouncing in the Dock to tell me someone’s posted a message. So, I got to thinking, maybe there’s a way to get Twitter messages to be sent to me via IM?  Had a brief look around but didn’t immediately find anything suitable. A quick Google however netted two interesting Ruby Gems – twitter and xmpp4r-simple, which give you a nice Ruby interface to Twitter and Jabber. So, after a couple of hours of hacking around, getting my Twitter account temporarily rate limited and creating Jabber accounts, I’ve got a very simple Twitter <-> Jabber gateway going.

It will post tweets to your Jabber account & you can reply! Your reply will get posted to Twitter.  As an added bonus I added filtering so I can see only what I want from MelbTransport guy’s updates.  You can easily add your own filters in there – hopefully it’s pretty straight forward. 

Now, I know this isn’t beautiful, elegant Ruby code – feel free to leave constructive criticism in the comments.

#!/usr/bin/env ruby

require 'rubygems'
require 'twitter'
require 'xmpp4r-simple'
require 'benchmark'

jabber_user="sendinguser@jabber.org.au"
jabber_pass=""

$receiving_jabber = "receivinguser@jabber.org.au"

twitter_user="twitteruser"
twitter_pass=""

jabber = twitter = nil

cj = Benchmark.realtime {jabber = Jabber::Simple.new(jabber_user, jabber_pass)}
puts "Connecting to Jabber: #{cj}"

ct = Benchmark.realtime {twitter = Twitter::Base.new(twitter_user, twitter_pass) }
puts "Connecting to Twitter: #{ct}"

def filters(status)
  if status.user.name == "MelbTransport"
    yield if status.text =~ /Craigieburn|Broadmeadows|Upfield/
  else
    yield
  end
end

def get_tweets(twitter, tweets, jabber)
  begin
    twitter.timeline.reverse.each do |s|
      if tweets[s.id].nil?
        filters(s) { jabber.deliver($receiving_jabber, "#{s.user.name} says: #{s.text}") }
        tweets[s.id] = "Sent"
      end
    end
  rescue Twitter::CantConnect
    puts "Can't connect. Sleeping."
    sleep 120
    retry
  end
end

def post_tweets(twitter, jabber)
  jabber.received_messages { |msg| twitter.post(msg.body) if msg.type == :chat }
end

def main(twitter, jabber)
  tweets = {}
  while true
    puts "Action!"
    get_tweets(twitter, tweets, jabber)
    post_tweets(twitter, jabber)
    sleep 60
  end
end

main(twitter, jabber)

Edits:Reversed the order of the timeline to match how they should show up in IM (IE – oldest at the top, newest at the bottom.

Categories: Uncategorized Tags: , , ,

Science & Morality discussed by Sam Haris

February 9th, 2009 No comments


Categories: Uncategorized Tags: , ,

Truism of the day

February 5th, 2009 No comments

“Broken gets fixed. Shoddy lasts forever”.  I’ve heard this phrased differently in different places and it’s too often true.  

via DesignAday – Truism.

Categories: Uncategorized Tags:

Storm by Tim Minchin

January 31st, 2009 No comments

Categories: Uncategorized Tags:

1981 Internet story

January 30th, 2009 No comments

Categories: Uncategorized Tags:

OCR and Neural Nets in JavaScript

January 26th, 2009 No comments

Javascript is becoming more and more useful as CPUs get faster and Javascript engines get better – John Resig – OCR and Neural Nets in JavaScript. Solving captcha with neural networks in Javascript. It sounds like a pretty small  neural net, but that’s pretty amazing.

Categories: Uncategorized Tags: , ,

LiPo

January 17th, 2009 No comments

Testing my new LiPo battery.  Watch those tyres balloon!  The battery can do 96Amp continuous with 160Amp bursts. It’s a 5350 mAH battery  but at 7.4V, it won’t push those sorts of currents for long.

Flying people

January 5th, 2009 No comments

Awesome!


wingsuit base jumping from Ali on Vimeo.

Categories: Uncategorized Tags: ,

YouTube picks

December 25th, 2008 No comments

They sell Beached As stuff at CafePress.

Categories: Uncategorized Tags:

Installing Ruby Enterprise Edition + Phusion Passenger (mod_rails) on Ubuntu in a VPS

December 13th, 2008 No comments

I’ve tried quite a few ways to deploy Ruby on Rails apps for Booko:

  • Apache with mod_proxy and mongrel cluster
  • Apache with mod_proxy and thin
  • Nginx with thin

I only gave nginx a small run – I needed PHP for the blog (I’ve since moved Booko to it’s own host, so this wouldn’t be a problem) and it seemed great – but so far, I think REE + mod_rails is the best. It’s the most convenient to install/setup, it seems to be very fast, and it is quite nice to manage.  You can restart your Rails application with a touch tmp/restart.txt – you know it’s restarted because the file disappears - that’s pretty nice. Naturally, you can restart Apache too.

So, this is a post on how to install Ruby Enterprise Edition and Phusion Passenger (aka: mod_rails) on Ubuntu 8.04 LTS in a VPS, specifically, Slicehost. It’s not hard, but this should make it even faster.  You can read all about Ruby Enterprise Edition, but basically it’s a version of Ruby tuned to be fast and lean. It’s made by the guys who’ve created Phusion Passenger, or mod_rails and they work well together.  I’ll be assuming that you want to use this version of Ruby for everything (ie – command line work as well as for mod_rails). IE, when you call irb or ruby or rake from the command line, you want to use REE. 

Read more…