Skip to content

Instantly share code, notes, and snippets.

View shakemno's full-sized avatar

Manolis Pahlke shakemno

View GitHub Profile
@ben-ole
ben-ole / Paging.coffee
Last active August 26, 2016 14:09
Simple Navigation Component for FramerJS
# simple navigation componenent like on iOS
# put at the top of your file
class Paging
pages = Array()
constructor: (@bg_layer) ->
# push a new page on top
import UIKit
import GenericViewKit
public class StateView: GenericView {
public enum State {
case Loading
case Loaded
case Error
}
@xem
xem / readme.md
Last active August 20, 2026 06:07
Maths & trigonometry cheat sheet for 2D & 3D games

Conventions

  • A = [xA, yA] is a point on the 2D plane. Same for B, C, ...
  • lengths are in any unit (ex: pixels)
  • code snippets are in JavaScript

Degrees to radians

angleRad = angleDeg * Math.PI / 180;

@andymatuschak
andymatuschak / States-v3.md
Last active May 17, 2026 19:29
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,

@khanlou
khanlou / StateMachine.swift
Created October 21, 2016 00:14
A state machine where invalid transitions can't compile
protocol State {}
struct Transition<From: State, To: State> {
let transition: () -> To
}
struct Machine<CurrentState: State> {
var state: CurrentState
//:
//: UIView Animation Syntax Sugar
//:
//: Created by Andyy Hope on 18/08/2016.
//: Twitter: @andyyhope
//: Medium: Andyy Hope, https://medium.com/@AndyyHope
import UIKit
extension UIView {
@simme
simme / debounce-throttle.swift
Created December 20, 2016 10:04
Swift 3 debounce & throttle
//
// debounce-throttle.swift
//
// Created by Simon Ljungberg on 19/12/16.
// License: MIT
//
import Foundation
extension TimeInterval {
@Ankit-Aggarwal
Ankit-Aggarwal / UIViewController+Helpers
Last active January 11, 2020 03:57
UIViewController Extension to handle keyboard updates easily
import Foundation
import UIKit
import ReactiveSwift
import Result
extension UIViewController {
typealias KeyboardStatusInfo = (height: CGFloat , duration: TimeInterval, animationOptions: UIViewAnimationOptions)
var keyboardUpdatesSignal: Signal<KeyboardStatusInfo, NoError> {
@norsez
norsez / MovieWriter.swift
Created May 11, 2017 04:13 — forked from isthisjoe/MovieWriter.swift
Swift 3 | macOs | Write NSImage(s) to a movie file. Modified from http://stackoverflow.com/a/36297656/1275125
import AppKit
import AVFoundation
class MovieWriter: NSObject {
func writeImagesAsMovie(_ allImages: [NSImage], videoPath: String, videoSize: CGSize, videoFPS: Int32) {
// Create AVAssetWriter to write video
guard let assetWriter = createAssetWriter(videoPath, size: videoSize) else {
print("Error converting images to video: AVAssetWriter not created")
return
}