Skip to content

Instantly share code, notes, and snippets.

@RoyalIcing
RoyalIcing / actor-protocol.swift
Last active March 31, 2021 00:38
Defining Actors in Swift with Protocols
protocol Actor : AnyObject, Sendable {
associatedtype State
isolated var state: State
}
struct BankAccountState {
var balance: Double
mutating func deposit(amount: Double) {
@RoyalIcing
RoyalIcing / soonerorlater.test.ts
Last active February 20, 2021 04:49
Parse natural language date span
import { parse } from "./index";
test("parse()", () => {
test.each([
['Monday', { weekdays: new Set(['monday']) }],
['Wednesday', { weekdays: new Set(['wednesday']) }],
[' Wednesday ', { weekdays: new Set(['wednesday']) }],
['Wednesday and Saturday', { weekdays: new Set(['wednesday', 'saturday']) }],
['Wednesday or Saturday', { weekdays: new Set(['wednesday', 'saturday']) }],
['Wednesday, Saturday', { weekdays: new Set(['wednesday', 'saturday']) }],
@RoyalIcing
RoyalIcing / machine.js
Created January 6, 2021 07:15
Generated by XState Viz: https://xstate.js.org/viz
const pedestrianStates = {
initial: 'walk',
states: {
walk: {
on: {
PED_COUNTDOWN: 'wait'
}
},
wait: {
on: {
@RoyalIcing
RoyalIcing / keybase.md
Created November 7, 2018 13:25
keybase.md

Keybase proof

I hereby claim:

  • I am burntcaramel on github.
  • I am burntcaramel (https://keybase.io/burntcaramel) on keybase.
  • I have a public key ASArnj22CZ7v-9tbcz-52hippT2ZfvGy4dQ3ZoSelHe3lwo

To claim this, I am signing this object:

@RoyalIcing
RoyalIcing / 1.ts
Created June 29, 2018 02:02
React state management ideas
interface State {
counter: number
}
const counterModel = {
initial(): State {
return {
counter: 0
};
},
//: Playground - noun: a place where people can play
import Foundation
struct ExampleStruct : Codable {
var title: String
var something: Int
public func encode(to encoder: Encoder) throws {
@RoyalIcing
RoyalIcing / Dockerfile
Last active April 2, 2020 17:06
Rails 5.1 Dockerfile
FROM ruby:2.4-alpine
ENV PATH /root/.yarn/bin:$PATH
RUN apk update && apk upgrade && \
apk add --no-cache bash git openssh build-base nodejs tzdata
RUN apk update \
&& apk add curl bash binutils tar gnupg \
&& rm -rf /var/cache/apk/* \
@RoyalIcing
RoyalIcing / 1-example.swift
Created May 27, 2016 13:36
Swift Dynamic Properties
public struct Person {
public var firstName: String
public var middleName: String?
public var lastName: String
public var ageInYears: Int
public var fullName: String {
return [firstName, middleName, lastName].flatMap{ $0 }.joinWithSeparator(" ")
}
}
@RoyalIcing
RoyalIcing / responder-chain.swift
Last active February 13, 2018 16:05
Responder chain in Swift using enums
//: Responder chain in Swift using enums
protocol CommandProtocol {}
protocol Responder: class {
var nextResponder: Responder? { get }
func performerForCommand
<Command : CommandProtocol>
(command: Command) -> (() -> ())?
@RoyalIcing
RoyalIcing / Mutation.swift
Last active April 22, 2016 08:09
Mutation methods as a type, allowing easy copies to be made
struct Person {
var firstName, lastName: String
mutating func makeScottishClan() {
lastName = "mc\(lastName)"
}
}
// Person.Mutation gets automatically created (like an enum)
// .firstName(String)