Skip to content

Instantly share code, notes, and snippets.

View owainlewis's full-sized avatar

Owain Lewis owainlewis

View GitHub Profile
@monkeygroover
monkeygroover / gist:0e4e2f5648b91c3bc6c4
Last active August 29, 2015 14:23
shapelessspray
import org.ensime.json.FamilyFormats
import spray.json._
object MainApp extends App {
case class Foo(blah: String, blah2: Option[String])
case class Bar(boo: List[Foo])
val wat = Bar(Foo("dfsdf", Some("dsfd")) :: Foo("feefef", None) :: Nil)
(ns type-level-tagger
{:doc "Implements State-of-the-art Unsupervised Part-of-speech Tagger
from \"Simple Type-Level Unsuperivsed POS Tagging\"
by Yoong-Keok Lee, Aria Haghighi and Regina Barzilay
(http://www.cs.berkeley.edu/~aria42/pubs/typetagging.pdf)
blog post: http://wp.me/pcW6S-x"
:author "Aria Haghighi (aria42@gmail.com)"}
(:use [clojure.java.io :only [reader]]
[clojure.contrib.duck-streams :only [with-out-writer]]
[clojure.contrib.seq-utils :only [indexed]]
@ehamberg
ehamberg / bktree.hs
Created December 8, 2011 13:40
Implementation of a BK-Tree in Haskell
import qualified Data.Map as M
import Control.Applicative
import Data.Maybe (mapMaybe)
-- A BK-Tree is has a root word and more trees connected to it with branches of
-- lengths equal to the Levenshtein distance between their root words (i.e. an
-- n-ary tree).
data BKTree s = BKTree s (M.Map Int (BKTree s)) | Empty deriving (Show)
-- Inserting a word is done by inserting it along a branch of lenght
@channingwalton
channingwalton / gist:3230464
Created August 1, 2012 20:31
Example of Kleisli composition of Validation
object KleisliValidation extends App {
import scalaz._
import Scalaz._
import scala.util.control.Exception._
type EValidation[+T] = Validation[String, T]
implicit val binding = new Bind[EValidation] {
def map[A, B](fa: EValidation[A])(f: A => B): EValidation[B] = fa.map(f)
def bind[A, B](fa: EValidation[A])(f: A => EValidation[B]): EValidation[B] = fa.flatMap(f)
}
(ns dojo.core
(:require
[clojure.string :as str]))
;;;
(def digits
[[" _ " "| |" "|_|"]
[" " " |" " |"]
[" _ " " _|" "|_ "]
@richhickey
richhickey / thread.clj
Created October 13, 2012 17:43
new thread macros draft
(defmacro test->
"Takes an expression and a set of test/form pairs. Threads expr (via ->)
through each form for which the corresponding test expression (not threaded) is true."
[expr
& clauses]
(assert (even? (count clauses)))
(let [g (gensym)
pstep (fn [[test step]] `(if ~test (-> ~g ~step) ~g))]
`(let [~g ~expr
~@(interleave (repeat g) (map pstep (partition 2 clauses)))]
@koddo
koddo / gist:4555655
Last active December 11, 2015 05:58
for Coursera / Programming Languages
;; for Coursera / Programming Languages
;; in emacs sml-mode: single keystroke for restarting repl and loading current file
(require 'cl)
(add-hook 'sml-mode-hook
(lambda ()
(define-key sml-mode-map (kbd "C-c C-v") 'my-sml-restart-repl-and-load-current-file)
(defun my-sml-restart-repl-and-load-current-file ()
(interactive)
(ignore-errors (with-current-buffer "*sml*"
(comint-interrupt-subjob)
@lrvick
lrvick / controllers.js
Last active December 14, 2015 19:09
Websocket AngularJS controller/services pattern
app.controller( 'AppCtrl', function ($scope, socket) {
socket.onopen(
function(){
console.log('Socket is connected :D')
}
)
socket.onclose(
function(){
console.log('Socket is disconnected :(')
}
@sw17ch
sw17ch / indented_parsec_example.lhs
Created March 16, 2012 04:31
A full example demonstrating the use of the indentation parser provided by the 'indents' package: http://hackage.haskell.org/package/indents
> module Main where
First, import all the needed modules.
> import Text.Parsec hiding (State)
> import Text.Parsec.Indent
> import Control.Monad.State
Next, define our new Parser type. This replaces the Identity monad
with the (State SourcePos) monad.
@hyone
hyone / gist:3950460
Created October 25, 2012 04:49
Multiple async HTTP requests by Haskell
{-# LANGUAGE FlexibleContexts #-}
import Data.Conduit
import qualified Data.Conduit.List as CL
import Network.HTTP.Conduit
import Control.Concurrent.Async (mapConcurrently)
import Control.Concurrent.MVar
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Control (MonadBaseControl)