Skip to content

Instantly share code, notes, and snippets.

View matthewadowns's full-sized avatar

Matthew Downs matthewadowns

View GitHub Profile
@remy
remy / gist:350433
Created March 31, 2010 14:58
Storage polyfill
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
@adamsanderson
adamsanderson / test_mail_purge.rb
Created December 18, 2010 04:35
An example of using MiniTest::Mock
require 'minitest/mock'
require 'minitest/unit'
require 'date'
MiniTest::Unit.autorun
class TestMailPurge < MiniTest::Unit::TestCase
class MailPurge
def initialize(imap)
@imap = imap
@stagas
stagas / how-to-run-apache-and-node.js-together-the-right-way.markdown
Created December 24, 2010 14:45
How to run Apache and Node.js together (the right way)

Step 1

Get a VPS that offers 2 or more IP addresses.

Step 2

From the WHM cPanel, find the menu item Service Configuration, select Apache Configuration and then click on Reserved IPs Editor.

Step 3

@juliocesar
juliocesar / best-localStorage-polyfill-evar.js
Created April 18, 2011 23:19
This is the best localStorage polyfill in the world
// I mean, seriously, localStorage is supported even by your mum. How about instead of
// casing the feature out, you give users in-memory (stale) storage instead?
// If they close your application, they deserve to lose data anyway.
// if (!('localStorage' in window)) {
if (!Modernizr.localstorage) {
window.localStorage = {
_data : {},
setItem : function(id, val) { return this._data[id] = String(val); },
getItem : function(id) { return this._data.hasOwnProperty(id) ? this._data[id] : undefined; },
@jordansissel
jordansissel / output
Created October 11, 2011 08:40
Context- and Structure-friendly logging in Ruby
Project here:
https://github.com/jordansissel/ruby-cabin
% ruby examples/sample.rb
I, [2011-10-11T01:45:04.011360 #1441] INFO -- : {"timestamp":"2011-10-11T01:45:04.010614-0700","program":"sample program","foo":"Hello","example":100,"message":"bar bar bar!","level":"info"}
I, [2011-10-11T01:45:05.173034 #1441] INFO -- : {"timestamp":"2011-10-11T01:45:05.172846-0700","program":"sample program","foo":"Hello","example":100,"message":"Timing bar","duration":1.162167376}
I, [2011-10-11T01:45:05.173392 #1441] INFO -- : {"timestamp":"2011-10-11T01:45:05.173322-0700","program":"sample program","foo":"Hello","example":100,"message":"bar bar bar!","level":"info"}
I, [2011-10-11T01:45:05.740390 #1441] INFO -- : {"timestamp":"2011-10-11T01:45:05.740275-0700","program":"sample program","foo":"Hello","example":100,"message":"Another bar timer","duration":0.566953405}
I, [2011-10-11T01:45:05.740577 #1441] INFO -- : {"timestamp":"2011-10-11T01:45:05.740530-0700","program":"sample program","message":"All done.","le
@gcoop
gcoop / qunit-runner.js
Created January 10, 2012 10:42
QUnit runner using PhantomJS.js
//
// Runs a folder of tests or a single test, using QUnit and outputs a JUnit xml file ready for sweet integration with your CI server.
//
// @usage
// DISPLAY=:0 phantomjs qunit-runner.js --qunit qunit.js --tests tests-foler/ --package package.json --junit qunit-results.xml
//
// package.json is a common JS package file which contains a list of files that need to be loaded before the tests are run. In this instance
// the package.json lists the files for a JS SDK, that gets loaded and then the tests test the SDK.
//
// Designed to run via PhantomJS.
@mshafrir
mshafrir / states_hash.json
Created May 9, 2012 17:05
US states in JSON form
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
@iros
iros / API.md
Created August 22, 2012 14:42
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

@domenic
domenic / promises.md
Last active April 1, 2025 01:54
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
@stevenyap
stevenyap / Rails Controller.md
Created October 19, 2013 13:58
Rails controller cheatsheet

Flash

# supports only notice and alert by default
# the rest has to go into flash hash
redirect_to :index, notice: "success"
redirect_to :new, notice: "errors"
redirect_to :new, flash: { success: "yeah" }
flash[:info] = "updated"