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
(defn counted [f] | |
(let [times (atom 0)] ; thread safe counter | |
(with-meta (fn [& args] | |
(swap! times inc) | |
(apply f args)) | |
{:times times}))) ; associated as metadata | |
(defn times-runned [f] | |
@(:times (meta 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
(ns berlin.core) | |
(defn composed-lights [amount] | |
[(quot amount 5) | |
(rem amount 5)]) | |
(defn seconds-lights [ss] | |
(if (even? ss) 1 0)) | |
(defn lights [[hh mm ss]] |
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
(ns berlin.core) | |
(defn composed-lights [amount] | |
[(quot amount 5) | |
(rem amount 5)]) | |
(defn seconds-lights [ss] | |
(if (even? ss) 1 0)) | |
(defn lights [[hh mm ss]] |
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
(ns pyindent.core) | |
(def tabsize 8) | |
(defn tabulate [column] | |
(- (+ column tabsize) | |
(rem column tabsize))) | |
(defn indent-level [^String line] | |
(let [[_ spaces] (re-matches #"^(\s*).*" line)] |
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
(ns pyindent.test.core | |
(:use midje.sweet | |
pyindent.core)) | |
(fact "Tabs increment to the next multiple of 8" | |
(tabulate 0) => 8 | |
(tabulate 8) => 16 | |
(tabulate 7) => 8 | |
(tabulate 9) => 16) |
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 scala.collection.immutable | |
class Distro[T](probs: Seq[(T, Double)]) { | |
require((probs.map(_._2).sum - 1.0d).abs < Distro.delta) | |
val probMap: Map[T, Double] = mergeProbs(probs) | |
def map[B](f: T => B): Distro[B] = | |
new Distro(for ((event, prob) <- probMap.toSeq) yield (f(event), prob)) | |
def flatMap[B](f: T => Distro[B]): Distro[B] = |
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
(ns osmos.core) | |
(defn absorb [[size additions] mote] | |
(loop [size size | |
additions additions] | |
(cond | |
(< size 2) [size Double/POSITIVE_INFINITY] | |
(< mote size) [(+ size mote) additions] | |
:else (recur (+ size (dec size)) | |
(inc additions))))) |
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 cleancode | |
object NameInverter { | |
def apply(name: String): String = | |
swapFirstAndLast(splitName(name).dropWhile(isHonorific)).mkString(" ") | |
def swapFirstAndLast(parts: List[String]) = parts match { | |
case first :: last :: postNominals => last + "," :: first :: postNominals | |
case _ => parts |
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 xmas | |
object Tree { | |
def apply(n: Int) = { | |
val width = n * 2 - 1 | |
def center(line: String) = { | |
val padding = " " * ((width - line.length) / 2) | |
padding ++ line ++ padding | |
}.mkString | |
def line(row: Int) = row * 2 + 1 |
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
sub locs { | |
my $repo = shift; | |
`sloccount $repo | grep ^java` =~ /^java:\s+(\d+)/; | |
return $1; | |
} |