Skip to content

Instantly share code, notes, and snippets.

View alexcurylo's full-sized avatar

Alex Curylo alexcurylo

View GitHub Profile
@alexcurylo
alexcurylo / 0_reuse_code.js
Last active August 29, 2015 14:14
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@alexcurylo
alexcurylo / ThreadsafeDF.m
Created February 16, 2015 02:30
Threadsafe Date Formatting
+ (NSDateFormatter *)dateReader
{
NSMutableDictionary *dictionary = [[NSThread currentThread] threadDictionary];
NSDateFormatter *dateReader = [dictionary objectForKey:@"SCDateReader"];
if (!dateReader)
{
dateReader = [[[NSDateFormatter alloc] init] autorelease];
dateReader.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];
dateReader.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
dateReader.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss Z";
@alexcurylo
alexcurylo / gist:e363411537dfe3aeb2ba
Created April 1, 2015 23:32
ASCIIImage_sample.m
+ (UIImage *)chevronImageWithColor:(UIColor *)color
{
NSArray *asciiRep =
@[
@"· · · · · · · · · · · ·",
@"· · · 1 2 · · · · · · ·",
@"· · · A # # · · · · · ·",
@"· · · · # # # · · · · ·",
@"· · · · · # # # · · · ·",
@alexcurylo
alexcurylo / singleton.swift
Last active May 8, 2016 03:46
Correct Swift Singleton
class TheOneAndOnlyKraken {
static let sharedInstance = TheOneAndOnlyKraken()
}
@alexcurylo
alexcurylo / PatternMatching.swift
Last active May 17, 2016 02:45
From Crunchy Development's Pattern Matching series
enum Media {
case Book(title: String, author: String, year: Int)
case Movie(title: String, director: String, year: Int)
case WebSite(urlString: String)
}
let mediaList: [Media] = [
.Book(title: "Harry Potter and the Philosopher's Stone", author: "J.K. Rowling", year: 1997),
.Movie(title: "Harry Potter and the Philosopher's Stone", director: "Chris Columbus", year: 2001),
.Book(title: "Harry Potter and the Chamber of Secrets", author: "J.K. Rowling", year: 1999),
import UIKit
// 1
private var maxLengths = [UITextField: Int]()
// 2
extension UITextField {
// 3
@IBInspectable var maxLength: Int {
#!/usr/bin/env xcrun swift -F Carthage/Build/Mac
import Foundation
import Markingbird
protocol Streamable {
var title: String { get }
var body: String { get }
}
class SomeViewController: UIViewController {
private typealias My = SomeViewController
private let videoPlayer: AVPlayer
private let videoPlayerLayer: AVPlayerLayer
override init(nibName: String?, bundle nibBundle: NSBundle?) {
(videoPlayer, videoPlayerLayer) = My.commonInit()
@alexcurylo
alexcurylo / StandOnGuard.swift
Created June 8, 2016 06:29
Guard failure diagnosis
guard let keypath = dictionary["field"] as? String,
let rule = dictionary["rule"] as? String,
let comparator = FormFieldDisplayRuleComparator(rawValue: rule),
let value = dictionary["value"]
else
{
return nil
}