Skip to content

Instantly share code, notes, and snippets.

@em
em / ruler.js
Created May 28, 2014 00:45
Gcanvas ruler
function ruler(ctx, width, length) {
ctx.font="5px helvetica";
ctx.beginPath();
// metric
ctx.beginPath();
for(var x = 1; x < length; ++x) {
ctx.beginPath();
@em
em / rjs-single-form-multi-sig.html
Created September 27, 2012 22:27
Recurly.js example using multiple signatures with a single form, so it doesn't lose the user-input
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>RecurlyJS Subscribe Example</title>
<link rel="stylesheet" href="examples.css" type="text/css" />
<link rel="stylesheet" href="../themes/default/recurly.css" type="text/css" />
<script src="../lib/jquery-1.7.1.js"></script>
<script src="../build/recurly.js"></script>
Sampling process 5677 for 3 seconds with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Analysis of sampling iTerm (pid 5677) every 1 millisecond
Process: iTerm [5677]
Path: /Applications/iTerm.app/Contents/MacOS/iTerm
Load Address: 0x100000000
Identifier: com.googlecode.iterm2
Version: 1.0.0.20120203 (1.0.0.20120203)
Code Type: X86-64 (Native)
Parent Process: launchd [124]
Date/Time: 2012-09-02 19:47:36 -0700
OS Version: 10.8.1 (Build 12B19)
Architecture: x86_64
Report Version: 11
Command: iTerm
Path: /Applications/iTerm.app/Contents/MacOS/iTerm
Version: 1.0.0.20120203 (1.0.0.20120203)
Parent: launchd [124]
@em
em / tcall.js
Created February 23, 2012 19:51
tail call recursion and faux threads by timeslicing
var tcallq = [];
function utime() {
return Date.now();
}
function call2(f,t,a) {
var r = f && function() {
return f.apply(t,a);
};
#!/usr/bin/env ruby
# Example: ./gensig 0 0123456789ABCDEF0123456789ABCDEF "[0,transactioncreate,[account_code:testac,amount_in_cents:5000,currency:USD]]"
require 'openssl'
@timestamp = ARGV[0]
@private_key = ARGV[1]
@em
em / signbillinginfo.js
Created November 14, 2011 22:40
Workaround to sign Recurly.js billing info updates
var crypto = require('crypto');
var privateKey = 'yourprivatekey';
function signBillingInfo(accountCode) {
// copypasta from transparent post
function hash(data) {
//get the sha1 of the private key in binary
var shakey = crypto.createHash('sha1');
@em
em / gensig
Created September 30, 2011 23:03
#!/usr/bin/env ruby
# Example: ./gensig 0 0123456789ABCDEF0123456789ABCDEF "[0,transactioncreate,[account_code:testac,amount_in_cents:5000,currency:USD]]"
require 'openssl'
@timestamp = ARGV[0]
@private_key = ARGV[1]
Recurly.buildSubscriptionForm({
target: '#recurly-subscribe',
afterSubscribe: function(result) {
var data = {
subscription: result
, somethingExtra: $('input.meta_data').val()
};
Recurly.post('/success/url', data, {});
}
Recurly.buildSubscriptionForm({
target: '#recurly-subscribe'
, planCode: 'simpleplan'
, successURL: 'confirmation.html'
, distinguishContactFromBillingInfo: false
, collectCompany: true
, privacyPolicyURL: 'http://example.com/pp'
, preFill: {
contactInfo: {
firstName: 'Joe'