Skip to content

Instantly share code, notes, and snippets.

View SimplGy's full-sized avatar

Eric Miller SimplGy

View GitHub Profile

If you use Spotify without cellular data, all you'll ever see for album art is a gray circle with a white musical note inside it.

image

I'm pretty familiar with spotify. Been a paid subscriber for a long time and visited Sweden, staying in the Jarl Birger hotel right under you guys. :)

Still, I never noticed how much I missed album art until one day I accidentally left cellular data on and chewed through a half gig of data.

I love album art. It's beautiful, connects me to the band, and I always want to see it.

@SimplGy
SimplGy / Wrap+Unbox+Symmetrical.swift
Last active May 17, 2016 18:51
An Experiment working on Enforced Symmetricality with JohnSundell's Wrap+Unbox
//
// A definition for the kind of model objects this library can work on
//
import Foundation
public protocol CollieModel: Unboxable, WrapCustomizable, Hashable, CustomStringConvertible {
/// Configure the mapping between client and server property names. keys are client names and values are JSON names eg: "authorId: "author_id"
static var propertyMapping: [String: String]? { get }
@SimplGy
SimplGy / optionalEnum.swift
Last active July 19, 2016 18:21
Switching on optional enums
enum Coin {
case heads
case tails
}
var result: Coin?
// You can pattern match against it like an optional:
switch result {
case .heads?: print("heads")
case .tails?: print("tails")
@SimplGy
SimplGy / openDeepLink.swift
Last active March 24, 2016 20:53
Opens a deep link into an app (Waitress). If that app isn't installed, open the app store for the app instead. Encode a back link into the app open url so the target app can navigate back to this app.
@SimplGy
SimplGy / jekyll-cheat-sheet.md
Last active March 17, 2016 18:01
Jekyll Cheat Sheet

Jekyll Cheat Sheet

Preview posts

Add a _drafts folder as a sibling of _posts. You add posts inside it the same way. To preview drafts, start jekyll with jekyll s --wD. The D is for Drafts.

Categorize blog posts

Jekyll only allows one category per post. You can apply the category by front matter or subfolder, but subfolder never gets forgotten so it's recommended. If you need more than one "something" per post, create a separate front matter field:

@SimplGy
SimplGy / logVCinitAndDeinit.swift
Created February 12, 2016 02:35
Sometimes you need to make sure init and deinit happen in the right order on your View Controllers, and you don't stand up two at once.
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
print("init nibName: \(self) \(unsafeAddressOf(self))")
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
print("init coder: \(self) \(unsafeAddressOf(self))")
}
deinit {
print("deinit coder: \(self) \(unsafeAddressOf(self))")
@SimplGy
SimplGy / apple-app-site-association
Last active December 20, 2015 00:58
Waitress app site assoc file
{
"applinks": {
"apps": [],
"details": [
{
"appID": "68Q8TRPLTN.com.waitress.ios",
"paths": [ "/place/*" ]
}
]
}
@SimplGy
SimplGy / currencyDisplayAsEnum.swift
Last active October 11, 2015 16:24
Playing around with enums and computed properties as a way to display formatted values in Swift. Usage: `let sek = Currency.Code(rawValue: "SEK"); print(sek.display("42.50")`
class Currency {
static private let decimals: [Code: Int] = [
Code.None: 0,
Code.DKK: 2,
Code.GBP: 2,
Code.NOK: 2,
Code.SEK: 2,
Code.USD: 2,
Code.XBT: 2
  • Single Responsibility -- one thing per file
  • IIFE -- free from coffeescript
  • Modules -- declare once, nest namespaces
  • Controllers -- name your fns, use controllerAs, vm = this, public methods at top of file
  • Services -- delegate all possible behavior to here for easier testing
  • Factories -- api up top, use promises for data calls
  • Data Services
  • Directives
  • Resolving Promises for a Controller
  • Manual Annotating for Dependency Injection
@SimplGy
SimplGy / createColoredIconImage.swift
Created August 19, 2015 10:07
Create a colored version of an existing UIImage in swift. Great for coloring icons.
class Icon {
// Create a colored version of an existing image. Great for coloring icons.
// @param name of the image in your bundle
// @param color of the image to return
static func createColoredVersionOfImageNamed(name: String, color: CGColor) -> UIImage {
let img = UIImage(named: name)!
let rect = CGRect(origin: CGPointZero, size: img.size)
UIGraphicsBeginImageContextWithOptions(rect.size, false, img.scale)
let context = UIGraphicsGetCurrentContext()