Skip to content

Instantly share code, notes, and snippets.

View asmallteapot's full-sized avatar
😴
😴

Ellen Teapot asmallteapot

😴
😴
View GitHub Profile
@asmallteapot
asmallteapot / Contents.swift
Created October 11, 2019 22:56
Playground demonstrating anchor-based layout constraints
import PlaygroundSupport
import UIKit
final class LabelViewController: UIViewController {
var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemBackground
@asmallteapot
asmallteapot / traincalculator2.py
Created August 17, 2019 23:06
modified version of @alon_levy’s train performance calculator
def integratel(f,a,b,n):
y = 0
for i in range(0,n):
y = y + f(a + (b-a)*i/n)
return y*(b-a)/n
def acceleration_time_fn(k,a,b,c,m):
return lambda x : max(x/(k - a*x - b*x**2 - c*x**3), 1/m)
def deceleration_time_fn(k,a,b,c,m):
@asmallteapot
asmallteapot / arduino-cli-Model01.md
Created June 7, 2019 01:06
Updating your keyboardio Model 01's firmware with arduino-cli

Updating your keyboardio Model 01's firmware with arduino-cli

0. Download the Model 01 firmware:

$ git clone https://github.com/keyboardio/Model01-Firmware.git
$ cd Model01-Firmware

1. Download and install arduino-cli:

@asmallteapot
asmallteapot / NSCoder+CodingKeys.swift
Last active April 26, 2018 03:55
NSCoder extension for working with CodingKeys
import Foundation
import QuartzCore
extension NSCoder {
public func decodeIfPresent<T>(_ valueType: T.Type, forKey key: CodingKey) -> T? {
guard self.containsValue(forKey: key.stringValue) else { return nil }
return self.decodeObject(forKey: key.stringValue) as? T
}
public func decodeCGRectIfPresent(forKey key: CodingKey) -> CGRect? {
@asmallteapot
asmallteapot / xcode-unfuck-deriveddata.sh
Created March 27, 2018 18:29
Shell script for removing Xcode derived data
# remove Xcode build cache
function xcode-unfuck-deriveddata() {
XCODE_DERIVED_DATA_DIR=`defaults read com.apple.dt.xcode.IDECustomDerivedDataLocation 2>&1 >/dev/null`
if [[ -e $XCODE_DERIVED_DIR ]]; then;
XCODE_DERIVED_DATA_DIR=~/Library/Developer/Xcode/DerivedData
fi
rm -rf $XCODE_DERIVED_DATA_DIR
}
const sampleInputs = [
"OAuth Token",
"Hello-World!",
];
String.prototype.capitalized = function() {
const firstCharacter = this.charAt(0).toUpperCase();
const remainder = this.substring(1);
return firstCharacter + remainder;
};
@asmallteapot
asmallteapot / NameFixer.swift
Last active December 31, 2017 04:43
Fix arbitrary input strings into camelCasedWords [Swift 4]
import Foundation
let sampleInputs = [
"OAuth Token",
"Hello-World!",
]
extension String {
func capitalized() -> String {
guard let firstCharacter = self.characters.first else { return "" }
@asmallteapot
asmallteapot / FunWithRanges.swift
Created November 20, 2017 19:32
Example of using ranges with arrays in Swift 4
import Foundation
/// https://developer.apple.com/documentation/swift/range
enum NamedService: String {
case altamontCorridor
case californiaZephyr
case caltrain
case capitolCorridor
case coaster

Keybase proof

I hereby claim:

  • I am asmallteapot on github.
  • I am asmallteapot (https://keybase.io/asmallteapot) on keybase.
  • I have a public key ASCNlIxuK0-RFIb0Ahx9Q8jQDe-ZUVoew19FIfB52TusUgo

To claim this, I am signing this object:

@asmallteapot
asmallteapot / URLSession+Decodable.swift
Created June 26, 2017 16:25
Code koan: Trivial extension to `URLSession` for decoding responses with `Decodable` in Swift 4
import Foundation
public protocol DataDecoder {
func decode<T>(_ type: T.Type, from data: Data) throws -> T where T : Decodable
}
extension JSONDecoder: DataDecoder {}
extension PropertyListDecoder: DataDecoder {}
extension URLSession {