The following are appendices from Optics By Example, a comprehensive guide to optics from beginner to advanced! If you like the content below, there's plenty more where that came from; pick up the book!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension Decodable where Self: Encodable { | |
/// Creates a new instance and changes the value for the provided key. | |
/// | |
/// - Parameters: | |
/// - key: The key path to the property that you want to modify. | |
/// Use period to separate levels and [] for indexes. | |
/// Examples: "id", "name.firstName", "children[2].name.firstName" | |
/// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension RangeReplaceableCollection { | |
static func += (collection: inout Self, element: Element) { | |
collection.append(element) | |
} | |
static func += (collection: inout Self, element: Element?) { | |
if let element = element { | |
collection.append(element) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env xcrun -sdk macosx swift | |
// Displays UI in an NSWindow which can interact with the commandline | |
// Usage: `echo "Bar" | ./swift-ui-commandline-tool.swift` | |
import Foundation | |
import SwiftUI | |
extension CommandLine { | |
static let input: String = { AnyIterator { readLine() }.joined() }() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env stack | |
-- stack --resolver lts-18.8 script | |
{-# LANGUAGE OverloadedStrings #-} | |
{- | |
This is a handy illustration of converting between five of the commonly-used | |
string types in Haskell (String, ByteString, lazy ByteString, Text and lazy | |
Text). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CLEAR='\033[0m' | |
RED='\033[0;31m' | |
function usage() { | |
if [ -n "$1" ]; then | |
echo -e "${RED}👉 $1${CLEAR}\n"; | |
fi | |
echo "Usage: $0 [-n number-of-people] [-s section-id] [-c cache-file]" |
I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6
apt-get update && apt-get install gdb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <mach-o/dyld.h> | |
#include <mach-o/nlist.h> | |
#include <mach-o/dyld_images.h> | |
#include <mach/mach_vm.h> | |
/* Dyld is the OSX Dynamic Linker | |
* /usr/include//mach-o/loader.h |
NewerOlder