Skip to content

Instantly share code, notes, and snippets.

View a2's full-sized avatar
🐼

Alex Akers a2

🐼
View GitHub Profile
@a2
a2 / pass-payload.js
Created August 13, 2017 16:17
Swiftly Passcards
{
// must be 1
"formatVersion": 1,
// required for "dynamic" passes
"authenticationToken": "<secret>",
"serialNumber": "<secret>",
"webServiceURL": "https://pass.a2.io/",
// top-left "logo" text
// Version A
// - crashes if viewControllers is empty
// - crashes if first VC is not of type MyViewController
let navigationController = ...
let myViewController = navigationController.viewControllers.first as! MyViewController
myViewController.configurationObject = ...
// Version B
// - doesn't crash, ever
// - does nothing if viewControllers is empty or the first is not of type MyViewController
import Guaka
enum MainError: Error, CustomStringConvertible {
case example
var description: String {
switch self {
case .example:
return "This is an example error."
}
import UIKit
protocol ViewProtocol {
var view: UIView { get }
}
extension ViewProtocol where Self: UIView {
var view: UIView {
return self
}
@a2
a2 / guard.swift
Created August 24, 2016 15:27 — forked from CastIrony/guard.swift
guard !arguments.isEmpty,
nums.count = arguments.count
else {
print("Usage: \(appName) <list-of-positive-integers>")
exit(-1)
}
infix operator <+ {}
func <+ <C: RangeReplaceableCollectionType>(inout collection: C, element: C.Generator.Element) {
collection.append(element)
}
var array = [String]()
array <+ "Foo"
array <+ "Bar"
@a2
a2 / SassMeister-input.scss
Created February 13, 2016 12:05
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
@function at2x-name($filename) {
$length: str-length($filename);
@if $length == 0 {
// return empty if input is empty
@return $filename;
}
@a2
a2 / safari_history.sh
Created December 1, 2015 15:34
Most Visited Safari Sites
sqlite3 -column ~/Library/Safari/history.db 'SELECT "visit_count", "url" FROM "history_items" ORDER BY "visit_count" DESC LIMIT 5;'
extension RangeReplaceableCollectionType {
init<S: SequenceType where S.Generator.Element == Self.Generator.Element>(sequence: S) {
self.init()
extend(sequence)
}
}
extension RangeReplaceableCollectionType where Index: IntegerType {
init<S: SequenceType where S.Generator.Element == Self.Generator.Element>(sequence: S) {
self.init()
Verifying I am +a2 on my passcard. https://onename.com/a2