Skip to content

Instantly share code, notes, and snippets.

View voidrender's full-sized avatar
👨‍💻
Idle hands build nothing

Isaac Overacker voidrender

👨‍💻
Idle hands build nothing
View GitHub Profile
@hyb175
hyb175 / realmMock.js
Last active June 13, 2024 02:45
Realm Mock for jest
// https://github.com/realm/realm-js/issues/370#issuecomment-270849466
export default class Realm {
constructor(params) {
this.schema = {};
this.callbackList = [];
this.data = {};
this.schemaCallbackList = {};
params.schema.forEach((schema) => {
this.data[schema.name] = {};
});
@andymatuschak
andymatuschak / States-v3.md
Last active December 17, 2024 17:27
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@skunkworks
skunkworks / NPClientAPI.h
Last active August 29, 2015 14:05
Using AFNetworking 2.0 and Mantle for some hot RESTful JSON action
@interface NPClientAPI : AFHTTPSessionManager
- (instancetype)initWithBaseURL:(NSString *)baseURL;
/**
Singleton object.
*/
+ (NPClientAPI *)sharedAPI;
/**
@ijoshsmith
ijoshsmith / PreferredViewSizeLookup.m
Created September 26, 2012 04:17
Inspect a View's NIB to determine its preferred/natural size
// This code assumes that ARC is enabled.
// Returns the size of this View in its NIB.
+ (CGSize)preferredSize
{
static NSValue *sizeBox = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// Assumption: The XIB file name matches this UIView subclass name.
UINib *nib = [UINib nibWithNibName:NSStringFromClass(self) bundle:nil];
@brentertz
brentertz / rvm2rbenv.txt
Created November 21, 2011 23:00
Switch from RVM to RBENV
## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################