Skip to content

Instantly share code, notes, and snippets.

Avatar

David Beck davbeck

View GitHub Profile
@davbeck
davbeck / README.md
Last active Aug 29, 2015
TNKPropertyKey
View README.md

It's become common practice to use an @selector for associated objects. This is useful because not only are SELs guaranteed to have a unique address, but because as of Xcode 5, Xcode will warn you when you use a selector that it does not know about. Meaning that it is somewhat protected against spelling mistakes.

This can also be useful when using string keys. For things like state restoration, where you want a key for a given property, you can use the selector for the getter, and get a string from that. Xcode will autocomplete the name for you, and will warn you if you misspell it.

- (void)encodeRestorableStateWithCoder:(NSCoder *)coder
{
    [super encodeRestorableStateWithCoder:coder];
    
    [coder encodeObject:self.feedID forKey:TNKPropertyKey(feedID)];
@davbeck
davbeck / time_zone_map.rb
Created Oct 2, 2014
Generate Time Zone Mapping
View time_zone_map.rb
#!/usr/bin/env ruby
#encoding: utf-8
require 'active_support/all'
timezones = ActiveSupport::TimeZone::MAPPING.map { |rails_name, name|
zone = ActiveSupport::TimeZone.new(name)
{
rails_name => {
offset: zone.utc_offset,
@davbeck
davbeck / formatted_mapping.json
Created Oct 2, 2014
Android/Rails Time Zone Mapping
View formatted_mapping.json
{
"International Date Line West":{
"offset":-39600,
"abbreviation":"SST",
"name":"Pacific/Midway"
},
"Midway Island":{
"offset":-39600,
"abbreviation":"SST",
"name":"Pacific/Midway"
View TNKURLFormatter.swift
//
// TNKURLFormatter.swift
//
// Created by David Beck on 2/6/15.
// Copyright (c) 2015 ThinkUltimate. All rights reserved.
//
import Foundation
@davbeck
davbeck / NSObject+TUBlockDealloc.h
Created Nov 29, 2012
Execute block on dealloc
View NSObject+TUBlockDealloc.h
//
// NSObject+TUBlockDealloc.h
// ThinkGV
//
// Created by David Beck on 4/20/12.
// Copyright (c) 2012 ThinkUltimate LLC. All rights reserved.
//
#import <Foundation/Foundation.h>
View NSNumber+Wrapper.swift
extension NSNumber {
@nonobjc convenience init(_ value: Bool) {
self.init(bool: value)
}
@nonobjc convenience init(_ value: Float) {
self.init(float: value)
}
@nonobjc convenience init(_ value: Double) {
@davbeck
davbeck / imgix.md
Created May 16, 2016
imgIX summary
View imgix.md

imgIX

imgIX is similar to a proxy CDN that sits between where we store the full-size images and the devices and browsers that download them. Images are not stored in imgIX directly but instead on an HTTP server such as S3. You configure "sources" in imgIX that then proxy to the source server.

In our case, we would upload images directly to S3, then the clients would request them using the imgIX URL instead of the direct S3 URL. You can then include URL parameters in addition to the original URL that specify the size you will display the images at, the pixel density (ie retina), as well as other transformations such as auto compression. This leads to drastically smaller file sizes, which download faster, use less bandwidth and use less memory on the user's device. There are other features we can take advantage of like smart cropping that centers detail like faces in square cropped photos.

Tests

I uploaded 4 photos from an iPhone 6s to S3 using the app and then tested their dow

View swift-options.md

Swift options

Recently, 2 Swift Evolution proposal results have really disappointed me. Together they move Swift away from the flexibility of using method parameters as option lists.

SE-0060 Enforcing order of defaulted parameters, which was accepted, removes the ability to provide optional parameters in any order you like. I had actually hoped to go the other direction and extend this ability to include required parameters. Now, as you add and remove parameters to a call site, you have to make sure to do so in the proper order. As the number of parameters a method takes grows, and as the relation between them gets weaker, it becomes more and more difficult to determine the correct positioning without referring to documentation.

SE-0084 Allow trailing commas in parameter lists and tuples was rejected. This proposal so

View workflow.md

Workflow

We use Jira to track bugs and features and git flow to track changes to the code. The workflow for a ticket goes as follows:

  1. The developer moves a ticket into the "In Progress" column, assigning it to themselves.

  2. The developer creates a new branch off of develop (or another feature branch if necessary) naming it feature/REALM-XXXXX-description where "REALM-XXXXX" is the ticket number in Jira and "description" is a 1-3 word description of the ticket.

  3. Any changes needed to fulfill the ticket are performed in 1 or more commits. Each commit should start with the ticket number, as in REALM-XXXXX Added link to make a gift. Prefixing the ticket number here causes the commit to appear in Jira.

@davbeck
davbeck / xcode.sh
Created Aug 4, 2016
Xcode switching
View xcode.sh
#!/usr/bin/env bash
rm -rf /Users/davbeck/Library/Developer/Xcode/DerivedData
osascript -e 'quit app "Simulator"'
osascript -e "tell application \"Xcode\"
close every window
end tell"
osascript -e 'quit app "Xcode"'