Skip to content

Instantly share code, notes, and snippets.

View jspahrsummers's full-sized avatar

Justin Spahr-Summers jspahrsummers

View GitHub Profile
@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 = ...
// 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;
// "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_];
@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];
-- 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)
@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);
@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
@technoweenie
technoweenie / gist:5101109
Last active January 7, 2016 16:56
API Existential Crisis

API Existential Crisis

One bit of feedback we've heard from some heavy users of the API is that they want to access user and repository data by ID, and not name.

GET /users/technoweenie
GET /repos/technoweenie/faraday

If you're tracking user or repository data, using a URL with a unique and unchanging ID means the application won't break if the user or repository is

{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
module TestInlineObjC (objc_initialise, dumpURL) where
import Language.C.Quote.ObjC
import InlineObjC
objc_import ["<Foundation/Foundation.h>"]
public DashboardHostTileView()
{
InitializeComponent();
this.OneWayBind(ViewModel, x => x.Model.Title, x => x.Title.Text);
this.OneWayBind(ViewModel, x => x.UserAndOrgTiles, x => x.UserAndOrgTiles.ItemsSource);
this.BindCommand(ViewModel, x => x.ShowLoginCommand, x => x.ShowLoginCommand);
// Bind SelectedItem of ListBox to the ViewModel
this.WhenAny(x => x.UserAndOrgTiles.SelectedItem, x => x.Value)