Skip to content

Instantly share code, notes, and snippets.

View levity's full-sized avatar

Lawrence Wang levity

View GitHub Profile
@levity
levity / rspec-syntax-cheat-sheet.rb
Created November 28, 2011 20:10 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@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)