Skip to content

Instantly share code, notes, and snippets.

View thoferon's full-sized avatar

Tom Feron thoferon

View GitHub Profile
@thoferon
thoferon / predicated_list.v
Last active August 29, 2015 13:56
First attempt at predicated lists in Coq
Require Import Coq.Arith.Arith.
Section predicated_list.
Variable A : Type.
Variable bin_rel : A -> A -> Prop.
Hypothesis bin_rel_trans : forall a b c : A, bin_rel c b -> bin_rel b a -> bin_rel c a.
Set Implicit Arguments.
@thoferon
thoferon / weighted_avg.sql
Last active August 29, 2015 14:23
Aggregate function weighted_avg for PostgreSQL
CREATE TYPE _weighted_avg_fraction
AS (num double precision, denom double precision);
CREATE OR REPLACE FUNCTION _weighted_avg_step (acc _weighted_avg_fraction,
val anyelement, pond anyelement) RETURNS _weighted_avg_fraction AS $$
BEGIN
RETURN (acc.num + val * pond, acc.denom + pond);
END;
$$ LANGUAGE plpgsql;
(defproject name-with-dashes "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.4.0"]]
:main name-with-dashes.core)
@thoferon
thoferon / .gitconfig
Created November 29, 2012 13:19
Configuration files
[alias]
st = status
br = branch
co = checkout
ci = commit
[user]
name = Thomas Feron
email = /email/
[color]
branch = auto
@thoferon
thoferon / monad.rb
Last active December 11, 2015 13:09
Simple example to understand monads for Rubyists. See http://en.wikipedia.org/wiki/Monad_(functional_programming)#Formal_definition.
class Monad
attr_reader :value
def bind(f)
raise "not implemented"
end
def self.return(v)
self.new v
end
@thoferon
thoferon / dependent-types-confidence.hs
Last active December 20, 2015 09:30
Quick test with dependent types in Haskell
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
data Confidence = High | Medium | Low deriving (Show, Eq)
data Dataset :: Confidence -> * -> * where
Dataset :: [a] -> Dataset c a
@thoferon
thoferon / Pickle.hs
Created August 30, 2013 21:28
So, your PM is talking about Cucumber... Just an idea
import Control.Monad
import Control.Monad.Identity
import Control.Monad.Trans
import Control.Monad.Writer.Lazy
data Step
= Action String
| Assertion Bool String
deriving (Show, Eq)
@thoferon
thoferon / .emacs
Last active December 22, 2015 20:59
Emacs configuration
;; Packages required :
;; jujube-theme
;; haskell-mode
;; ghc
(require 'package)
(add-to-list 'package-archives
'("marmalade" .
"http://marmalade-repo.org/packages/"))
(package-initialize)
import parser from "./nonSequentialActions.js"
function generateDocumentation (parser) {
switch (parser.action) {
case "pure":
return null
case "stringField":
return { [parser.key]: "string" }
import readline from "readline-sync"
// Side effects
class EffectfulImplementation {
getUserInput () {
return readline.question("> ")
}
listTodoItems () {