Skip to content

Instantly share code, notes, and snippets.

View dlo's full-sized avatar
Always shipping.

Dan Loewenherz dlo

Always shipping.
View GitHub Profile
@dlo
dlo / JSONSerialization.swift
Last active September 19, 2016 18:21
JSONSerialization extension to hone in on which values are invalid in complex Swift arrays or dictionaries.
extension JSONSerialization {
static func invalidJSONValue(data: Any) -> AnyObject? {
if let elements = data as? [Any] {
if !isValidJSONObject(data) {
for element in elements {
if let value = invalidJSONValue(data: element) {
return value
}
}
@dlo
dlo / NSDecimalNumber.swift
Last active November 13, 2017 10:23 — forked from mattt/NSDecimalNumber.swift
NSDecimalNumber Additions for Swift 3 - Updated
import Foundation
public func ==(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool {
return lhs.compare(rhs) == .orderedSame
}
public func <(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool {
return lhs.compare(rhs) == .orderedAscending
}
@dlo
dlo / force_migration.sh
Last active November 6, 2016 14:14
For those of you who’ve run into the Xcode 8 / Swift migrator hanging issue, this script fixes it. It marks all targets in the project as migrated. For any targets that haven’t actually been migrated to Swift 2.3/3, the script outputs a one-liner that you can cut-and-paste to undo individual targets.
#!/bin/bash
PROJ=$1
if [[ -z "$PROJ" ]]; then
echo "Please provide a path to an Xcode project file."
exit 1
fi
ROOT=$(/usr/libexec/PlistBuddy -c "Print rootObject" $PROJ)
@dlo
dlo / sample.py
Last active August 25, 2016 15:24 — forked from afroisalreadyinu/sample.py
import operator
def build_book_inventory(book_ids, shops):
shop_labels = map(operator.itemgetter('label'), shops)
books = Persistency.books_table.read(shops=shop_labels, books=book_ids)
inventory = {}
for book in books:
shop_inventory = inventory.setdefault(book['shop_label'])
book_inventory = shop_inventory.setdefault(book['cell_label'], {})
Pod::Spec.new do |s|
s.name = "zxing"
s.version = "2.3.0"
s.summary = "Multi-format 1D/2D barcode image processing library."
s.homepage = "http://code.google.com/p/zxing/"
s.author = "ZXing team (http://code.google.com/p/zxing/people/list)"
s.source = { :git => "https://github.com/zxing/zxing.git", :revision => "00f634024ceeee591f54e6984ea7dd666fab22ae" }
s.requires_arc = false
# workaround for a missing import in objc/src/ZXing/ZXImage.mm
@dlo
dlo / README.md
Last active February 2, 2024 02:18
Xcode script that automatically uploads builds to iTunes Connect after archive

Summary

This script will automatically upload your app to iTunes Connect after a successful Xcode archive action.

After doing this about a million times by hand (i.e., opening the Organizer, clicking on "Upload to App Store", waiting for teams to load, etc.), I decided I'd had enough. Now, I just go to "Product" > "Archive", sip my margherita, and kick up my feet while the world marvels at my genius, while my app gets distributed to my testers without lifting but a finger. Or...I just take a bathroom break. Either way, it's pretty awesome.

Yes, yes, I know you can do this completely via fastlane, but I'm somewhat sadistic and prefer to do my archiving completely within Xcode.

Instructions

KEYWORDS="TODO|FIXME|\?\?\?:|\!\!\!:"
cd "${SRCROOT}"
find . ! \( -path ./Pods -prune \) -type f -name "*.swift" -print0 \
| xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" \
| perl -p -e "s/($KEYWORDS)/ warning: \$1/"
@dlo
dlo / REFUND.md
Last active May 22, 2017 03:39
Instant App Store refunds

Hi,

You can get a refund by following this process:

  1. Visit https://reportaproblem.apple.com logged in with the Apple ID you purchased the app with.
  2. Find the app in the list or search.
  3. Click "Report a Problem".
  4. In the dropdown, choose "Item opens but doesn't function as expected".
  5. Click "Submit".
func selectionSort(_ array: [Int]) -> [Int] {
guard let minValue = array.min(), let index = array.index(of: minValue) else {
return []
}
let ranges = [0..<index, index.advanced(by: 1)..<array.endIndex]
return [minValue] + selectionSort(ranges.lazy.flatMap { array[$0] })
}
@dlo
dlo / dispatch_once.swift
Created June 20, 2016 01:43 — forked from kristopherjohnson/dispatch_once.swift
Example of using dispatch_once() in Swift
import Foundation
var token: dispatch_once_t = 0
func test() {
dispatch_once(&token) {
println("This is printed only on the first call to test()")
}
println("This is printed for each call to test()")
}