Skip to content

Instantly share code, notes, and snippets.

View levity's full-sized avatar

Lawrence Wang levity

View GitHub Profile
@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;
})
})
#!/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 / 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'
@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 / branch_ages.rb
Created January 10, 2013 00:48
list remote branches sorted by age
require 'date'
branch_times = `git remote show origin`.split("\n").grep(/tracked/).map do |line|
name = line.split(' ').first
last_log = `git log -n1 origin/#{name}`
last_time = Date.parse(last_log.split("\n").grep(/^Date/).first.sub(/^Date\s+/, ''))
[name, last_time.to_date]
end.sort_by(&:last)
branch_name_maxlen = branch_times.map(&:first).map(&:size).max
@levity
levity / change.js
Last active January 4, 2016 08:19
editing a page with VoodooPad API
var Page = function(key) {
var page = document.pageForKey(key),
data = page.dataAsAttributedString(),
text = data.mutableString(),
changed = false;
this.write = function(msg) {
changed = true;
text.appendString(msg);
};
@levity
levity / mosql.rake
Created March 25, 2014 22:55
Rake task for MoSQL on Heroku
# This is a simplified version of what we're using in production for drinksoma.com
namespace :mosql do
task :run => :environment do
conf_path = Rails.root.join('config', 'collections.yml')
cmd = "mosql -c #{conf_path} --sql #{ENV['MOSQL_POSTGRES_URI']} --mongo #{ENV['MOSQL_MONGO_URI']}"
IO.popen(cmd) do |child|
trap('TERM') { Process.kill 'INT', child.pid }
$stdout.sync = true
Verifying I am +lw on my passcard. https://onename.com/lw
@levity
levity / gist:f0bf0f890d0f5587d6b836d04be169a2
Created February 3, 2017 00:22
yarnpkg.com partial outage
Command: curl -I https://yarnpkg.com/latest.tar.gz
West Coast US:
HTTP/1.1 404 Not Found
Date: Fri, 03 Feb 2017 00:17:42 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Set-Cookie: __cfduid=df3a36c097b2974c57d5a70443866f69f1486081062; expires=Sat, 03-Feb-18 00:17:42 GMT; path=/; domain=.yarnpkg.com; HttpOnly
Cache-Control: public, max-age=0, must-revalidate
const request = require('request')
const crypto = require('crypto')
const url = 'https://api.bitfinex.com/v1'
const apiKey = '<Your API key here>'
const apiSecret = '<Your API secret here>'
const payload = {
'request': '/v1/account_infos',
'nonce': Date.now().toString()
}