Skip to content

Instantly share code, notes, and snippets.

@steverichey
steverichey / LittleTyper.swift
Created May 4, 2020 15:22
A Swift playground for the beginning of the book, The Little Typer
import Cocoa
import Foundation
protocol AtomType {}
struct Atom: AtomType {}
func == <Atom1, Atom2> (lhs: Atom1, rhs: Atom2) -> Bool where Atom1: AtomType, Atom2: AtomType {
return type(of: lhs) == type(of: rhs) // maybe
}
@steverichey
steverichey / pw
Created October 25, 2019 21:54
Simple password generator, version 2
#!/usr/bin/env sh
set -eur
generate()
{
allowed_characters="${1}"
number_of_characters="${2}"
cat /dev/random | env LC_CTYPE=C tr -cd "${allowed_characters}" | head -c "${number_of_characters}"
}
@steverichey
steverichey / imagenet_labels.txt
Created March 29, 2019 19:39
Just the ImageNet labels used by ResNet.
tench
goldfish
great_white_shark
tiger_shark
hammerhead
electric_ray
stingray
cock
hen
ostrich
@steverichey
steverichey / keep-adb-running.sh
Last active November 28, 2018 15:23 — forked from mauron85/keep-adb-running.sh
Workaround adb disconnecting issue on macOS Sierra
#!/bin/bash
cat << EOF
###########################################################
# Workaround adb disconnecting issue on macOS Sierra
#
# More info:
# https://code.google.com/p/android/issues/detail?id=219085
# credits to: hans...@meetme.com, vs...@google.com
###########################################################
@steverichey
steverichey / pw
Created November 21, 2018 03:52
Password generation script
#!/bin/sh
set -e
# generate allowed_characters number_of_characters
generate()
{
cat /dev/random | env LC_CTYPE=C tr -cd $1 | head -c $2
}
@steverichey
steverichey / xoshiroPRNG.swift
Created November 21, 2018 03:20
Not thoroughly tested, needs update for some Random changes in Swift
import Foundation
// http://xoshiro.di.unimi.it/xoshiro256starstar.c
protocol PseudoRandomNumberGenerator {
associatedtype ReturnValue
mutating func next() -> ReturnValue
}
struct Arc4Random: PseudoRandomNumberGenerator {
//: Playground - noun: a place where people can play
import Cocoa
let caseLookup: [Character: Character] = [
"a": "A", "b": "B", "c": "C", "d": "D", "e": "E", "f": "F", "g": "G", "h": "H", "i": "I", "j": "J", "k": "K", "l": "L", "m": "M", "n": "N",
"o": "O", "p": "P", "q": "Q", "r": "R", "s": "S", "t": "T", "u": "U", "v": "V", "w": "W", "x": "X", "y": "Y", "z": "Z"
]
extension Dictionary where Value: Equatable {
@steverichey
steverichey / allow_ios_firewall.sh
Created July 30, 2018 13:33
In theory, allows the iOS simulator to bypass the firewall. May no longer be needed, or it works so well I no longer get the dialog prompt.
#!/bin/sh
# requires sudo
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off
/usr/libexec/ApplicationFirewall/socketfilterfw --add /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on
@steverichey
steverichey / gifopt.sh
Created July 13, 2018 14:16
GIF creation with some optimization options
#!/bin/sh
# this was created for an admittedly specialized purpose but has some neat settings i want to remember
palette="/tmp/palette.png"
cropped="/tmp/cropped.mp4"
width="275"
filters="fps=15,scale=${width}:-1:flags=lanczos"
@steverichey
steverichey / Camera.playground
Created June 29, 2018 21:20
Camera edge detection demo for Realities 360
import Cocoa
import AVFoundation
import AVKit
import QuartzCore
import PlaygroundSupport
import AppKit
import CoreGraphics
import CoreImage
let playgroundView = NSView(frame: NSRect(x: 0.0, y: 0.0, width: 640.0, height: 480.0))