Skip to content

Instantly share code, notes, and snippets.

@brianpartridge
brianpartridge / superbowl_squares.swift
Last active February 2, 2018 17:32 — forked from anonymous/superbowl_squares.swift
Superbowl Squares random number generator
import Foundation
/// http://stackoverflow.com/a/24029847/4992155
extension MutableCollection where Indices.Iterator.Element == Index {
/// Shuffles the contents of this collection.
mutating func shuffle() {
let c = count
guard c > 1 else { return }
for (unshuffledCount, firstUnshuffled) in zip(stride(from: c, to: 1, by: -1), indices) {
#! /usr/bin/env ruby
# usage:
# $ das_download.rb email password [download_directory]
require "mechanize"
class DasDownloader
attr_reader :agent, :email, :password, :output_dir
def initialize(email, password, output_dir)
/* I'm still trying to wrap my head around this monad.
* Examples either seem contrived or do not use multiple
* types; it's not very useful for understanding when
* every input and output is a string.
*/
@brianpartridge
brianpartridge / gist:df980e8ae9a94a13a8cc
Created February 8, 2016 23:02
Weird Swift crash stack
Crashed: com.apple.main-thread
EXC_BREAKPOINT 0x00000000e7ffdefe
Thread : Crashed: com.apple.main-thread
0 MyApp 0x210ac4 specialized CartTableViewController.tableView(UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath : NSIndexPath) -> String? (CartTableViewController.swift:190)
1 MyApp 0x2106bc specialized CartTableViewController.tableView(UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath : NSIndexPath) -> String? (CartTableViewController.swift:184)
2 MyApp 0x20d990 @objc CartTableViewController.tableView(UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath : NSIndexPath) -> String? (CartTableViewController.swift)
3 UIKit 0x2726acbb -[UITableView _titleForDeleteConfirmationButtonForRowAtIndexPath:] + 146
4 UIKit 0x27392f4f -[UITableView _deleteConfirmationButtonForRowAtIndexPath:] + 102
5 UIKit 0x27393483 -[UITableView _sw
@brianpartridge
brianpartridge / .bashrc
Created January 8, 2016 19:04
Open a project or workspace in the current directory with Xcode. Very useful when you switch between different versions of Xcode.
alias x='open -a `xcode-select --print-path`/../.. .'
@brianpartridge
brianpartridge / CompareSimulator.scpt
Created August 31, 2015 15:48
Load the current iOS Simulator screen into Kaleidoscope
tell application "System Events" to tell process "iOS Simulator"
set frontmost to true
tell menu bar item "Edit" of menu bar 1
# Grab Screenshot
click menu item "Copy Screen" of menu 1
end tell
end tell
tell application "System Events" to tell process "Kaleidoscope"
set frontmost to true
protocol StateMachine {
typealias State
var state: State { get }
func canTransitionToState(newState: State) -> Bool
func transitionToState(newState: State) // throws, in Swift 2
}
@brianpartridge
brianpartridge / gist:e8f1c11be6e897257149
Created August 24, 2014 12:15
Overviewer Chunk Error
$ ./overviewer.py --config=../config.conf
2014-08-24 07:52:29 Welcome to Minecraft Overviewer!
2014-08-24 07:52:29 Generating textures...
2014-08-24 07:52:42 W Tried several times to read chunk -12,-8. It may be corrupt. Giving up.
2014-08-24 07:52:42 E An error has occurred. This may be a bug. Please let us know!
See http://docs.overviewer.org/en/latest/index.html#help
This is the error that occurred:
Traceback (most recent call last):
File "./overviewer.py", line 587, in <module>

Keybase proof

I hereby claim:

  • I am brianpartridge on github.
  • I am brianpartridge (https://keybase.io/brianpartridge) on keybase.
  • I have a public key whose fingerprint is EB71 95B1 4313 F900 01DB 073D 3EE1 E8E9 822C B951

To claim this, I am signing this object:

@brianpartridge
brianpartridge / gist:8939270
Last active August 29, 2015 13:56
An example of how to add keyboard commands to Debug builds of an iOS app. From http://cocoa.tumblr.com/post/75111441462/supporting-keyboard-shortcuts-without-uitextview
#ifdef DEBUG
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (NSArray *)keyCommands {
static NSArray *keyCommands;
static dispatch_once_t onceToken;