Skip to content

Instantly share code, notes, and snippets.

View cbarrett's full-sized avatar
🏴
Revolting

Colin Barrett cbarrett

🏴
Revolting
View GitHub Profile
@cbarrett
cbarrett / .gitignore
Created April 4, 2011 05:35
adium multi nightly changes
.DS_Store
@cbarrett
cbarrett / SSMutableIndexPathSet.h
Created July 19, 2011 18:04
Represent a set of index paths
//
// SSMutableIndexPathSet.h
// MutableIndexPathSet Test
//
// Created by Colin Barrett on 11/19/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@cbarrett
cbarrett / gist:1642401
Created January 19, 2012 20:31
Had this laying around for quite a while -- really useful and kind of dumb it's not built in...
// stringByAddingPercentEscapesUsingEncoding is pretty conservative about escaping characters, which is fine most of the time. This method however escapes *all special characters*, allowing any arbitrary string to be used when building any part of a URL.
// (c) 2011 Springs & Struts. Released under MIT-style license. See: http://www.opensource.org/licenses/mit-license.php
@interface NSString (SSURLEscaping)
- (NSString *)ss_stringByEscapingAllURLCharactersForRealWithEncoding:(NSStringEncoding)encoding;
@end
@implementation NSString (SSURLEscaping)
- (NSString *)ss_stringByEscapingAllURLCharactersForRealWithEncoding:(NSStringEncoding)encoding
### 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:
@cbarrett
cbarrett / Reducer.swift
Last active August 22, 2017 00:19
Some fun with Reducers
// 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
}
}
@cbarrett
cbarrett / AtomicPtr.swift
Last active March 9, 2017 04:13
Simple atomic pointer
// 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?) {
@cbarrett
cbarrett / dhall.swift
Last active January 17, 2017 04:56
Notes from my stream on 2017/01/16
// 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)
/* 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: */
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
@cbarrett
cbarrett / delim-cont-reactive.rkt
Last active December 12, 2015 05:28
Using delimited continuations to implement RAC's signal type
#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)])))