Skip to content

Instantly share code, notes, and snippets.

View jspahrsummers's full-sized avatar

Justin Spahr-Summers jspahrsummers

View GitHub Profile
@joshaber
joshaber / gist:5226626
Last active December 15, 2015 07:49
ReactivePersistence?
// The basics
[[self.connection fetch:@"the-answer"] subscribeNext:^(NSNumber *x) {
NSLog(@"The answer is %@", x);
}];
[[self.connection writeObject:@42 forKey:@"the-answer"] subscribeCompleted:^{
NSLog(@"Wrote it.");
}];
// Signal for changes to the object at a key
@indragiek
indragiek / gist:5297435
Last active March 5, 2023 21:55
Draft of a ReactiveCocoa based interface for CoreData
//
// FGOManagedObjectContextStack.h
//
// Created by Indragie Karunaratne on 2012-12-23.
//
#import <Foundation/Foundation.h>
typedef void (^FGOConfigurationBlock)(id);
-- implements an option type as a tagged union
local option = {}
local mt = { __index = option }
local function isoption(t)
return getmetatable(t) == mt
end
function option.some(a)
@ashfurrow
ashfurrow / gist:5658708
Last active December 17, 2015 19:09
ReactiveCocoa Find Max Value in Array
CGFloat max = [[numbersArray.rac_sequence foldLeftWithStart:@(FLT_MIN) combine:^id(id accumulator, id value) {
if (value == [NSNull null]) return accumulator;
if ([accumulator floatValue] < [value floatValue]) return value;
else return accumulator;
}] floatValue];
// "Semantic issue - Unsequences modification and access to '_cmd'"
// Expanded from macro 'NSParameterAssert'
// Expanded from macro 'NSAssert'
// Expanded from macro 'self'
@implementation _ModelClass
+ (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ {
NSParameterAssert(moc_);
return [NSEntityDescription insertNewObjectForEntityForName:@"Model" inManagedObjectContext:moc_];
// Only let input Observable fire every 'n' seconds at most
// but unlike Throttle, items fire immediately when they aren't
// rate-limited.
public IObservable<T> RateLimit<T>(this IObservable<T> This, TimeSpan interval, IScheduler scheduler)
{
var slot = default(IObservable<Unit>);
var input = This.Publish().RefCount();
return input.Window(input, _ => {
if (slot != null) return slot;
@mchakravarty
mchakravarty / Exp.hs
Created August 25, 2013 05:20
Functorial approach to defining expressions.
data PreExp exp = Val Int
| Add exp exp
newtype Exp = Exp (PreExp Exp) -- this is just a normal expression
data AttrExp = AttrExp Attr (PreExp AttrExp) -- an attributed expression
data Attr = ...
@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`.
@lukehefson
lukehefson / uninstall-GHfM.sh
Created November 27, 2013 13:48
Completely uninstall GitHub for Mac
#!/bin/bash
function remove_dir () {
rm -rf "$1_"
if [ -d "$1" ]
then
mv "$1" "$1_"
fi
}