Skip to content

Instantly share code, notes, and snippets.

View scsibug's full-sized avatar

Greg Heartsfield scsibug

View GitHub Profile
class Messages extends DispatchSnippet {
override def dispatch = {
case "all" => all _
case "top" => top _
case "paginate" => paginator.paginate _
case "detail" => detail _
}
@scsibug
scsibug / Fermata_Formula
Created October 27, 2010 04:43
Homebrew formula for fermata
require 'formula'
class Fermata < Formula
url 'http://ghsoftware.s3.amazonaws.com/fermata-0.6.tar.gz'
version '0.6'
homepage 'http://github.com/scsibug/fermata'
def install
bin.install 'fermata' # shell script, runs java -jar fermata.war
bin.install 'fermata.war' # executable jar/war
@scsibug
scsibug / blink.c
Created April 29, 2011 14:10
MSP430 button and LED demo
@scsibug
scsibug / cgol_golf.hs
Created December 5, 2011 07:02
Conway's Game of Life - Haskell
import Data.Set
import Prelude hiding (map, filter)
generation g = filter (\p -> or [liveRule p g, spawnRule p g]) (candidates g)
liveRule p g = (member p g) && ((neighborCount p g) `elem` [2,3])
spawnRule p g = not(member p g) && ((neighborCount p g) == 3)
neighborCount p g = size $ intersection (border p) g
@scsibug
scsibug / Prelude.hs
Created December 8, 2011 04:23
Hugs98 Prelude.hs (BSD-Licensed)
{----------------------------------------------------------------------------
__ __ __ __ ____ ___ _______________________________________________
|| || || || || || ||__ Hugs 98: The Nottingham and Yale Haskell system
||___|| ||__|| ||__|| __|| Copyright (c) 1994-1999
||---|| ___|| World Wide Web: http://haskell.org/hugs
|| || Report bugs to: hugs-bugs@haskell.org
|| || Version: February 1999_______________________________________________
This is the Hugs 98 Standard Prelude, based very closely on the Standard
Prelude for Haskell 98.
@scsibug
scsibug / qc_function.hs
Created December 14, 2011 23:10
QuickCheck.Function
import Test.QuickCheck
import Test.QuickCheck.Function
-- mapping any function over reverse of a list ==
-- reversing the map of that function of a list
prop_maprev ∷ [Int] → Fun Int String → Bool
prop_maprev i (Fun _ f) = map f (reverse i) == reverse (map f i)
@scsibug
scsibug / tictactoe.scala
Created February 1, 2012 23:31
tic-tac-toe (7 languages in 7 Weeks, Scala chapter)
import scala.Console
// Write a game that will take a tic-tac-toe board with X, O, and blank
// characters and detect the winner or whether there is a tie or no
// winner yet. Use classes where appropriate.
// Represent a board with X,O,blank plays.
class Board(positions:String) {
val winningTuples = List( (0,1,2), (3,4,5), (6,7,8), // L-to-R
(0,3,6), (1,4,7), (2,5,8), // T-to-B
(0,4,8), (2,4,6)) // Diagonal
@scsibug
scsibug / stringListSize.scala
Created February 1, 2012 23:32
string list size (7 languages in 7 weeks, Scala chapter)
val x = List("a", "aoe", "", "foo")
val sum = x.foldLeft(0)(_ + _.length)
println(x.mkString + " --> " + sum)
@scsibug
scsibug / censor.scala
Created February 1, 2012 23:33
censor (7 languages in 7 weeks, Scala chapter)
trait Censor {
val replacements = Map("Shoot" -> "Pucky",
"Darn" -> "Beans")
// Censor a string with multiple words
def censor(s:String):String = {
(s /: replacements){case (a,(k,v)) => a.replaceAll(k,v)}
}
}
object CensorApp extends Censor {
@scsibug
scsibug / string_words.erl
Created February 9, 2012 01:08
string_words erlang
-module(string_words).
-export([word_count/1]).
%Write a function that uses recursion to return the number of words in a string.
word_count([]) -> 0;
word_count([32]) -> 0;
word_count([_]) -> 1;
word_count([32|T]) -> word_count(T);
word_count([H|32]) -> word_count(H);
word_count([_,32|T]) -> 1+word_count(T);