Skip to content

Instantly share code, notes, and snippets.

@mmb
mmb / gist:49311
Created January 20, 2009 03:48
imageshack uploader
#!/usr/bin/ruby
# upload a local image or an image on the web to imageshack
require 'rubygems'
require 'mechanize'
require 'open-uri'
require 'uri'
@mmb
mmb / gist:66728
Created February 19, 2009 04:16
sparkline showing the number of lines in a file
#!/usr/bin/ruby
# sparkline showing the number of lines in a file
# run from cron at regular intervals
require 'rubygems'
require 'sparklines'
file_to_count = '/tmp/growing_file'
count_file = "#{file_to_count}.linecount"
require 'pp'
temps = {}
temps['video'] = `aticonfig --od-gettemperature`.match(/Temperature - (\d+\.\d+) C/).captures.first.to_f
sensors_output = `sensors`
(['CPU', 'System'] + (0..3).to_a.map {|c| "Core #{c}"}).each do |x|
@mmb
mmb / gist:78350
Created March 12, 2009 23:19
get gmail unread count in ruby
#!/usr/bin/ruby
# gmail unread message count
require 'open-uri'
require 'rexml/document'
unread_count = open('https://mail.google.com/mail/feed/atom',
:http_basic_authentication=>['you', 'secret']) do |f|
doc = REXML::Document.new(f.read)
doc.root.elements['//feed//fullcount/text()'].value.to_i
@mmb
mmb / gcal_backup.rb
Created March 18, 2009 03:02
Google Calendar backup for custom domain
#!/usr/bin/ruby
# Google Calendar backup for custom domain
require 'rubygems'
require 'mechanize'
domain, user, pass = ARGV
unless [domain, user, pass].include?(nil)
@mmb
mmb / get latitude and longitude from a photo
Created March 26, 2009 22:33
get latitude and longitude from a photo
#!/usr/bin/ruby
# get latitude and longitude from a photo
# known to work with iphone photots
require 'rubygems'
require 'exifr'
x = EXIFR::JPEG.new(ARGV[0])
@mmb
mmb / prepend youtube links with thumbnails
Created April 30, 2009 22:43
prepend youtube links with thumbnails
@mmb
mmb / gist:115799
Created May 21, 2009 22:46
get number of active and allowed connections from a DD-WRT router
#!/usr/bin/ruby
# get number of active and allowed connections from a DD-WRT router
require 'rubygems'
require 'net/ssh'
Net::SSH.start('192.168.0.1', 'root') do |ssh|
max = ssh.exec!('cat /proc/sys/net/ipv4/netfilter/ip_conntrack_max').strip
tcp = ssh.exec!('grep -c ^tcp /proc/net/ip_conntrack').strip
@mmb
mmb / stock quote
Created June 15, 2009 22:42
stock quote
#!/usr/bin/ruby
require 'open-uri'
require 'hpricot'
symbol = ARGV[0]
open("http://www.nasdaq.com/aspxcontent/NasdaqRSS.aspx?data=quotes&symbol=#{symbol}") do |f|
doc = Hpricot(f)
desc = (doc/"//rss/channel/item/description").first.inner_html
@mmb
mmb / gist:151066
Created July 21, 2009 02:32
show recent anonymous edits to a Wikipedia article from interesting domains
#!/usr/bin/ruby
# show recent anonymous edits to a Wikipedia article from interesting domains
require 'hpricot'
require 'open-uri'
require 'socket'
require 'yaml'
article = 'Henry_Paulson'