Skip to content

Instantly share code, notes, and snippets.

Avatar

Patrick Smith BurntCaramel

View GitHub Profile
View 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:

@BurntCaramel
BurntCaramel / 1.ts
Created Jun 29, 2018
React state management ideas
View 1.ts
interface State {
counter: number
}
const counterModel = {
initial(): State {
return {
counter: 0
};
},
View CodableDefaultHashable.swift
//: 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 {
@BurntCaramel
BurntCaramel / Dockerfile
Last active Apr 2, 2020
Rails 5.1 Dockerfile
View 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/* \
@BurntCaramel
BurntCaramel / 1-example.swift
Created May 27, 2016
Swift Dynamic Properties
View 1-example.swift
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(" ")
}
}
@BurntCaramel
BurntCaramel / responder-chain.swift
Last active Feb 13, 2018
Responder chain in Swift using enums
View responder-chain.swift
//: Responder chain in Swift using enums
protocol CommandProtocol {}
protocol Responder: class {
var nextResponder: Responder? { get }
func performerForCommand
<Command : CommandProtocol>
(command: Command) -> (() -> ())?
@BurntCaramel
BurntCaramel / Mutation.swift
Last active Apr 22, 2016
Mutation methods as a type, allowing easy copies to be made
View Mutation.swift
struct Person {
var firstName, lastName: String
mutating func makeScottishClan() {
lastName = "mc\(lastName)"
}
}
// Person.Mutation gets automatically created (like an enum)
// .firstName(String)
View money-currency-types.swift
//: Types for currency conversion
// https://www.natashatherobot.com/swift-money-phantom-types/
import Foundation
struct Money {
enum Currency {
case GBP, EUR, USD
}
View switch-dictionary.swift
enum Fruit {
case apple, pear, orange, plum
}
extension Fruit {
var cents: Int {
return switch self [
.apple: 70,
.pear: 85,
.orange: 40,
View 1-StageProtocol.swift
import Foundation
protocol StageProtocol {
func perform() throws -> Self?
var queue: dispatch_queue_t { get }
func run(completion: (() throws -> Self) -> ())
}
You can’t perform that action at this time.