Skip to content

Instantly share code, notes, and snippets.

@tfausak
tfausak / class-comparison.rb
Last active August 29, 2015 14:01
A rundown of the many ways to compare classes in Ruby.
# coding: utf-8
require 'rspec' # 2.14.1
# NOTE: "include?" and "included_modules" are for modules only.
CLASS_METHODS = %i(
!=
<
<=
<=>
@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 / 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)