(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
import Cocoa | |
/// A wrapper around any type to make Result compile | |
class Box<T> { | |
let unbox: T | |
init(_ value: T) { | |
self.unbox = value | |
} | |
} |
// | |
// main.swift | |
// pggrep - updated 12/4/15 | |
// Created by Erica Sadun on 6/17/15. | |
// Copyright © 2015 Erica Sadun. All rights reserved. | |
// | |
import Foundation | |
extension String { |
import Cocoa | |
// Note: use of enumeration var in generic is instadeath | |
// Note: use of static var in generic is not yet supported | |
public protocol EnumConvertible: Hashable { | |
init?(hashValue hash: Int) | |
static func countMembers() -> Int | |
static func members() -> [Self] | |
} |
#! /usr/bin/env python | |
# coding: utf-8 | |
''' | |
auto switch keyboard between different applications | |
if you want to change the app list, modify the var 'ignore_list' | |
''' | |
from AppKit import NSWorkspace, NSWorkspaceDidActivateApplicationNotification, NSWorkspaceApplicationKey |
import Foundation | |
// Extend String to support regex searching by conforming | |
// to CustomStringConvertible | |
extension String: CustomStringConvertible { | |
public var description: String {return self} | |
} | |
// Regex support for keys | |
public extension Dictionary where Key: CustomStringConvertible { |
import UIKit | |
// Swift rewrite challenge | |
// Starting point: https://gist.github.com/jkereako/200342b66b5416fd715a#file-scale-and-crop-image-swift | |
func scaleAndCropImage( | |
image: UIImage, | |
toSize size: CGSize, | |
fitImage: Bool = true | |
) -> UIImage { |
import Cocoa | |
// Missing isWord | |
func isWord(string: String) -> Bool { | |
if let _ = Int(string) { return false } | |
let range = NSSpellChecker.shared().checkSpelling(of: string, startingAt: 0) | |
return range.location == NSNotFound | |
} | |
/*: |
# The trick is to link the DeviceSupport folder from the beta to the stable version. | |
# sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :) | |
# Support iOS 15 devices (Xcode 13.0) with Xcode 12.5: | |
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/15.0 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport | |
# Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions | |
# (A similar approach works for older versions too, just change the version number after DeviceSupport) |
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,