Skip to content

Instantly share code, notes, and snippets.

import Foundation
struct Contains {
let value: String
init(_ str: String) {
value = str
}
}
import Foundation
public struct CartesianProductIterator<X, Y>: IteratorProtocol where X: IteratorProtocol, Y: Collection {
private var xIt: X
private let yCol: Y
private var x: X.Element?
private var yIt: Y.Iterator
@jemmons
jemmons / params.swift
Created June 8, 2017 22:01
Turning JSON into URLQueryParams
func f(_ jsonValue: Any, prefix: String? = nil) throws -> [URLQueryItem] {
var items: [URLQueryItem] = []
switch jsonValue {
case let d as Dictionary<String, Any>:
try d.forEach {
let newPrefix = prefix == nil ? $0.key : prefix! + "[\($0.key)]"
items.append(contentsOf: try f($0.value, prefix: newPrefix))
}
@jemmons
jemmons / RunScriptPhase.sh
Created February 22, 2017 16:26
Build number in Xcode build script.
#!/bin/bash
if [ "${CONFIGURATION}" != "Debug" ]
then
buildNumber=$(date +"%Y%m%d%H%M")
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" ${INFOPLIST_FILE}
fi
import Foundation
protocol `enum` {
func `protocol`()
}
struct `class`: `enum` {
func `protocol`() {
print("hello!")
}
@jemmons
jemmons / Fireballed.terminal
Last active February 8, 2017 00:25
Terminal.app theme inspired by Daring Fireball.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ANSIBlueColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
LjM1MDgzOTA3NzIgMC4zNTA4MzkwNzcyIDAuNjg5ODcwODQ1NAAQAoAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
@jemmons
jemmons / jemmons-ized.dvtcolortheme
Created February 8, 2017 00:24
Solarized dark theme for Xcode.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>0.324366 0.407177 0.438506 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>SourceCodePro-Medium - 14.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>0.505992 0.564858 0.563637 1</string>
@jemmons
jemmons / jemmons-ized Light.dvtcolortheme
Created February 8, 2017 00:23
Solarized light theme for Xcode.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>0.324366 0.407177 0.438506 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>SourceCodePro-Medium - 14.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>0.505992 0.564858 0.563637 1</string>
@jemmons
jemmons / Hairline.swift
Last active November 13, 2019 08:31
Draws a `singlePixelLine` line above or below the given point, depending on `topBias`.
import UIKit
func singlePixelLine(at y: CGFloat, in rect: CGRect, topBias: Bool = true) {
let offset = pixelUnit/2.0
let adjustedY = round(from: y - offset, fraction: pixelUnit, down: topBias) + offset
let line = makeLine(at: adjustedY, in: rect)
strokePath(line, width: pixelUnit)
}
/* Doesn't work. */
NSLocale.currentLocale().displayNameForKey(NSLocaleCountryCode, value: "DE")
//> nil
/* Does work. */
NSLocale(localeIdentifier: "en_US").displayNameForKey(NSLocaleCountryCode, value: "DE")
//> "Germany"