Skip to content

Instantly share code, notes, and snippets.

View jonsterling's full-sized avatar

Jon Sterling jonsterling

View GitHub Profile

Things About Interface Builder in No Particular Order

I have many other problems with Interface Builder beyond the ones here; these are just the ones that immediately came to mind. Likewise, however unsafe I have characterized IB to be in this tract, I assure you, it is far more unsafe than that.

Fragility: stringly styped code strikes again (bite me)

There are a number of places where IB-style stuff encourages unchecked stringly-typed code, and worse, the kind of stringly-typed code that doesn't allow you to use the same constant everywhere to provide some semblance of sanity.

  1. Cell reuse identifiers.
  2. Storyboard scene identifiers.
{-# OPTIONS --type-in-type --no-positivity-check --no-termination-check #-}
module IndexingByCanonicity where
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
π₁ : A
π₂ : B π₁
open Σ public
@jonsterling
jonsterling / gist:5940947
Created July 6, 2013 19:23
Installing Idris / libffi on Mac OS 10.8
@jonsterling
jonsterling / gist:5941001
Created July 6, 2013 19:40
Homebrew libffi installation errors

brew --config:

HOMEBREW_VERSION: 0.9.4
ORIGIN: https://github.com/mxcl/homebrew.git
HEAD: 0c1bf5fc5158d39e7e83ca2a779c4b4e9a2897fc
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: quad-core 64-bit haswell
OS X: 10.8.4-x86_64
// RACCommand α β === Kleisli RACSignal α β === α -> RACSignal β
// We can pullback along the kleisli arrow to change the input to a command.
// Likewise, we can pushout along the arrow to change the output to a command.
RACSignal *validationSignal = self.form.validationSignal.replayLast;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:nil action:nil];
doneButton.rac_command = [self.viewModel.doneCommand ys_pullback:^RACSignal *(id input) {
return [validationSignal take:1];
}];
@jonsterling
jonsterling / gist:7001562
Last active December 25, 2015 15:49
Rethinking commands as Kleisli arrows with a bit more stuff. This show the basics of how to start with Kleisli arrows (of signals) which are interesting and useful in their own right. I often need to compose monadic pipelines `a -> Signal a`, and it's nice to be able to reify these rather than thread everything through (very pointy) flatmaps. Ne…
typedef RACSignal *(^RACSignalKleisliBlock)(id input);
@interface RACSignalKleisli : NSObject
- (id)initWithSignalBlock:(RACSignalKleisliBlock)block;
- (instancetype)compose:(RACSignalKleisli *)kleisli;
- (RACSignal *)execute:(id)input;
@end
@implementation RACSignalKleisli {
RACSignalBlock _signalBlock;
RACCommand *example = [[RACCommand alloc] initWithSignalBlock:^(id input) {
return [RACSignal createWithBlock:^(id<RACSubscriber> subscriber){
[subscriber sendCompleted];
return nil;
}];
];
// Now, how will I know when each task has completed?
// I certainly cannot tell from `example.executionSignals.flatten`.
@jonsterling
jonsterling / empty.ml
Last active December 27, 2015 21:59
I think this suffices for the empty type in OCaml, but I'm not certain.
module type TYPE = sig
type t
end
module type EMPTY = functor (T : TYPE) -> sig
val apply : T.t
end
type empty = (module EMPTY)
// A nice little example of using transactional signal generators.
// Imagine a board of buttons with numbers on it, and a big red button with a picture of a bomb on it.
// When a button with a number is pressed, `increment` is invoked with that number. When the bomb
// button is pressed, then `reset` is invoked.
//
//This returns a signal of the running total made by incrementing by numbers and resetting by explosions.
RACDynamicSignalGenerator *increment = [[RACDynamicSignalGenerator alloc] initWithBlock:^RACSignal *(NSNumber *add) {
return [RACSignal return:^(NSNumber *count) {
return @(count.integerValue + add.integerValue);
}];
@jonsterling
jonsterling / proofs.sml
Last active January 2, 2016 04:48
Constructive proofs in SML's module language
(* It is not possible in Standard ML to construct an identity type (or any other
* indexed type), but that does not stop us from speculating. We can specify with
* a signature equality should mean, and then use a functor to say, "If there
* were a such thing as equality, then we could prove these things with it."
* Likewise, we can use the same trick to define the booleans and their
* induction principle at the type-level, and speculate what proofs we could
* make if we indeed had the booleans and their induction principle.
*
* Functions may be defined by asserting their inputs and outputs as
* propositional equalities in a signature; these "functions" do not compute,