Skip to content

Instantly share code, notes, and snippets.

BJ Homer bjhomer

Block or report user

Report or block bjhomer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bjhomer
bjhomer / enumFilter.swift
Created Jan 15, 2019
Is there a better way to do this?
View enumFilter.swift
enum Thing {
case empty
case int(Int)
}
let things: [Thing] = [.empty, .int(3), .int(7)]
// Surely there's a more concise way to write this `filter` closure?
let intThings = things.filter({
if case Thing.int = $0 { return true }
@bjhomer
bjhomer / .gitconfig
Created Apr 27, 2018
git delete-merged
View .gitconfig
[alias]
delete-merged = !bash -c '\
REMOTE=$1 && \
REMOTE=${REMOTE:="origin"} && \
echo "Fetching $REMOTE" && \
git fetch $REMOTE --prune && \
git branch -vv | grep "gone]" | awk \"{ print \\$1 }\" | xargs git branch -d' -
# usage: `git delete-merged`
View layoutPriorityHelpers.swift
public extension NSLayoutConstraint.Priority {
public static func -(lhs: NSLayoutConstraint.Priority, rhs: Float) -> NSLayoutConstraint.Priority {
return NSLayoutConstraint.Priority(lhs.rawValue - rhs)
}
public static func +(lhs: NSLayoutConstraint.Priority, rhs: Float) -> NSLayoutConstraint.Priority {
return NSLayoutConstraint.Priority(lhs.rawValue + rhs)
}
}
View fish_prompt.fish
# ~/.config/fish/functions/fish_prompt.fish
function fish_prompt --description 'Write out the prompt'
# Just calculate these once, to save a few cycles when displaying the prompt
if not set -q __fish_prompt_normal
set -g __fish_prompt_normal (set_color normal)
end
set -l delim '$'
@bjhomer
bjhomer / operationCompletionBlock.swift
Last active Jun 2, 2017
Proof that NSOperation.completionBlock is not being cleared.
View operationCompletionBlock.swift
// Run this in an iOS playground. It works correctly on Mac.
import Foundation
import PlaygroundSupport
let page = PlaygroundPage.current
page.needsIndefiniteExecution = true
@bjhomer
bjhomer / feed.json
Created May 19, 2017
Check the md5 for the thumbnail of moment ID 2230DA8A73AE42958884030BEA8EC958
View feed.json
{
"cursor": 302,
"revision": {
"entryId": "796C229F25F64223ABF87CEB05AA273B",
"saveDate": 1475160495641,
"featureFlags": "1",
"editDate": 1475160494747,
"journalId": "398870",
"revisionId": 2538,
"moments": [
View crash.swift
import Foundation
enum Foo: Error {
case dogAteHomework
}
func makesAnError(_ error: NSErrorPointer) {
autoreleasepool {
error?.pointee = Foo.dogAteHomework as NSError
}
View swift-build-failure.txt
[519/1021] Building HTML documentation
FAILED: docs/CMakeFiles/docs_html
cd /Users/bjhomer/Projects/swift-source/swift/docs && /usr/local/bin/sphinx-build -W -D latex_paper_size=letter -d /Users/bjhomer/Projects/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/doctrees -b html . /Users/bjhomer/Projects/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/docs/html
Running Sphinx v1.6b3
/usr/local/Cellar/python/2.7.7_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.6b3-py2.7.egg/sphinx/util/requests.py:64: UserWarning: Some links may return broken results due to being unable to check the Server Name Indication (SNI) in the returned SSL cert against the hostname in the url requested. Recommended to install "requests[security]" as a dependency or upgrade to a python version with SNI support (Python 3 and Python 2.7.9+).
'Some links may return broken results due to being unable to '
Warning, treated as error:
unknown config value 'latex_paper_size' in override, ignor
@bjhomer
bjhomer / crowder_climate.md
Last active May 31, 2017
Response to Ben Crowder's "Top 5 climate myths" video
View crowder_climate.md

I was sent a link to a video by Ben Crowder, titled DEBUNKED: Top 5 "Climate Change" Myths. (Link) The person who sent me the video said that it encapsulates a lot of their own skepticism about climate change, and wanted to know if I had any response. This is my response.


Crowder makes a bunch of argments, but groups them broadly under 5 main claims. We'll address them individually.

1: There's no Scientific Consensus

Claim:

  • The initial paper showing a 97% consensus among scientists has some flaws. They didn't sample enough people, etc. So we don't really know how much consensus there is.
@bjhomer
bjhomer / searchingAString.swift
Last active Feb 2, 2017
Incrementally searching through a string in Swift
View searchingAString.swift
import Foundation
let str = "abXcdXefXg"
let start = str.startIndex
var searchStart = start
while let xRange = str.range(of: "X", range: searchStart..<str.endIndex) {
searchStart = xRange.upperBound
You can’t perform that action at this time.