This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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:] + '|' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def factorial(n): | |
| i = 1 | |
| factorial = 1 | |
| while i <= n: | |
| factorial = factorial * i | |
| i = i + 1 | |
| return factorial |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| file_contents = open 'filename.txt', &:read |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 | |
| ) |
NewerOlder