Skip to content

Instantly share code, notes, and snippets.

View levity's full-sized avatar

Lawrence Wang levity

View GitHub Profile
@levity
levity / ssl_bookmarklet.coffee
Created September 13, 2011 20:25
stub for ssl bookmarklet server
https = require 'https'
fs = require 'fs'
options = {
key: fs.readFileSync('privatekey.pem'),
cert: fs.readFileSync('certificate.pem')
}
host = 'levityisland.com'
#!/usr/bin/ruby
# america's funniest home ruby tricks:
# barebones textmate shell REPL
# paste this into a textmate window
# type a command at the prompt, then type Cmd-a Ctrl-r
prompt = "> "
history = DATA.read.split("\n")
cmd = history.last.gsub(/^#{prompt}/, '')
print "\n#{`#{cmd}`}#{prompt}"
__END__
@levity
levity / retry.html
Created August 9, 2011 00:25
jQuery auto-retries if a callback fails!?
<html>
<body>
<div id="foo"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(function() {
$('#foo').hide().slideDown(null, function() {
x = intentionally_cause_error;
})
})
@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"/>
@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 / 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 / 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
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 / 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)
@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']