Skip to content

Instantly share code, notes, and snippets.

View designatednerd's full-sized avatar

Ellen Shapiro designatednerd

View GitHub Profile
@designatednerd
designatednerd / AsyncToSync.swift
Created October 15, 2019 23:05
Playground showing how to take an async API and make it synchronous
import UIKit
struct AsyncAPI {
enum AsyncAPIError: Error, LocalizedError {
case callDidNotCompleteSynchronously
case noErrorAndNoData
var errorDescription: String? {
switch self {
@designatednerd
designatednerd / Contents.swift
Created July 3, 2019 14:27
Composing A Protocol
protocol BaseDelegate: class {
func baseMethod()
}
protocol SecondaryDelegate: BaseDelegate {
func secondaryMethod()
}
protocol TertiaryDelegate: BaseDelegate {
func tertiaryMethod()
@designatednerd
designatednerd / Resources-en.lproj-Localizable.stringsdict
Last active February 26, 2020 17:32
99 Bottles of Beer On The Playground
<?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>beers_on_wall</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@beers@</string>
<key>beers</key>
<dict>
@designatednerd
designatednerd / Contents.swift
Last active September 16, 2018 14:26
Chainable Result
//: This is based on Vincent Pradeilles' NSSpain 2018 lightning talk. I tried to find a way around using a
//: custom operator for this because I haaaaate custom operators, but everything else I tried just led to
//: more callback hell.
//:
//: Custom `infix` operators allow you to pass the left hand side and right hand side of the operator as
//: the first and second parameters of a function. I couldn't figure out how to make a function which did that.
//:
//: Vincent's original approach is outlined here:
//: https://github.com/vincent-pradeilles/slides/blob/master/nsspain-2018-solving-callback-hell-with-good-old-function-composition.pdf
//:
@designatednerd
designatednerd / Contents.swift
Created February 16, 2018 11:49
SwiftTimeZones.playground
//: Playground - noun: a place where people can play
import UIKit
print("Time Zone Abbreviation: Time Zone Identifier\n")
print(TimeZone.abbreviationDictionary.map { "\($0): \($1)" }.sorted().joined(separator: "\n"))
print("\n\nKnown Time Zone Identifiers:\n")
print(TimeZone.knownTimeZoneIdentifiers.joined(separator: "\n"))
let utc = TimeZone(identifier: "UTC")!
@designatednerd
designatednerd / android_for_ios_intro.sh
Created April 1, 2017 18:10
Fun With The Voices In My Mac
#!/bin/bash
# http://www.makeuseof.com/tag/siri-voice-mac/
# list all voices: say -v ? "hello world"
# US female (Siri) voice: -v "Samantha"
# Irish female voice: -v "Moira"
# Australian female voice: -v "Karen"
# Indian-english voice: -v "Veena"
@designatednerd
designatednerd / CountableIntEnum.swift
Last active August 3, 2018 06:14
Swift 3 Helpers for getting all the cases of a given enum [Swift 3]
import Foundation
/**
A swift protocol to make any Int enum able to count its cases.
Super-useful for making enums to help you deal with sections in tableviews without having to maintain a case for the count of the enum.
Originally developed by Logan Wright for Swift 2.0 here:
https://gist.github.com/LoganWright/c8a26b1faf538e40f747
@designatednerd
designatednerd / build.gradle
Created December 16, 2015 21:31
Using the number of commits in the HEAD to auto-increment your android version count.
//Counts the number of commits on the HEAD of the repo.
def headCommitCount() {
def cmd = "git rev-list HEAD --count"
return cmd.execute().text.toInteger()
}
android {
defaultConfig {
versionCode headCommitCount() //Auto-increment the version based on how many commits have occurred.
versionName "x.x.x (" + versionCode + ")"
/**
How to get a method which takes any string enumeration in Swift 2.1.
Actually figured out by Carl Hill-Popper, documented by me.
*/
import UIKit
// 1) Make you some string enums.
@designatednerd
designatednerd / rdar-20211159.playground
Last active August 29, 2015 14:17
NSDecimalNumber lulz
/*
Fun with NSNumber to integer and unsigned integer conversions! This
bit someone trying to use key-value coding to get the average of a
given number out of an array of items with an NSUInteger property.
The NSNumber which came out of the @avg.value KVC method was of value
588.33333333333333333333333333333333333. The person then tried to access
this value by calling both average.integerValue and
average.unsignedIntegerValue.