Skip to content

Instantly share code, notes, and snippets.

View vlazzle's full-sized avatar

Vlad Chernis vlazzle

  • San Diego
View GitHub Profile
package com.twitter.externalstorage;
import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
http://en.wikipedia.org/wiki/Church_numerals#Church_pairs (example)
fst (pair a b)
\p.p (\x.\y.x) ((\x.\y.\z.z x y) a b)
\p.p (\x.\y.x) (\z.z a b)
???
(\z.z a b) (\x.\y.x)
(\x.\y.x) a b
a
#################################################
# currying and partial application in python #
# based on code from Simon Willison's geocoders #
#################################################
# curries fn, a function of exactly 2 parameters
def partial2(fn):
def inner1(arg2):
def inner2(arg1):
return fn(arg1, arg2)
/*
* usage example:
* $('body').zIndices()
*
* Returns a hash with z-indices as keys whose corresponding
* values are elements with that z-index set. Any z-index <z>
* having more than one element will also be in the hash
* under the key '!<z>' (to be sorted together near the top),
* as well as the regular key, '<z>'.
*/
def really_in(y, xs):
if y is not True and y is not False:
'''thanks http://www.reddit.com/r/Python/comments/asmwr/python_boolean_coercion_gotchas/c0j7cd7?context=3'''
return y in xs
for x in xs:
if y is x: return True
return False
True in [1, 2, 3] # -> True
def test_filtered_really_in_2(y, xs):
def pred(e): return e is y
return filter(pred, xs)
# if there are any others who don't care much for try ... catch AttributeError
def hasmethods(obj, *meth_names):
return all(
hasattr(
# if it calls like a method it's a method
getattr(obj, m, None),
'__call__'
) for m in meth_names
)
from urllib import urlopen
from xml.dom import minidom
import re
REGIONAL_REPORT_FEED = 'http://www.surfline.com/rss/region.cfm?id=2958'
GOOD_WORDS = re.compile(r'good|epic|solid|fun', re.IGNORECASE)
HEIGHTS = re.compile(r'\d+')
GOOD_HEIGHT = 4
def is_of_interest(title):
@vlazzle
vlazzle / soundcloud_loop.js
Created September 22, 2011 00:52
Bookmarklet to play a SoundCloud track in loop
// note: currently, this only works for an individual track, e.g. the main track on
// http://soundcloud.com/tall-cans/el-pico-acoustic-ratatat-cover
//
// bookmarklet:
// (function($)%20{var%20$play%20=%20$(%27.controls%20a.play:first%27),poll%20=%20true;function%20startPolling()%20{setInterval(function()%20{if%20(poll)%20{if%20(!$play.hasClass(%27playing%27))%20{$play.trigger(%27click%27,%20true);}}},%20500);}$play.bind(%27click%27,%20function(e,%20loop)%20{if%20(typeof%20loop%20===%20%27undefined%27%20||%20!loop)%20{poll%20=%20!$play.hasClass(%27playing%27);}});startPolling();}(jQuery));
(function($) {
var $play = $('.controls a.play:first'),
poll = true;
@vlazzle
vlazzle / soundcloud_loop_track_bookmarklet.js
Created September 22, 2011 01:49
bookmarklet to loop a track in soundcloud
(function($)%20{var%20$play%20=%20$(%27.controls%20a.play:first%27),poll%20=%20true;function%20startPolling()%20{setInterval(function()%20{if%20(poll)%20{if%20(!$play.hasClass(%27playing%27))%20{$play.trigger(%27click%27,%20true);}}},%20500);}$play.bind(%27click%27,%20function(e,%20loop)%20{if%20(typeof%20loop%20===%20%27undefined%27%20||%20!loop)%20{poll%20=%20!$play.hasClass(%27playing%27);}});startPolling();}(jQuery));