Skip to content

Instantly share code, notes, and snippets.

View alexyoung's full-sized avatar
💤

Alex Young alexyoung

💤
View GitHub Profile
@alexyoung
alexyoung / jquery.template.js
Created October 20, 2011 12:12
templates
/**
* Render templates.
*
* @param {String} The template to use `<p>Hello {{name}}</p>`
* @param {String} The data `{ name: 'Alex' }`
* @return {String} The rendered template
**/
function template(t, d) {
return t.replace(/{{([^}]*)}}/g, function(m, f, p, a) {
return d[f] || '';
@alexyoung
alexyoung / hasClass.js
Created August 20, 2011 07:26
hasClass benchmarks
/*
hasClassString x 2,290,290 ops/sec ±0.38% (86 runs sampled)
hasClassRegExp x 17,025 ops/sec ±0.45% (82 runs sampled)
Fastest is hasClassString
*/
var Benchmark = require('benchmark')
, suite = new Benchmark.Suite
@alexyoung
alexyoung / deploy.sh
Created May 17, 2011 10:47
Deployment script
#!/usr/bin/env bash
# Configuration
SERVER='myserver'
DEPLOY_TO='/path/to/app'
EXCLUDE='*.swp .git/ db/sphinx/ tmp/ log/'
DRY_RUN=false
DEPLOY_GEM_PATH='/opt/ec/ruby/1.8.7/lib/ruby/gems/1.8'
@alexyoung
alexyoung / twitter_favicon_convertor.rb
Created December 11, 2010 21:19
Downloads a profile picture from Twitter and converts it to a favicon
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
name = 'alex_young'
doc = Nokogiri::HTML(open("http://twitter.com/#{name}"))
doc.search('#profile-image').each do |img|
require.paths.unshift('./turing-test/lib');
turing = require('../turing.core.js').turing;
var test = require('test'),
assert = require('assert'),
$t = require('../turing.alias.js');
exports.testAlias = {
'test turing is present': function() {
assert.equal(turing.VERSION, '0.0.41', 'turing.core should have loaded');
@alexyoung
alexyoung / ed.c
Created December 8, 2010 10:41
Hello, I'm ed
#include <stdio.h>
#include <signal.h>
void sigfun(int sig) { }
int main()
{
(void) signal(SIGINT, sigfun);
int c;
while ((c = getchar()) != 'q') {
require 'rubygems'
require 'open-uri'
require 'json'
repositories = JSON::parse(open('http://github.com/api/v2/json/repos/search/ruby').read)
repositories['repositories'].each do |repo|
user = JSON::parse(open("http://github.com/api/v2/json/user/show/#{repo['username']}").read)['user']
puts user['email']
end
require 'rubygems'
require 'open-uri'
require 'zlib'
require 'faster_csv'
def get_csv(uri)
gz = Zlib::GzipReader.new open(uri)
FasterCSV.parse(gz)
end
NSArray *suffixes = [NSArray arrayWithObjects:@"th", @"st", @"nd", @"rd", nil];
NSString *suffix = nil;
NSInteger birthday = [[goal valueForKey:@"beforeBirthday"] intValue];
NSInteger offset = birthday % 10;
offset = (offset % 100) > 10 && (offset % 100) < 20 ? 0 : offset;
if (birthday > 0) {
suffix = offset > 3 ? @"th" : [suffixes objectAtIndex:offset];
} else {
suffix = @"";
Interval Since Last Panic Report: 9356825 sec
Panics Since Last Report: 1
Anonymous UUID: DACAD640-50CA-4728-9F8B-6B39CDB98D5C
Wed Oct 27 18:10:35 2010
panic(cpu 0 caller 0x2a8ab2): Kernel trap at 0x0046d801, type 14=page fault, registers:
CR0: 0x80010033, CR2: 0x00000018, CR3: 0x00100000, CR4: 0x000006e0
EAX: 0x08bf0a9c, EBX: 0x08bf0a9c, ECX: 0x136cfe68, EDX: 0x00000000
CR2: 0x00000018, EBP: 0x5c77bd08, ESI: 0x136cfe68, EDI: 0x0a61f968
EFL: 0x00010293, EIP: 0x0046d801, CS: 0x00000008, DS: 0x022d0010