Skip to content

Instantly share code, notes, and snippets.

Avatar

Kevin Lundberg klundberg

View GitHub Profile
View machine.js
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@klundberg
klundberg / optional-collection.swift
Last active Feb 24, 2018
Potential Swift 4.1 implementation of conditional conformace to Collection for Optional<Collection>
View optional-collection.swift
public struct OptionalIndex<InnerIndex: Comparable> {
let inner: InnerIndex?
init(_ base: InnerIndex) {
inner = base
}
init() {
inner = nil
}
@klundberg
klundberg / optional-conditional-collection.swift
Created Feb 21, 2018
Conditional conformance in swift 4.1 for optional for some common protocols
View optional-conditional-collection.swift
extension Optional: Collection where Wrapped: Collection {
public typealias Element = Wrapped.Element
public typealias Index = Wrapped.Index
public func index(after i: Wrapped.Index) -> Wrapped.Index {
switch self {
case let value?:
return value.index(after: i)
case nil:
fatalError() // TODO: ???
View genesis_public_key
041f94dcd6f7e66679da2ead9c76e5aaa24f0d17ec559ab354806133340f877095226f2d4bc36a07c4cf1f1e9269bb3bb55970234a0af292c869446ce0f6e8e886;nsirlconnection
@klundberg
klundberg / json-codable.swift
Last active Jul 21, 2020
encode/decode arbitrary JSON data with swift 4's Codable
View json-codable.swift
enum JSONValue: Codable, Equatable {
struct JSONValueDecodingError: Error {
let message: String
}
case boolean(Bool)
case number(Double)
case string(String)
case array([JSONValue?])
case object([String: JSONValue?])
@klundberg
klundberg / SnakeCaseCodingKeys.stencil
Created Sep 16, 2017
Sourcery template that adds CodingKeys overrides for Codable types to convert camelCase property names to snake_case in the serialized format.
View SnakeCaseCodingKeys.stencil
{% for type in types.based.Codable|!enum %}
public extension {{ type.name }} {
enum CodingKeys: String, CodingKey {
{% for variable in type.variables|instance %}
{% if variable|annotated:"keyOverride" %}
case {{ variable.name }} = "{{ variable.annotations.keyOverride }}"
{% else %}
case {{ variable.name }} = "{{ variable.name|camelToSnakeCase }}"
{% endif %}
{% endfor %}
@klundberg
klundberg / build.log
Created Jun 13, 2017
FutureKit build errors with Xcode 9
View build.log
/usr/bin/xcrun xcodebuild -workspace /Users/klundberg/workspaces/wayfair-ios/Carthage/Checkouts/FutureKit/FutureKit.xcworkspace -scheme FutureKit\ iOS -configuration Release -derivedDataPath /Users/klundberg/Library/Caches/org.carthage.CarthageKit/DerivedData/FutureKit/3.0.0 -sdk iphoneos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean buildUser defaults from command line:
IDEDerivedDataPathOverride = /Users/klundberg/Library/Caches/org.carthage.CarthageKit/DerivedData/FutureKit/3.0.0
Build settings from command line:
BITCODE_GENERATION_MODE = bitcode
CARTHAGE = YES
CODE_SIGN_IDENTITY =
CODE_SIGNING_REQUIRED = NO
ONLY_ACTIVE_ARCH = NO
SDKROOT = iphoneos11.0
@klundberg
klundberg / copyonwrite.swift
Last active Apr 1, 2017
Encapsulating copy-on-write behavior in a reusable way.
View copyonwrite.swift
// Written using Swift 3.0.x
fileprivate final class Box<T> {
let unbox: T
init(_ value: T) {
unbox = value
}
}
public struct CopyOnWrite<T: AnyObject> {
View keybase.md

Keybase proof

I hereby claim:

  • I am klundberg on github.
  • I am kevlario (https://keybase.io/kevlario) on keybase.
  • I have a public key ASAXKidIohQbWt66-UXKy-Ek8vejycrMu6F4xoG3oojvTQo

To claim this, I am signing this object:

View regex.swift
let regex = try NSRegularExpression(pattern: mypattern, options: [])
let str = "some string to match"
if let result = regex.firstMatchInString(str, options: [], range: NSMakeRange(0, str.characters.count)) {
print((str as NSString).substringWithRange((result?.rangeAtIndex(1))!))
}
You can’t perform that action at this time.