Skip to content

Instantly share code, notes, and snippets.

@Bogidon
Bogidon / machine.js
Created October 19, 2021 20:47
Generated by XState Viz: https://xstate.js.org/viz
const TRANSITIONS = {
BACK: 'BACK',
CONTINUE: 'CONTINUE',
};
const STATES = {
ENTREE: 'ENTREE',
COMBO: 'COMBO',
DRINK: 'DRINK',
@Bogidon
Bogidon / machine.js
Last active July 9, 2021 21:03
Generated by XState Viz: https://xstate.js.org/viz
const TRANSITIONS = {
BACK: 'BACK',
CONTINUE: 'CONTINUE',
};
const STATES = {
INITIALIZE: 'INITIALIZE',
@Bogidon
Bogidon / machine.js
Created March 25, 2021 06:25
Generated by XState Viz: https://xstate.js.org/viz
/*************
Fixed
*************/
const STATES = Object.fromEntries(["animalKingdom", "dogOrCat", "petAge", "enrolledInPuppySchool", "recommendedProduct"].map(x => [x, x]))
const GUARDS = Object.fromEntries(["isMammal", "isFish", "isDog", "isCat", "petNameValid"].map(x => [x, x]))
const TRANSITIONS = Object.fromEntries(["continue", "error"].map(x => [x, x]))
/*************
@Bogidon
Bogidon / machine.js
Created March 25, 2021 06:23
Generated by XState Viz: https://xstate.js.org/viz
/*************
Fixed
*************/
const STATES = Object.fromEntries(["animalKingdom", "dogOrCat", "petAge", "enrolledInPuppySchool", "recommendedProduct"].map(x => [x, x]))
const GUARDS = Object.fromEntries(["isMammal", "isFish", "isDog", "isCat", "petNameValid"].map(x => [x, x]))
const TRANSITIONS = Object.fromEntries(["continue", "error"].map(x => [x, x]))
// FULLY SERIALIZED
@Bogidon
Bogidon / machine.js
Created March 18, 2021 22:06
Generated by XState Viz: https://xstate.js.org/viz
const State = {
cancelMigrationConfirmation: 'cancelMigrationConfirmation',
done: 'done',
duplicatePortal: 'duplicatePortal',
initial: 'initial',
migrationAccountsMismatch: 'migrationAccountsMismatch',
migrationDisclosure: 'migrationDisclosure',
plaidFlow: 'plaidFlow',
portalError: 'portalError',
selectInstitution: 'selectInstitution',
@Bogidon
Bogidon / ScaleAndFit.swift
Created March 31, 2017 19:36
Scale and fit an image in a size
extension UIImage {
/// Aspect fit an image from a size. (center)
///
/// The input size is the minimum size of the output image. The size of `self` is the
/// maximum size of the output image. Aspect ratio is maintained. Transparency is added to the
/// sides of the output image to keep the image centered.
///
/// - parameter in: The `CGSize` in which to scale and center `self`.
func scaleAndFit(in inputSize: CGSize) -> UIImage? {
// Scale rect to fit image, if image is larger.
@Bogidon
Bogidon / GrowingTextView.swift
Last active February 15, 2021 20:06
A UITextView subclass that grows with its text but allows scrolling according to AutoLayout constraints. Updates intrinsicContentSize. For an animatable version see https://gist.github.com/Bogidon/632e265b784ef978d5d8c0b86858c2ee
//
// GrowingTextView.swift
// https://gist.github.com/Bogidon/cc0c9ae6f041413c39fb0ff146ad1b18
//
// Created by Bogdan Vitoc on 02/22/2017.
// Distributed under the MIT License: https://gist.github.com/Bogidon/cc0c9ae6f041413c39fb0ff146ad1b18#file-license
//
import UIKit
@Bogidon
Bogidon / AnimatedGrowingTextView.swift
Last active January 11, 2023 07:04
A short and understandable UITextView subclass that grows with its text. Animatable. Updates intrinsicContentSize. If you don't need animations check out https://gist.github.com/Bogidon/cc0c9ae6f041413c39fb0ff146ad1b18
//
// AnimatedGrowingTextView.swift
// https://gist.github.com/Bogidon/632e265b784ef978d5d8c0b86858c2ee
//
// Created by Bogdan Vitoc on 02/15/2017.
// Distributed under the MIT License: https://gist.github.com/Bogidon/632e265b784ef978d5d8c0b86858c2ee#file-license
//
import UIKit
@Bogidon
Bogidon / BrowserSpec.js
Last active February 8, 2017 11:12
The default Mocha "spec" reporter, but with colors formatted for browser consoles. Original reporter: https://github.com/mochajs/mocha/blob/master/lib/reporters/spec.js
'use strict'
let mocha = require('mocha')
let Base = mocha.reporters.Base
exports = module.exports = BrowserSpec
// This class is a ported version of Mocha's default "spec" reporter to format color output for the browser.
// https://github.com/mochajs/mocha/blob/master/lib/reporters/spec.js
function BrowserSpec (runner) {
mocha.reporters.Base.call(this, runner)
@Bogidon
Bogidon / Date+TimeZone.swift
Created February 7, 2017 07:09
Get the current time in a timezone.
import Foundation
extension Date {
/**
Returns the current time in a timezone.
- Note:
`Date` is [time zone agnostic.](https://developer.apple.com/reference/foundation/date#overview)
*/
static func `for`(zone: TimeZone) -> Date {