Skip to content

Instantly share code, notes, and snippets.

View gist:43933
#!/usr/bin/ruby
# convert embed code generated by some Flash video players into valid markup
# (use object tag instead of deprecated embed tag)
require 'rexml/document'
require 'rubygems'
require 'builder'
@mmb
mmb / gist:49311
Created Jan 20, 2009
imageshack uploader
View gist:49311
#!/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 Feb 19, 2009
sparkline showing the number of lines in a file
View gist:66728
#!/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"
View gist:74780
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 Mar 12, 2009
get gmail unread count in ruby
View gist:78350
#!/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 Mar 18, 2009
Google Calendar backup for custom domain
View gcal_backup.rb
#!/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 Mar 26, 2009
get latitude and longitude from a photo
View 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 Apr 30, 2009
prepend youtube links with thumbnails
View prepend youtube links with thumbnails
@mmb
mmb / gist:115799
Created May 21, 2009
get number of active and allowed connections from a DD-WRT router
View gist:115799
#!/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
View 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