Skip to content

Instantly share code, notes, and snippets.

View chbatey's full-sized avatar
🐯
WFH

Christopher Batey chbatey

🐯
WFH
View GitHub Profile
@chbatey
chbatey / gist:5302877
Created April 3, 2013 16:33
A snippet from ScalaTest of 7 languages in 7 weeks Scala day 1
class BoardSuite extends FunSuite with BeforeAndAfter {
var board : Board = _
before {
board = new Board
}
test("A board is initialized to blank") {
board.moves.foreach(row => row.foreach(box => assert(box === Player.B)))
}
@chbatey
chbatey / gist:5309993
Created April 4, 2013 12:31
Clojure hello world
(ns oobook-lein.core)
(defn hello-world []
(println "Hello world"))
@chbatey
chbatey / gist:5317208
Created April 5, 2013 07:02
FFoo Book: Clojure exercise 1
(def second (fn [list] ( nth list 1 ) ))
(def secondMkTwo (fn [list] ( first (rest list) ) ))
@chbatey
chbatey / gist:5317239
Created April 5, 2013 07:12
7 languages: Scala: Day2 E1
listOfStrings.foldLeft(0)((sum, value) => sum + value.length)
@chbatey
chbatey / gist:5317253
Created April 5, 2013 07:15
7 languages: Scala: Day2 E2a
trait Censor {
var alternatives = Map("Shoot" -> "Pucky", "Darn" -> "Beans")
def censor(input : String) : String = {
var toReturn = input
alternatives.foreach( entry => toReturn = toReturn.replace(entry._1, entry._2))
toReturn
}
}
@chbatey
chbatey / gist:5317264
Created April 5, 2013 07:18
7 languages: Scala: Day 2 E2B
import scala.io.Source._
trait CensorFromFile extends Censor {
val curses =
fromFile("day2/curses")
.getLines()
.map(_.split("="))
.map(fields => fields(0) -> fields(1)).toList
alternatives = Map(curses : _*)
public static <T> void mockIterable(Iterable<T> iterable, T... values) {
Iterator<T> mockIterator = mock(Iterator.class);
when(iterable.iterator()).thenReturn(mockIterator);
if (values.length == 0) {
when(mockIterator.hasNext()).thenReturn(false);
return;
} else if (values.length == 1) {
when(mockIterator.hasNext()).thenReturn(true, false);
when(mockIterator.next()).thenReturn(values[0]);
@chbatey
chbatey / mergesort.py
Created July 11, 2013 20:03
Merge sort in python
class MergeSort(object):
@staticmethod
def sort(array):
if len(array) <= 1:
return array
else:
middle = len(array)/2
left_half = MergeSort.sort(array[:middle])
right_half = MergeSort.sort(array[middle:])
@chbatey
chbatey / mergesort_test.py
Created July 11, 2013 20:07
mergesort_test
import unittest
from mergesort import MergeSort
class MergeSortTest(unittest.TestCase):
def setUp(self):
self.under_test = MergeSort()
def test_empty_array(self):
array_to_sort = []
class Service {
private Datastore datastore
Service(Datastore datastore) {
// ...
}
def processEntry(Map<String, String> someStuffToStore) {
// ...