Skip to content

Instantly share code, notes, and snippets.

View reckenrode's full-sized avatar

Randy Eckenrode reckenrode

View GitHub Profile

Keybase proof

I hereby claim:

  • I am reckenrode on github.
  • I am reckenrode (https://keybase.io/reckenrode) on keybase.
  • I have a public key ASBPJ4FGo-Gwg6iUItotbZDQnC_fPv4DSwu9Uk_9CVyVzAo

To claim this, I am signing this object:

@reckenrode
reckenrode / json.swift
Created June 23, 2017 14:25
Decoding arbitrary JSON with the new Decoder in Swift 4
enum JSON: Decodable {
case bool(Bool)
case double(Double)
case string(String)
indirect case array([JSON])
indirect case dictionary([String: JSON])
init(from decoder: Decoder) throws {
if let container = try? decoder.container(keyedBy: JSONCodingKeys.self) {
self = JSON(from: container)
@reckenrode
reckenrode / codeableEnum.swift
Created June 23, 2017 19:49
Implement Codable on an enum
struct User: Codable {
var name: String
var email: String
var id: String
var metadata: [String: MetadataType]
enum CodingKeys: String, CodingKey {
case name, email, id, metadata
}
}
@reckenrode
reckenrode / routing.swift
Created April 7, 2018 23:14
Router databinding configuration for my website
let router = try container.make(Router.self)
let blog = try container.make(BlogController.self)
router.get("blog", use: Template(path: "Blog/listing")
.bind(blog.posts, to: "posts")
.bind(blog.isOldestFirst, to: "oldest-first").fn())
router.get("blog", ":author", use: Template(path: "Blog/author-post").fn())
router.post("blog", ":save", use: (blog.save >>> { $0.redirect(to: "/blog") }))
router.get("blog", String.parameter, use: Template(path: "Blog/view-post")
.bindObject(blog.post).fn())
@reckenrode
reckenrode / Microsoft.PowerShell_profile.ps1
Last active June 24, 2018 20:07
PowerShell config file for macOS, which correctly updates the Terminal’s cwd and also understands /etc/paths.d.
$env:PATH = {
# Powershell doesn’t understand paths.d, nor does it put sbin in the path.
# Fix-up the paths to have the same ones as bash.
$pathPrefixes = "/usr/local/bin"
$pathSuffixes = "/usr/sbin", "/sbin", `
[System.String]::Join(":", (Get-ChildItem -Path "/etc/paths.d" | Get-Content))
"$([System.String]::Join(':', $pathPrefixes)):$($env:PATH):$([System.String]::Join(':', $pathSuffixes))"
}.Invoke()
function Format-Path {
@reckenrode
reckenrode / abilityGen.swift
Last active August 25, 2018 22:07
5e ability score generation
// Requires Swift 4.2. Compile with `swiftc -O abilityGen.swift`. Run with ./abilityGen <type> > <output.csv>
import Foundation
let costs = [
8: 0,
9: 1,
10: 2,
11: 3,
12: 4,
13: 5,
use rand::{Rng, thread_rng};
use std::{
collections::HashMap,
io::Write,
thread
};
fn encounters_per_week<R: Rng>(rng: &mut R) -> u32 {
let mut count = 0;
for _ in 1..=(7*6) {
@reckenrode
reckenrode / sieve.rs
Created April 28, 2019 19:08
Rust Sieve of Eratosthenes
use num::Unsigned;
use structopt::StructOpt;
#[derive(Debug)]
enum NumberType {
Unit(usize), Prime(usize), Composite(usize)
}
impl NumberType {
[package]
name = "ability-scores"
version = "0.1.0"
authors = ["Randy Eckenrode <randy@largeandhighquality.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.7"
@reckenrode
reckenrode / reverse.fs
Created August 3, 2019 19:10
Unicode-aware string reverse in F#
open System.Text
open System
open ICU4N.Text
let reverse (str: string) =
if str.Length <= 0 then
str
else
let span = str.AsSpan ()
let breaks = seq {