Skip to content

Instantly share code, notes, and snippets.

View ketzusaka's full-sized avatar

james ketzusaka

  • Tools for Humanity
  • San Francisco, CA
  • 21:35 (UTC -07:00)
View GitHub Profile
/*
This is a Swift Singleton. Lack of inline class variables right now make this a slightly more difficult task.
Please ignore the oddly named class for the example. viewWillAppear made for good testing ;)
*/
class DetailViewController: UIViewController {
func sharedInstance() -> DetailViewController {
struct Container {
static var instance: DetailViewController?
static var token: dispatch_once_t = 0
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDECodeSnippetCompletionPrefix</key>
<string>swift_dispatch_once</string>
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>All</string>
</array>
@ketzusaka
ketzusaka / gist:12743fa9d6569dbb447d
Created June 6, 2014 03:38
Swift Operator Overloading Adding << On Array
/*
In Swift, you can overload operators. A common operator in Ruby for working with arrays is <<,
which is syntatic sugar for array.push(). Since Array's in Swift don't take bitwise operations, this is
an example demonstrating adding that operator to an array that contains any type.
As an extra tidbit, I've added >> to prepend an array with an object
*/
@infix func << <T>(inout array: Array<T>, item: T) {
array.append(item)
@ketzusaka
ketzusaka / gist:6198106
Last active December 20, 2015 21:29
Option Checking in Ruby: Hash vs Bitwise Operations This is a simple script that compares how fast it is to build option dictionaries and checking them versus using integers and bitwise flagging
require 'benchmark'
class HashedFlags
def initialize(opts = {})
@silly_prepend = opts.fetch(:silly_prepend, false)
@uppercase = opts.fetch(:uppercase, false)
end
end
SILLY_PREPEND = 0b00000001