Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View vlazzle's full-sized avatar

Vlad Chernis vlazzle

  • San Diego
View GitHub Profile
sealed class Either<L, R> {
class Left<L1, R1>(val left: L1) : Either<L1, R1>()
class Right<L1, R1>(val right: R1) : Either<L1, R1>()
}
val left: Either<String, Throwable> = Either.Left("foo")
val right: Either<String, Throwable> = Either.Right(Throwable("bar"))
val leftOrRight = left
val x: String = when (leftOrRight) {
def print_abacus(value):
abacus = '00000*****'
for i in range(0, 10):
power_of_ten = 9 - i
row_factor = pow(10, power_of_ten)
num_beads = value / row_factor
if num_beads > 0:
value = value % row_factor
divider = 10 - num_beads
print '|' + abacus[:divider] + ' ' + abacus[divider:] + '|'
def factorial(n):
i = 1
factorial = 1
while i <= n:
factorial = factorial * i
i = i + 1
return factorial
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;
@vlazzle
vlazzle / quick_read.rb
Created February 16, 2012 19:17
ruby one-liner for opening a file and reading its contents
file_contents = open 'filename.txt', &:read
@vlazzle
vlazzle / native.js
Created January 27, 2012 00:19
native methods for javascript collections
var obj = {foo: 4, bar: 7};
// returns an array of keys: [ 'foo', 'bar' ]
Object.keys(obj);
var arr = [3, 6, 9];
// returns a new array: [ 4, 7 ]
arr.map(function(n) { return n + 1; });
@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));
@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;
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):
# 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
)