Skip to content

Instantly share code, notes, and snippets.

View marcinmatczuk's full-sized avatar

Marcin Matczuk marcinmatczuk

  • Wrocław, Poland
View GitHub Profile
@marcinmatczuk
marcinmatczuk / States-v3.md
Created December 1, 2017 14:22 — forked from andymatuschak/States-v3.md
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,

@marcinmatczuk
marcinmatczuk / CompilerCheckedKeyPaths.h
Last active September 4, 2015 13:24 — forked from quinntaylor/CompilerCheckedKeyPaths.h
Code for getting compiler check on key paths, more accurate than using NSStringFromSelector(@selector(foo)).
// See http://nshipster.com/key-value-observing/
// Put this code a common utilities header, and use it to have the compiler help check correctness of key paths.
// Uses macro stringification to create an Obj-C string literal, plus validation code that the compiler optimizes out.
@interface NSObject (KeyPathFakeCategoryForCompilerWarnings)
+ (instancetype)__fake_method_for_compiler_warnings__;
- (instancetype)__fake_method_for_compiler_warnings__;
@end
/*! Returns a string for the given keypath, but causes a compiler warning if the keypath is not defined on \c self.
@marcinmatczuk
marcinmatczuk / osx-for-hackers.sh
Last active September 3, 2015 09:52 — forked from brandonb927/osx-for-hackers.sh
OSX for Hackers: Yosemite Edition. This script tries not to be *too* opinionated and any major changes to your system require a prompt. You've been warned. Also, please don't email me about this script, my poor inbox...
#!/bin/sh
# Alot of these configs have been taken from the various places
# on the web, most from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
@marcinmatczuk
marcinmatczuk / SthToTest
Created December 12, 2013 13:58
A potential replacement for NSHashTable for iOS 5 - need to test it and see how it works with ARC.
/* Source: http://stackoverflow.com/questions/4692161/non-retaining-array-for-delegates/4692229#4692229 */
@implementation NSMutableArray (WeakReferences)
+ (id)mutableArrayUsingWeakReferences
{
return [self mutableArrayUsingWeakReferencesWithCapacity:0];
}
+ (id)mutableArrayUsingWeakReferencesWithCapacity:(NSUInteger)capacity {
@marcinmatczuk
marcinmatczuk / hack.sh
Created April 4, 2012 20:07 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@marcinmatczuk
marcinmatczuk / hack.sh
Created April 1, 2012 11:10 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
#!/usr/bin/env ruby
# Xcode auto-versioning script for Subversion by Axel Andersson
# Updated for git by Marcus S. Zarra and Matt Long
# Converted to ruby by Abizer Nasir
# Appends the git sha to the version number set in Xcode.
# see http://www.stompy.org/2008/08/14/xcode-and-git-another-build-script/ for more details
# These are the common places where git is installed.
# Change this if your path isn't here