Skip to content

Instantly share code, notes, and snippets.

@alexspeller
alexspeller / source_maps.rb
Created September 16, 2012 00:03
Coffeescript Source Maps in Rails
# config/initializers/source_maps.rb
if Rails.env.development?
require 'open3'
module CoffeeScript
class SourceMapError < StandardError; end;
class << self
def map_dir
@acdha
acdha / active_value_filter.py
Created August 31, 2012 20:14
Django admin list_filter which filters out values which are not used in the current queryset
from django.contrib.admin import FieldListFilter
from django.utils.translation import ugettext as _
class ActiveValueFilter(FieldListFilter):
"""list_filter which displays only the values for a field which are in use
This is handy when a large range has been filtered in some way which means
most of the potential values aren't currently in use. This requires a
queryset field or annotation named "item_count" to be present so it can
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@mpasternacki
mpasternacki / rename-node.rb
Created March 1, 2012 19:17
A knife exec script to change Chef node's name.
#!./bin/knife exec
# A knife exec script to change chef node's name, preserving all the attributes.
#
# Usage: knife exec rename-node.rb old-name new-name
#
# Script retrieves the Node object, changes its 'name' attribute,
# creates new Node object with updated name and rest of attributes
# untouched. Then it deletes old Node and Client objects from
# database, and logs into the server to update it:
@addyosmani
addyosmani / backboneglobalpubsub.md
Created February 4, 2012 19:37
Backbone.js global pub/sub

Generally one implements notifications by listening for events on specific models but if one wishes to have a single global message interchange, it could be done as follows:

var pubsub = new Backbone.Model;

View1 = Backbone.View.extend({
  initialize: function(){
    pubsub.bind('custom event', callback);
  }
 // ...
@bryanveloso
bryanveloso / brew-services.rb
Created December 8, 2011 09:39 — forked from lwe/brew-services.rb
External script for homebrew to simplify starting services via launchctl, out of the box support for any formula which implements #startup_plist. (This version fixes the deprecation warning raised on Formula.resolve_alias.)
#!/usr/bin/env ruby -w
# brew-services(1) - Easily start and stop formulas via launchctl
# ===============================================================
#
# ## SYNOPSIS
#
# [<sudo>] `brew services` `list`<br>
# [<sudo>] `brew services` `restart` <formula><br>
# [<sudo>] `brew services` `start` <formula> [<plist>]<br>
@tmiz
tmiz / CoreLocationTest.m
Created December 1, 2011 12:08
Using CoreLocation on Mac OS X with command-line
//
// Using CoreLocation on Mac OS X with command-line
// $ clang CoreLocationTest.m -framework cocoa -framework CoreLocation
// $ ./a.out
// location service enabled
// 2011-12-01 21:03:01.839 a.out[10214:903] latitude,logitude : 35.606647, 140.695538
// 2011-12-01 21:03:01.842 a.out[10214:903] timestamp : 2011-12-01 21:01:36 +0900
// tmiz moo@tmiz.net
//
#import <cocoa/cocoa.h>
@progrium
progrium / bash
Created November 13, 2011 11:39
parse_http for nc http
# writes host to a host file
nc -l -p 9998 -c "./parse_http>/tmp/cgi;. /tmp/cgi>/dev/null && echo $HTTP_HOST > host"
# pipemill the request body
nc -l -p 9998 -c "./parse_http>/tmp/cgi;. /tmp/cgi | while read line; do something; done"
# route on the path
# uhh, well, sure, just use if on $HTTP_PATHINFO
"Diversity is not about big sticks and hitting people over the head.
It is about creating a welcome and open environment and active
efforts to recruit members who would not otherwise participate.
Great efforts by PyLadies are proving to be very effective.
In contrast, big stick politics drive people away.
Please abandon this notion of using diversity as a stick to bonk
people over the head. It is counterproductive, misguided and offensive."
@carljm
carljm / postactivate
Created July 12, 2011 18:21
Yo dawg, I heard you like Ruby...
#!/bin/bash
# This hook is run after every virtualenv is activated.
export OLD_GEM_HOME=$GEM_HOME
export GEM_HOME=$VIRTUAL_ENV/gems/
export GEM_PATH=
export PATH=$VIRTUAL_ENV/gems/bin:$PATH