Skip to content

Instantly share code, notes, and snippets.

@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
//: 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 / 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 {
@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 / 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 / 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 / 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 / PerformOnExit.cs
Created May 14, 2020 14:02
A C# class to call a method when the object goes out of scope.
/// <summary>
/// Performs an action when disposed.
/// <code>
/// using (new PerformOnExit(Foo))
/// {
/// Bar();
/// }
/// </code>
/// </summary>
public sealed class PerformOnExit : IDisposable
@steverichey
steverichey / delete_git_submodule.md
Last active January 26, 2021 14:43 — forked from myusuf3/delete_git_submodule.md
How to effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes: git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path/to/submodule (no trailing slash).
  • Run rm -rf .git/modules/path/to/submodule (no trailing slash).
  • Commit git commit -m "Removed submodule <name>"
  • Delete the now untracked submodule files: rm -rf path/to/submodule
import sys
pair_table = {
"a" : ("", 1),
"b" : ("", 2),
"c" : ("", 3),
"d" : ("", 4),
"e" : ("", 5),
"f" : ("", 6),
"g" : ("", 7),