Skip to content

Instantly share code, notes, and snippets.

View liamoc's full-sized avatar

Liam O'Connor liamoc

View GitHub Profile
@liamoc
liamoc / 2048.el
Created April 16, 2014 17:39
Graphical enhancement to 2048-game.el.
;;; 2048.el --- play 2048 in Emacs (updated graphical version)
;; A mild extension for graphical improvements on the 2048-game.el
;; by Liam O'Connor to the game 2048 implemented in emacs by
;; Zachary Kafner
;; Copyright 2014 Zachary Kanfer
;; Author: Zachary Kanfer <zkanfer@gmail.com>
;; Version: 2014.03.27
@liamoc
liamoc / gist:d1295c91607e5bc9d2db
Created September 27, 2015 13:22
Quickcheck properties
Tests
basics
arbitrary instance: wf(l): OK (0.04s)
+++ OK, passed 5000 tests.
take, drop
take
commutativity: take n ∘ take m ≡ take m ∘ take n: OK (1.57s)
+++ OK, passed 5000 tests.
accumulativity: take m ∘ take n ≡ take (m ⊓ n): OK (1.54s)
+++ OK, passed 5000 tests.
@liamoc
liamoc / gist:2875241
Created June 5, 2012 14:11
Fun pointless style
import Control.Applicative
import Data.List
import qualified Data.Map as M
import Control.Arrow ((&&&), (***))
import Data.Char(isAlpha, toLower)
unscramble = curry $ fmap unwords
. uncurry mapM
. ( ( ( fmap head .)
. flip M.lookup
@liamoc
liamoc / gist:2972077
Created June 22, 2012 10:56
Implicit Parameters
data Eq a = Eq {
eq :: a -> a -> Bool,
neq :: a -> a -> Bool
}
(==) :: (?eq :: Eq a) => a -> a -> Bool
(==) = eq ?eq
(/=) :: (?eq :: Eq a) => a -> a -> Bool
(/=) = neq ?eq
@liamoc
liamoc / gist:3176041
Created July 25, 2012 12:55
Arbitrary DFAs with a total delta function
{-# LANGUAGE GADTs, DataKinds, KindSignatures, FlexibleInstances, ScopedTypeVariables #-}
import Test.QuickCheck
import Test.QuickCheck.Gen
import Control.Applicative
import Data.List
-- Peano naturals (used on value and type level)
data Nat = Zero | Suc Nat
@liamoc
liamoc / gist:3187282
Created July 27, 2012 10:18
Yaml example
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Yaml
import System.Environment
import Control.Applicative
data Whatever = Foo { courses :: [String], required :: Int } deriving Show
instance FromJSON Whatever where
@liamoc
liamoc / gist:3643591
Created September 5, 2012 19:58
Type-safe sum types in C
// needs -fnested-functions. Can be done without, but makes the whole thing a lot more cumbersome
// and less useful.
#include <stdio.h>
#define my_data_alts ( void (*A)(int) , void (*B)(int, int) , void (*C)(char, int) )
#define make_my_data(n) void n my_data_alts
typedef void (*my_data) my_data_alts;
void show(my_data match) {
@liamoc
liamoc / FakeWebFramework.hs
Created October 2, 2012 09:34
Fake Haskell routing DSL
{-# LANGUAGE GADTs, KindSignatures #-}
module FakeWebFramework (add , notActuallyAWebFramework, get, Handler', link) where
import UrlPath
import Control.Monad.Writer
import Data.Maybe
maybeRead :: (Read a) => String -> Maybe a
maybeRead s = case reads s of
[(x, "")] -> Just x
module bugreport where
open import Data.Nat
open import Data.Bool hiding (_≟_)
open import Relation.Nullary
⸤_⸥ : {A : Set} → Dec A → Bool
⸤ yes _ ⸥ = true
⸤ no _ ⸥ = false
@liamoc
liamoc / gist:762380
Created January 2, 2011 07:30
Creating Tables in C
#include <stdio.h>
/* BEGIN HACKERY */
typedef struct field {
enum {
TABLE_NAME,
TABLE_FIELD,
TABLE_TERMINATOR
} tag;