Skip to content

Instantly share code, notes, and snippets.

View levity's full-sized avatar

Lawrence Wang levity

View GitHub Profile
javascript:function iprl5() {
var d=document,
z=d.createElement('scr'+'ipt'),
b=d.body,
l=d.location;
try {
if (!b) throw(0);
d.title='(Saving...)'+d.title;
z.setAttribute('src',l.protocol+'//www.instapaper.com/j/LIq7XKV1Bp1I?u='+encodeURIComponent(l.href)+'&t='+(new Date().getTime()));
@levity
levity / identitymap.rb
Created December 7, 2010 01:22
DataMapper Identity Map on Rack
## somewhere
module Persistence
class IdentityMap
def initialize(app)
@app = app
end
def call(env)
DataMapper.repository { @app.call(env) }
end
@levity
levity / fb_connect.html
Created December 8, 2010 06:26
Facebook Connect
<html>
<body>
<div id="login" style="display: none">
<fb:login-button perms="email"></fb:login-button>
</div>
<div id="logout" style="display: none">
<button onclick="FB.logout()">Log out</button>
</div>
@levity
levity / infinite_hash.rb
Created December 14, 2010 21:49
Infinite Hash
# O.o
# http://opensoul.org/blog/archives/2010/12/12/the-ruby-infinite-hash/
>> hash = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
=> {}
>> hash['a'] = 1
=> 1
>> hash['a']
=> 1
>> hash['b']
@levity
levity / photo_essay.rb
Created January 10, 2011 04:38
simple templating
#!/usr/bin/ruby
require 'yaml'
# DATA is a little-used feature of the Ruby language; it's a file handle
# whose contents are everything in the current file after the __END__.
# YAML is "Yet Another Markup Language".
data = YAML.load(DATA)
def url_for(entry_num)
set -g prefix C-a
unbind C-b
bind C-a send-prefix
set-window-option -g mode-keys vi
bind k up-pane
bind j down-pane
@levity
levity / att.rb
Created May 2, 2011 20:34
scrape your historical monthly data usage (in KB) from att.com
#!/usr/bin/ruby
LOGIN, PASSWORD = 'your_number', 'your_password'
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
agent.get 'https://wireless.att.com'
login = agent.page.forms_with(:name=>'loginActionForm').first
@levity
levity / meetup.rb
Created June 5, 2011 21:14
more mechanize: mass-adjust meetup communication settings
#!/usr/bin/ruby
require 'rubygems'
require 'mechanize'
print "email: "
email = gets.chomp
print "password: "
password = gets.chomp
agent = Mechanize.new
@levity
levity / google_talk.rb
Created July 20, 2011 00:10
send a Google Talk message with Ruby
require 'xmpp4r'
include Jabber
Client.new(JID.new "#{USERNAME}/Home").instance_eval do
connect 'talk.google.com'
auth PASSWORD
send Message.new(RECIPIENT, MESSAGE).tap{|m| m.type = :chat }
close
end
@levity
levity / tumblr.html
Created August 4, 2011 09:19
tumblr theme for sympathizer
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
{block:Description}<meta name="description" content="{MetaDescription}" />{/block:Description}
<meta name="text:Twitter Username" content=""/>
<meta name="text:Flickr Username" content=""/>
<meta name="text:Disqus Shortname" content=""/>
<meta name="color:Asterisk" content="#17f0ff"/>