Skip to content

Instantly share code, notes, and snippets.

View vlazzle's full-sized avatar

Vlad Chernis vlazzle

  • San Diego
View GitHub Profile
@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
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;
def factorial(n):
i = 1
factorial = 1
while i <= n:
factorial = factorial * i
i = i + 1
return factorial
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:] + '|'
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) {