This file contains 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
import random | |
def memoize(f): | |
cache = {} | |
def memoized(*arg): | |
if arg in cache: | |
return cache[arg] | |
result = f(*arg) | |
cache[arg] = result | |
return result |
This file contains 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
public class RotationalHash { | |
public static int hash(String beads) { | |
byte[] buf = beads.getBytes(); | |
int hash = hashBytes(buf); | |
int i = 0; | |
int j = buf.length - 1; | |
while (i < j) { | |
buf[i] ^= buf[j]; | |
buf[j] ^= buf[i]; |
This file contains 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
'use strict'; | |
var slothful = (function() { | |
function _(step) { | |
var getResult = function() { return step(); }; | |
return function() { | |
var result = getResult(); | |
getResult = function() { return result; } | |
return result; |
This file contains 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
"use strict"; | |
// compose :: (b -> c) -> (a -> b) -> (a -> c) | |
function compose(g, f) { | |
return function() { | |
return g(f.apply(f, arguments)); | |
}; | |
} | |
// each :: [a] -> (a -> _) -> _ |
This file contains 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
1 (ns poker.core | |
2 (:use clojure.contrib.string)) | |
3 | |
4 (defrecord Card [value suit]) | |
5 | |
6 (def VALUE { | |
7 "1" :one | |
8 "2" :two | |
9 "3" :three | |
10 "4" :four |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> | |
<script src="scanva.js"></script> | |
<script src="particles.js"></script> | |
</head> | |
<body> | |
<canvas width="500px" height="500px" id="canvas"></canvas> | |
</body> |
This file contains 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
public class RangeSetsTest { | |
@Test public void | |
an_empty_list_of_ranges_is_coalesced_to_an_empty_set() { | |
Collection<Range<Integer>> ranges = newArrayList(); | |
assertThat(RangeSets.containing(ranges).size(), Matchers.is(0)); | |
} | |
@SuppressWarnings("unchecked") |
This file contains 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
@FunctionalInterface | |
public interface Judiciously<T> { | |
class WrappedException extends RuntimeException { | |
public WrappedException(Throwable cause) { | |
super(cause); | |
} | |
} | |
static <T> T attempt(Judiciously<T> f) { |
This file contains 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.youdevise.lofty | |
import org.specs2.mutable._ | |
import scala.language.dynamics | |
import scala.language.reflectiveCalls | |
import scalaz._ | |
import Scalaz._ | |
import scala.reflect.runtime.universe._ | |
trait Builder[T] { |
This file contains 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.youdevise.matchless | |
import org.specs2.matcher.MustMatchers._ | |
import com.youdevise.matchless.Collections._ | |
object HasThePairsWorksheet { | |
val testMap = Map( | |
"a" -> "Apple", | |
"b" -> "Banana", | |
"c" -> "Carrot" |
OlderNewer