Skip to content

Instantly share code, notes, and snippets.

View NSLocale.m
/*
======================================================
THIS CODE IS FOR EDUCATIONAL PURPOSES ONLY.
I'M NOT RESPONSIBLE IF YOU SHIP THIS AND IT BLOWS UP IN YOUR FACE.
IF IT DOES AND YOU COMPLAIN TO ME I WILL LAUGH AT YOU.
@davedelong
davedelong / reenumerate.m
Last active Aug 5, 2019
Reenumerate attached devices
View reenumerate.m
#import <Foundation/Foundation.h>
#import <IOKit/IOKitLib.h>
#import <IOKit/usb/IOUSBLib.h>
int main() {
NSMutableDictionary *match = (__bridge NSMutableDictionary *)IOServiceMatching("IOUSBDevice");
if (match == nil) { return -1; }
match[@"IOPropertyMatch"] = @{@"SupportsIPhoneOS": @YES};
io_iterator_t iterator = 0;
@davedelong
davedelong / marsedit.applescript
Last active Jun 28, 2019
Export a blog from MarsEdit
View marsedit.applescript
on pad(thisNumber)
set thisText to thisNumber as text
if length of thisText = 1 then
return "0" & thisText
else
return thisText
end if
end pad
@davedelong
davedelong / Domino.swift
Created Dec 23, 2018
Mexican Train → given a set of dominos, find the optimal chain for a game of Mexican Train
View Domino.swift
fileprivate let tileBaseH = Array("""
┏━━┳━━┓
┃ ┃ ┃
┗━━┻━━┛
""")
fileprivate let tileBaseV = Array("""
┏━━┓
┃ ┃
┣━━┫
@davedelong
davedelong / build_script.sh
Created Nov 22, 2018
Auto-increment build numbers in release mode
View build_script.sh
# Automatically increment the CFBundleVersion in release builds
config=${CONFIGURATION}
if [ "${config}" = "Release" ]; then
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
else
echo "info: Skipping build number incrementation in ${config} mode"
View japanese_eras.swift
// obviously, we'll need a japanese calendar
let jp = Calendar(identifier: .japanese)
// this is a date formatter that, when formatting a date, gives us the full readable name of the date's era
let jpf = DateFormatter()
// see also: https://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns
jpf.dateFormat = "GGGG"
jpf.calendar = jp
// ranges are numbered starting at 0
View DarkMode.applescript
on setDarkMode(shouldBeDark)
set paneID to "com.apple.preference.general"
tell application "System Events"
if dark mode of appearance preferences is shouldBeDark then return
end tell
set paneWasOpen to false
@davedelong
davedelong / Proposal.md
Last active Apr 3, 2018
Proposal: ContainmentSet
View Proposal.md

Adding the ContainmentSet Protocol to Swift

  • Proposal: SE-TBD
  • Author(s): Dave DeLong
  • Review manager: TBD
  • Status: TBD
@davedelong
davedelong / Collapsing.md
Last active Feb 20, 2018 — forked from joyrexus/README.md
collapsible markdown
View Collapsing.md

collapsible markdown?

CLICK ME

yes, even hidden code blocks!

print("hello world!")
@davedelong
davedelong / Collection.swift
Created Jun 14, 2017
Grouping collections
View Collection.swift
public extension Collection {
func keyedBy<T>(_ keyer: (Iterator.Element) -> T?) -> Dictionary<T, Iterator.Element> {
var d = Dictionary<T, Iterator.Element>()
for item in self {
if let key = keyer(item) {
d[key] = item
}
}
return d