Skip to content

Instantly share code, notes, and snippets.

View daltonclaybrook's full-sized avatar

Dalton Claybrook daltonclaybrook

View GitHub Profile
#[macro_use]
extern crate lazy_static;
use regex::{Captures, Regex};
use std::fs;
use std::ops::Range;
use std::str::FromStr;
#[derive(Debug)]
enum AdventError {
Unknown,
import RxSwift
/// This type is similar to `BehaviorRelay`, but it allows for mutating an element in-place
/// rather than assigning a new one.
///
/// This is useful for large copy-on-write containers. For example, it's less expensive to append
/// an element to an `Array` with 1M entries than it is to make a new `Array` by concatenating it with
/// a second `Array` with one element.
public final class MutableRelay<Element>: ObservableType {
public private(set) var value: Element
/// Types that implement this trait provide the rules
/// for replacing objects of the same type.
pub trait Replaceable {
type Key: Eq;
fn unique_key(&self) -> Self::Key;
fn should_replace(&self, other: &Self) -> bool;
}
/// Trait implemented for collections that can be
/// filtered using replacement rules
private func fibonacci(_ n: Int) -> Int {
guard n != 0, n != 1 else { return n }
return fibonacci(n - 1) + fibonacci(n - 2)
}
pico-8 cartridge // http://www.pico-8.com
version 18
__lua__
-- this is called automatically
-- one time when the game starts
-- but we'll call it again later
-- to start the game over
function _init()
-- later, when the game is over
-- we'll call this functiom
struct Grid<T> {
let width: Int
let height: Int
private var gridData: [T]
init(width: Int, height: Int, initialFill: T) {
self.width = width
self.height = height
gridData = [T](repeating: initialFill, count: width * height)
include "hardware.inc" ; https://github.com/gbdev/hardware.inc
; Constants
LCD_ON_BIT EQU 7
LCD_BG_TILE_DATA_BIT EQU 4
RUBY_TOP_VRAM EQU _VRAM
; Define a 2-byte RGB color
;
; /1 = R, /2 = G, /3 = B
import Combine
import SwiftUI
extension Publisher {
func withPrevious(_ initial: Output) -> AnyPublisher<(Output, Output), Failure> {
scan((initial, initial)) { previousTuple, currentValue in
(previousTuple.1, currentValue)
}.eraseToAnyPublisher()
}
}
@daltonclaybrook
daltonclaybrook / LazyView.swift
Created July 21, 2019 20:20
A view which lazily initializes its content view.
import SwiftUI
/// A view which lazily initializes its content view.
struct LazyView<Content: View>: View {
private let viewBlock: () -> Content
init(_ content: @escaping @autoclosure () -> Content) {
viewBlock = content
}
@daltonclaybrook
daltonclaybrook / NextValue.swift
Last active July 19, 2019 03:16
A Swift property wrapper which conforms to Publisher and emits before the wrappedValue has been set
import Combine
@propertyWrapper
struct NextValue<Output> {
typealias Failure = Never
typealias Publisher = AnyPublisher<Output, Never>
var wrappedValue: Output {
willSet {
subject.send(newValue)