This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am cbarrett on github. | |
* I am chbarrett (https://keybase.io/chbarrett) on keybase. | |
* I have a public key ASDhSCmtfibfvZ0Lo54bUO6YcFc7iqAiFDj0Um0oFWhc9wo | |
To claim this, I am signing this object: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// type State = ... | |
// infix operator <>: AdditionPrecedence | |
// enum Either<A, B> { ... | |
struct Reducer<Action> { | |
let reduce: (Action, State) -> State | |
init(_ f: @escaping (Action, State) -> State) { | |
reduce = f | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2017 Colin Barrett, all rights reserved. | |
// License freely granted under the terms of CC-BY-NC <https://creativecommons.org/licenses/by-nc/4.0/>. | |
import Darwin | |
public class AtomicPointer<Pointee>: Equatable { | |
fileprivate var ptr: UnsafeMutablePointer<Pointee?> | |
fileprivate var flag: atomic_flag = atomic_flag() | |
public init(_ pointee: inout Pointee?) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dhall, a terminating configuration language | |
// Syntax: https://github.com/Gabriel439/Haskell-Dhall-Library/blob/master/src/Dhall/Core.hs | |
// This gist's history: | |
// 1. Contents at stream end | |
// 2. Clean up free vs. bound variables | |
enum Expr { | |
case constant(Int) | |
case variable(Bound) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- You can find the original in section 4.3.2 of SICP: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-28.html#%_sec_4.3.2 | |
import Data.List | |
distinct :: Eq a => [a] -> Bool | |
distinct xs = length (nub xs) == length xs | |
require :: Bool -> [[a]] -> [[a]] | |
require b e = if b then e else return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Let's say you want to list all of the options to your program as an enum */ | |
enum Option { | |
OptionFoo, | |
OptionBar, | |
CountOfOption | |
} | |
/* You want to write a procedure to generate a help message for your program. Here's one way: */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addDependentTree :: FilePath -> Bool -> Q () | |
addDependentTree p inclFile = do | |
pwd <- runIO getCurrentDirectory | |
let p' = if not inclFile then dropFileName p else p | |
let paths = scanl (</>) pwd (splitDirectories p') | |
mapM_ addDependentFile paths -- We add every subdirectory along `p` in the hopes of catching any new files added therein |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang scheme | |
(require racket/control) | |
(require racket/match) | |
(define (create-signal didSubscribe) | |
(lambda (next error complete) | |
(match (shift k (didSubscribe k)) | |
[(list 'next v) (next v)] | |
[(list 'error e) (error e)] | |
[(list 'complete) (complete)]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Applicative | |
import Control.Monad | |
import Data.ByteString (ByteString) | |
import qualified Data.ByteString as B | |
import qualified Data.ByteString.Char8 as C | |
import Data.Map (Map) | |
import qualified Data.Map as M | |
import Text.Parsec hiding ((<|>), many) | |
import Text.PrettyPrint.HughesPJ ((<>), brackets, text, braces, hsep) | |
import qualified Text.PrettyPrint.HughesPJ as P |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Applicative | |
import Control.Monad | |
import qualified Data.ByteString as B | |
import qualified Data.ByteString.Char8 as C | |
import qualified Data.Map as M | |
import Text.Parsec hiding ((<|>), many) | |
import qualified Text.PrettyPrint.HughesPJ as P | |
type Parser = Parsec B.ByteString () |
NewerOlder