Skip to content

Instantly share code, notes, and snippets.

View alexyoung's full-sized avatar
💤

Alex Young alexyoung

💤
View GitHub Profile
@alexyoung
alexyoung / Makefile
Created November 27, 2011 23:41
Publish a subdirectory of documentation to a gh-pages branch
publishdocs:
$(eval PARENT_SHA := $(shell git show-ref -s refs/heads/gh-pages))
$(eval DOC_SHA := $(shell git ls-tree -d HEAD docs | awk '{print $$3}'))
$(eval COMMIT := $(shell echo "Auto-update docs." | git commit-tree $(DOC_SHA) -p $(PARENT_SHA)))
@git update-ref refs/heads/gh-pages $(COMMIT)
@alexyoung
alexyoung / 2011-11-28-flickr-breakdown.md
Created November 27, 2011 14:58 — forked from voidfiles/gist:1397205
Breakdown of flickr's pre-script loading event handler

Production Tear Down: How Does Flickr Handle Loading Scripts Asynchronously?

If you are using an async loader, or even if you are just putting your scripts at the bottom of your DOM, you have a problem. In some cases your scripts will load after the user has clicked on something that requires a JavaScript function to handle the click. It's possible you have a pure HTML version, but if the user has JavaScript we want them to use it, even if the JavaScript hasn't loaded yet. You need some way of handling events before all of your assets have finished loading.

There are a number of ways we could do this, but it's helpful to look at a working implementation. This is going to be a two part series. First, we are going to look at how Flickr does this. In the second part, we can take the code that Flickr uses and extract the main features so that anyone can use the code.

In all of the code that Flickr loads before the body this is the part that matters to us: [Isolated actionQueue Code](https://gist.github.com/139

@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