Skip to content

Instantly share code, notes, and snippets.

View vamsiac's full-sized avatar

Vamsi Anguluru vamsiac

View GitHub Profile
@vamsiac
vamsiac / 0_reuse_code.js
Last active August 29, 2015 14:15
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
@vamsiac
vamsiac / String.swift
Created December 17, 2015 10:08 — forked from kharrison/String.swift
Swift String Playground Examples
// Swift Standard Librray - String
// Keith Harrison http://useyourloaf.com
// Import Foundation if you want to bridge to NSString
import Foundation
// ====
// Initializing a String
// ====
@vamsiac
vamsiac / Fetchable.swift
Last active May 2, 2017 13:23 — forked from capttaco/Fetchable.swift
A utility protocol for custom NSManagedObjects that makes querying contexts simpler and more convenient. Requires Swift 2.
import CoreData
protocol Fetchable
{
associatedtype FetchableType: NSManagedObject = Self
static func entityName() -> String
static func objectsInContext(_ context: NSManagedObjectContext, predicate: NSPredicate?, sortedBy: String?, ascending: Bool) throws -> [FetchableType]
static func singleObjectInContext(_ context: NSManagedObjectContext, predicate: NSPredicate?, sortedBy: String?, ascending: Bool) throws -> FetchableType?
static func objectCountInContext(_ context: NSManagedObjectContext, predicate: NSPredicate?) -> Int
@vamsiac
vamsiac / async_error_handling.md
Created August 16, 2016 10:42 — forked from BlameOmar/async_error_handling.md
Asynchronous Error Handling in Swift 2.0

Asynchronous Error Handling in Swift 2.0

As Swift 1.0 did not include support for exceptions, a common error handling pattern was to use a Result enum that either took on a value on success, or an error on failure. In a way, this was superior to using exceptions, since being a instantiable type, Results could be passed around freely, enabling asynchronous code to use the same error handling mechanisim as synchronous code. Using Swift's robust support for custom operators, this also enabled Railway Oriented Programming for more functional oriented programers.

Swift 2.0 introduces throwable errors, which are similar to exceptions. However, like exceptions, thrown errors

@vamsiac
vamsiac / SKActionTransitionColor.swift
Created January 18, 2019 11:16 — forked from johnnyw/SKActionTransitionColor.swift
[SpriteKit] Custom SKAction to transition the fill/stroke color of an SKShapeNode.
import CoreGraphics
import SpriteKit
extension SKAction {
static func transitionStrokeColor(from: SKColor, to: SKColor, duration: TimeInterval) -> SKAction {
return transitionColor(from: from, to: to, duration: duration, fill: false)
}
static func transitionFillColor(from: SKColor, to: SKColor, duration: TimeInterval) -> SKAction {