Skip to content

Instantly share code, notes, and snippets.

@zackdouglas
zackdouglas / with_ex.py
Created March 29, 2013 21:53
Playing with Python `with` statement
# $ python -i withtest.py
# initializing <__main__.cex instance at 0x10f219e18> () {}
# entering <__main__.cex instance at 0x10f219e18> () {}
# with <__main__.cex instance at 0x10f219e18>
# exiting <__main__.cex instance at 0x10f219e18> (None, None, None) {}
class cex:
def __enter__(slf, *a, **k):
print 'entering', slf, a, k
return slf
def __exit__(slf, *a, **k):
@zackdouglas
zackdouglas / hoist.js
Created January 24, 2013 15:47
JS Hoist implementation
function hoist (source, target, property, prfx, sufx) {
for (var p in source[property]) {
target[(prfx||'') + p + (sufx||'')] = source[property][p];
}
}
var source = {
loader: {
fire: function () { alert('fire!') }
}
@zackdouglas
zackdouglas / gist:3313945
Created August 10, 2012 12:42
Diff output of two commands
$ diff <(echo "Hello") <(echo "h3ll0")
1c1
< Hello
---
> h3ll0
@zackdouglas
zackdouglas / shrink-all-the-css.sh
Created July 17, 2012 14:10
Shrink the dang CSS
sed ':a; $!N; s/[\r\n]//g; s/\/\*.*\*\///g; ta; s/ *\([{!:;,}]\) */\1/g; s/}[^{]*{}/}/g;'
@zackdouglas
zackdouglas / Copyright.md
Created July 16, 2012 16:19
Detect if *nix shell script reading from pipe, readfile, or stdin
@zackdouglas
zackdouglas / xgmaps.js
Created June 5, 2012 12:19
A Google Maps Bookmarklet
javascript:var v_='1.0.0', p={home:'', work:''}, arr,addr='',newURL='',i=0,t='', sub=function(s){return p[s]||s;}, URLEncode=function (a){var b='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.!~*%25()', c='0123456789ABCDEF', d='',e='',f=''; for(i=0;i<a.length;i++){ e=a.charAt(i); if(e==' ') d+='+'; else if(b.indexOf(e)!=-1) d+=e; else{ f=e.charCodeAt(0); if(f>255){ alert('Character %25'+e+'%25 will be encoded as a space will be used.'); d+='+'; } else{ d+='%'+c.charAt((f>>4)&0xF)+c.charAt(f&0xF)}}} return d}; if(typeof String.prototype.trim == 'undefined'){ String.prototype.trim = function(){ return this.replace(/^\s\s*/,'').replace(/\s\s*$/,'')}} if(typeof document.getSelection()=='string'&&(addr=document.getSelection()).length>0&&confirm('XGMaps detected a possible address selection. Would you like XGMaps to use this selection?')){} else{ addr=unescape('%s'); if(addr=='%25s'){ addr='home'} if(addr.indexOf('--')!=-1){ arr=addr.split('--'); addr='from:'+sub(arr[0].trim()); for(i=1;i<arr.leng
@zackdouglas
zackdouglas / hack.sh
Created March 31, 2012 18:02 — forked from steveklabnik/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@zackdouglas
zackdouglas / array-until.js
Created March 28, 2012 12:15
Iterate over an array until a condition is true
Array.prototype.until = function ( test, fn) {
var l = this.length,
i = l,
_;
for ( ; i && !test( _ = this[l-i] ) ; --i ) {
fn( _ );
}
};
@zackdouglas
zackdouglas / plain_language.txt
Created March 9, 2012 15:16 — forked from steveklabnik/plain_language.txt
Hypermedia benefits in plain language
Hypermedia designs scale better, are more easily changed, and promote decoupling
and encapsulation; with all the benefits those things bring. On the downside,
it is not necessarily the most latency-tolerant design, and caches can get stale
if you're not careful. It may not be as efficient on an individual request level
as other designs.
For those folks not already hanging out in #documentcloud... here's the log of this afternoon's Ember/Backbone politics discussion.
12:21 PM <wycats> jashkenas: hey
12:21 PM <wycats> jashkenas: I'm sorry
12:21 PM <wycats> how would you like me to describe backbone?
12:21 PM <wycats> let's work this out for once and for all :)
12:21 PM <wycats> I'm definitely not intentionally saying incorrect things about backbone
12:22 PM • knowtheory gets out popcorn
12:24 PM <jashkenas> don't worry about it too much -- I'm just not terribly pleased with backbone being continued to be used as the strawman...
12:24 PM <wycats> jashkenas: I am worried about it a lot