Skip to content

Instantly share code, notes, and snippets.

@tfausak
tfausak / Main.hs
Created May 29, 2014 15:24
A simple example of FFI in Haskell using the standard library, a source file, and a library.
{-# LANGUAGE ForeignFunctionInterface #-}
module Main (main) where
import Foreign.C.Types (CDouble (..))
foreign import ccall safe "math.h sin" c_sin :: CDouble -> CDouble
foreign import ccall safe "public.h square" c_square :: CDouble -> CDouble
foreign import ccall safe "private.h half" c_half :: CDouble -> CDouble
@tfausak
tfausak / Swifty8.swift
Last active August 29, 2015 14:02
2048 implemented in Swift via Haskell.
// http://taylor.fausak.me/2014/04/28/cloning-2048-in-haskell/
import func Cocoa.rand
/*
Utilities
*/
// TODO: Can this be generalized to allow anything addable?
func combine(array: Int[]) -> Int[] {
@tfausak
tfausak / doctest.rb
Last active May 22, 2018 13:12
Test Ruby code in Markdown files.
#!/usr/bin/env ruby
pattern = /^```(.*)/
capturing = false
language = ''
lines = {}
File.open(ARGV.shift).each_line do |line|
match = pattern.match(line)
@tfausak
tfausak / hs2048.hs
Created June 16, 2014 02:02
Difference between blog post and Hs2048.
import Data.List (group)
import Data.Maybe (isJust)
import Data.Monoid ((<>))
empty :: Int -> [Maybe Int]
empty = flip replicate Nothing
shift :: [Maybe Int] -> [Maybe Int]
shift v = take n (v' <> empty n)
where

Keybase proof

I hereby claim:

  • I am tfausak on github.
  • I am taylorfausak (https://keybase.io/taylorfausak) on keybase.
  • I have a public key whose fingerprint is 1074 397C 56E3 4F1B FBDA 9D31 9C45 BE88 5CC1 680A

To claim this, I am signing this object:

@tfausak
tfausak / stoplight.rb
Created August 17, 2014 18:16
Exploratory attempt at storing all stoplight runs.
class Run
attr_reader :state
attr_reader :exception
attr_reader :time
def initialize(state, exception = nil, time = nil)
@state = state
@exception = exception
@time = time.nil? ? Time.now : time
end
@tfausak
tfausak / pfds-5-1.hs
Last active August 29, 2015 14:05
Exercise 5.1 from Purely Functional Data Structures
-- Purely Functional Data Structures
-- Exercise 5.1
module Main
( Deque (Deque)
, empty
, isEmpty
, cons
, head
, tail
@tfausak
tfausak / erudite.rb
Last active August 29, 2015 14:05
Ruby doctest
# coding: utf-8
require 'stringio'
module Erudite
class Outcome
attr_reader :result
attr_reader :output
def initialize(result, output)
diff --git a/lib/active_interaction/base.rb b/lib/active_interaction/base.rb
index 64c70c3..9f5f61d 100644
--- a/lib/active_interaction/base.rb
+++ b/lib/active_interaction/base.rb
@@ -168,7 +168,18 @@ module ActiveInteraction
attr_accessor filter.name
define_method("#{filter.name}?") { !public_send(filter.name).nil? }
- filter.default if filter.default?
+ initialize_default(filter)