Skip to content

Instantly share code, notes, and snippets.

View .gitignore
#########################
# .gitignore file for Xcode4 / OS X Source projects
#
# Version 2.0
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
# 2013 updates:
# - fixed the broken "save personal Schemes"
#
# NB: if you are storing "built" products, this WILL NOT WORK,
@Koshub
Koshub / gist:a39655478f7e8ffc8df1
Created Feb 21, 2015
Quoting selection for pyha.ru
View gist:a39655478f7e8ffc8df1
$('li.post > div > div > p > span > a.quote').сlick(function() {
function getSelection() {
var text = "", element = null;
if (typeof window.getSelection != "undefined") {
var sel = window.getSelection();
if (sel.rangeCount) {
var node = sel.getRangeAt(0).commonAncestorContainer;
element = node.nodeType == 1 ? node : node.parentNode;
text = sel.toString();
View NSTimer+Closure.swift
extension NSTimer {
/**
Creates and schedules a one-time `NSTimer` instance.
:param: delay The delay before execution.
:param: handler A closure to execute after `delay`.
:returns: The newly-created `NSTimer` instance.
*/
class func schedule(#delay: NSTimeInterval, handler: NSTimer! -> Void) -> NSTimer {
@Koshub
Koshub / KeyboardEventsHandler.swift
Created Feb 23, 2016
iOS keyboard notifications view controller extension
View KeyboardEventsHandler.swift
//
// KeyboardEventsHandler.swift
//
// Created by Konstantin Gerasimov on 2/23/16.
// License MIT
import UIKit
protocol KeyboardEventsHandler {
func startHandlingKeyboardEvents()
@Koshub
Koshub / UIView+LoadAndReuse.swift
Last active Feb 28, 2016
UIView extension to simplify load and reuse views
View UIView+LoadAndReuse.swift
// https://gist.github.com/Koshub/6fb12b8d2430e586b4c8
// Created by Konstantin Gerasimov on 11/25/15.
import UIKit
extension UIView {
class func loadFromNib<T: UIView>(view: T.Type) -> T? {
if let nib = NSBundle.mainBundle().loadNibNamed(className(), owner: nil, options: nil) {
for object in nib {
@Koshub
Koshub / States-v3.md
Created May 9, 2020 — forked from andymatuschak/States-v3.md
A composable pattern for pure state machines with effects (draft v3)
View States-v3.md

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,