Skip to content

Instantly share code, notes, and snippets.

Tyler Stromberg AquaGeek

Block or report user

Report or block AquaGeek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View L10n.swift
struct L10n {
struct Login {
static func welcomeMessage(placeholder: String) -> String {
return String.localizedStringWithFormat(
NSLocalizedString("login.welcome_message", "Greeting to show users upon successful login"),
placeholder
)
}
}
}
View ColorExtensions.swift
extension NSColor {
// Derived from logic in TextMate
func soften(color inColor: NSColor, factor: CGFloat) -> NSColor {
guard let color = inColor.usingColorSpace(NSColorSpace.sRGB) else {
return inColor
}
var red = color.redComponent
var green = color.greenComponent
var blue = color.blueComponent
@AquaGeek
AquaGeek / Tips.md
Created Mar 22, 2017
macOS/AppKit tips
View Tips.md

Override stupid system default that disables state restoration.

UserDefaults.standard.set(true, forKey: "NSQuitAlwaysKeepsWindows")  // override stupid global preference, so our state restore works properly
@AquaGeek
AquaGeek / Manifesto.md
Created Feb 17, 2017
Swift Ownership Manifesto
View Manifesto.md

Ownership

Introduction

Adding "ownership" to Swift is a major feature with many benefits for programmers. This document is both a "manifesto" and a "meta-proposal" for ownership: it lays out the basic goals of the work, describes a general approach for achieving those goals, and proposes a number of specific changes and features, each of which will need to be separately discussed in a smaller and more

View Rx.swift
// Retry with backoff
// Adapted from http://blog.danlew.net/2016/01/25/rxjavas-repeatwhen-and-retrywhen-explained/
Observable
.range(start: 1, count: 10)
.doOn(onNext: { i in
if i == 5 {
throw NSError(domain: "com.example", code: 1, userInfo: ["any": "thing"])
}
})
.retryWhen { (attempts: Observable<ErrorType>) -> Observable<Int64> in
View Storyboards.swift
// FROM: http://ankit.im/swift/2016/01/18/first-pure-swift-ios-app-swiflytics/
protocol StoryboardInstantiable {
typealias ViewController
static var storyboardID: String { get }
static func instance(storyboard: UIStoryboard) -> ViewController?
}
extension StoryboardInstantiable {
static func instance(storyboard: UIStoryboard) -> ViewController? {
return storyboard.instantiateViewControllerWithIdentifier(Self.storyboardID) as? ViewController
View AdjacentList.m
@interface TSGraph : NSObject
- (void)addEdgeFrom:(id)vertexA to:(id)vertexB;
@end
@implementation TSGraph
{
NSMutableDictionary *_vertices;
}
@AquaGeek
AquaGeek / main.m
Created May 23, 2015
Objective-C command line tool
View main.m
@import Foundation;
int main(int argc, const char * argv[])
{
__block BOOL keepRunning = YES;
// Configure a dispatch source to listen for SIGTERM
// Adapted from https://mikeash.com/pyblog/friday-qa-2011-04-01-signal-handling.html
dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM, 0, dispatch_get_main_queue());
dispatch_source_set_event_handler(source, ^{
View LRUCache.swift
private class LRUCacheNode<Key: Hashable, Value> {
let key: Key
var value: Value
var previous: LRUCacheNode?
var next: LRUCacheNode?
init(key: Key, value: Value) {
self.key = key
self.value = value
}
@AquaGeek
AquaGeek / heroku-addons.rb
Last active Sep 25, 2017
Heroku Addons Breakdown
View heroku-addons.rb
require 'uri'
require 'net/http'
require 'json'
require 'ostruct'
module Heroku
module Addons
class Addon
attr_accessor :name
You can’t perform that action at this time.