Skip to content

Instantly share code, notes, and snippets.

@lwu
lwu / 1+1
Created September 6, 2012 06:08
Gist defect?
0
@lwu
lwu / url.txt
Created April 13, 2012 20:51
URLs
http://a.espncdn.com/combiner/i?img=/photo/2012/0306/ncb_u_barkleysmile_134.jpg
http://a.espncdn.com/combiner/i?img=/photo/2012/0326/grant_g_crawford_gb1_134.jpg
http://a.espncdn.com/i/columnists/reilly_rick_80fp.png
http://a.espncdn.com/i/columnists/simmons_bill_80fp.png
http://a.espncdn.com/i/ncb/ncaatourney12/fp_check_bracket.gif
http://a.espncdn.com/media/motion/2012/0325/dm_120325_nfl_ontheclock_robertgriffinIII_thumdnail_wbig.jpg
http://a.espncdn.com/media/motion/2012/0327/dm_120327_nfl_schefter_payton_parcells_thumdnail_wbig.jpg
http://a.espncdn.com/photo/2012/0326/as_zoom_134.jpg
http://a.espncdn.com/photo/2012/0326/mlb_g_suzuki_gb1_110.jpg
http://a.espncdn.com/photo/2012/0327/nba_a_dirky_cr_110.jpg
@lwu
lwu / PKSimple.rb
Created September 11, 2009 18:36
Pressure-sensitive keyboard IO in Ruby (experimental MSFT hw!)
#!/usr/bin/env ruby
#
# Pressure-sensitive keyboard IO in Ruby (experimental MSFT hw!)
%w(rubygems serialport).each { |lib| require lib } # sudo gem install serialport pls
ser = SerialPort.new("/dev/tty.usbserial-A6007kA6", 115200, 8, 1, SerialPort::NONE)
ser.write("q") # initiate continuous ASCII mode
while true
@lwu
lwu / geo_test.rb
Created July 28, 2009 02:25
Experiment with Wikipedia opensearch
#!/usr/bin/ruby
#!/usr/bin/env ruby # MacPorts 1.87
air = {
:input => ["JFK", "LGA", "EWR"],
:expected => ["JFK Airport", "LaGuardia Airport", "Newark Liberty International Airport"]
}
# Note that opensearch "Mount Whitney NGS" returns empty, but the Wikipedia on-site search tries to return something!
This ruby script takes in a TSV of type co-occurrence probabilities,
does some simple filtering, and prints the output.
The filtered text file is suitable for node-link diagram visualization.
#!/usr/bin/env ruby
require 'open-uri'
days = []
(1..15).each do |pg|
query = 'days+ago+whendidyoujointwitter'
s = open("http://search.twitter.com/search.json?q=#{query}&rpp=100&page=#{pg}")
days << s.read.scan(/(\d+) days ago/).flatten.map { |st| st.to_i }
end
@lwu
lwu / pfly09.rb
Created March 29, 2009 10:57
= AllisonF + Brianna + Constance + Emily + Lucy + RKelly + Wushu
#!/usr/bin/env ruby
# primary source data: zteam car manifests :)
santabar = %w(AllisonF AnnieW Becky Brianna Brittany Chips Constance Dex
Emily Firebelly Frogger Galen LeslieR Lolo Lucy Marielle Marisa
RKelly Rosalie Scout Sparky Skiddo Tajah Tank Wushu)
davis = %w(AllisonF AnnieW Annika Ariana Brianna Chips Constance Emily
Firebelly Gina Izzy Laurel Lucy RKelly RachelL Rosalie SarahC
@lwu
lwu / ZlibCompressor.mxml
Created March 12, 2009 05:18
Want to load compressed JSON files from ActionScript 3? Use this Ruby script (or AIR application) to create the compressed files
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
title="ZlibCompressor"
nativeDragDrop="onDrop(event)"
nativeDragEnter="onDragIn(event)"
>
<mx:Script>
<![CDATA[
@lwu
lwu / osm_bbox.rb
Created February 4, 2009 19:16
Download the OSM XML that contains a given KML (bounding box)
#!/usr/bin/env ruby
%w[open-uri hpricot].each {|lib| require lib }
# get KML bbox and grab OSM XML
raise "no query arg specified" if ARGV.empty?
kml_filename = ARGV[0]
doc = Hpricot(open(kml_filename))
coords = (doc/"coordinates")[0].inner_html.split.map { |x| x.split(',').map {|s| s.to_f } }
longs = coords.transpose[0]
@lwu
lwu / shapefly.rb
Created February 4, 2009 01:04
Get the shapefile for a query string using Yahoo/Flickr webservices
#!/usr/bin/env ruby
%w[open-uri hpricot].each {|lib| require lib }
YAHOO_APP_ID = "[yourappidhere]"
FLICKR_KEY = "[yourapikeyhere]"
raise "alarms" if YAHOO_APP_ID =~ /here/
raise "no query arg specified" if ARGV.empty?
# command line query => Y! where query => Flickr getInfo query => wget shapefile => ogr2ogr to KML