Skip to content

Instantly share code, notes, and snippets.

View SimplGy's full-sized avatar

Eric Miller SimplGy

View GitHub Profile
@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
@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 / 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 / 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 / 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 / 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 / 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 }

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.

# Update the system's packages
apt-get update
apt-get upgrade
# Set up the `deploy` user
useradd deploy
mkdir /home/deploy
mkdir /home/deploy/.ssh
chmod 700 /home/deploy/.ssh
usermod -s /bin/bash deploy
@SimplGy
SimplGy / hamming.go
Created September 4, 2016 05:14
A beautiful piece of code I didn't write
// https://programmingpraxis.com/2011/08/30/hamming-numbers/
// cosmin said
// October 30, 2012 at 7:14 PM
// Another solution based upon Dijkstra’s paper:
def hammingSeq(N):
h = [1]
i2, i3, i5 = 0, 0, 0
for i in xrange(1, N):
x = min(2*h[i2], 3*h[i3], 5*h[i5])