Skip to content

Instantly share code, notes, and snippets.

View JessyCatterwaul's full-sized avatar

Jessy Catterwaul JessyCatterwaul

View GitHub Profile
infix operator • {precedence 255}
/// Used when you'd normally use the dot operator to get a property,
/// but you have to store that operation as a closure for whatever reason.
///
///- Parameter instance: instance on which you'd normally use a dot
///- Parameter property: returns a Property when supplied with an instance
///
///- Returns: the property
///
public struct CoreError: ErrorType {
public init(
_ reason: String,
_ context: String = __FILE__
) {
self.reason = reason
self.context = context
}
let
@JessyCatterwaul
JessyCatterwaul / =================Able.swift
Last active December 6, 2015 06:27
catterwaul.com/=================Able
infix operator • {precedence 255}
/// Used when you'd normally use the dot operator to get a property,
/// but you have to store that operation as a closure for whatever reason.
///
///- Parameter instance: instance on which you'd normally use a dot
///- Parameter property: returns a Property when supplied with an instance
///
///- Returns: the property
///
enum StringPaddingStyle {case Left, Right}
func padStringToLength(
sourceString: String,
destinationCount: Int,
paddingStyle: StringPaddingStyle = .Left,
paddingCharacter: Character = " "
) -> String {
let padCount = destinationCount - sourceString.characters.count,
padString = String(count: padCount, repeatedValue: paddingCharacter)
@JessyCatterwaul
JessyCatterwaul / FizzBuzz Golf.swift
Created October 7, 2015 15:18
Simple wins this round. forEach doesn't help with anything except obfuscation.
for 🔢 in 1...100{print([3:"Fi",5:"Bu"].reduce(nil){🔢%$1.0==0 ?$1.1+"zz"+($0 ?? ""):$0} ?? 🔢)} //93
for 🔢 in 1...100{print(🔢%15==0 ?"FizzBuzz":🔢%3==0 ?"Fizz":🔢%5==0 ?"Buzz":"\(🔢)")} //81
(1...100).forEach{print($0%15==0 ?"FizzBuzz":$0%3==0 ?"Fizz":$0%5==0 ?"Buzz":"\($0)")} //86
@JessyCatterwaul
JessyCatterwaul / Managed.swift
Created September 16, 2015 03:17
Strongly-typed Core Data ideas
import CoreData
/// Designed to add functionality to classes deriving from *NSManagedObject*
protocol Managed {}
// This keeps us from having to explicitly implement Managed
// on all NSManagedObject subclasses.
extension NSManagedObject: Managed {}
// Managed is extended instead of NSManagedObject,
@JessyCatterwaul
JessyCatterwaul / Cat.swift
Created August 31, 2015 02:06
Property initalizers in Swift
// It would help if Xcode visually differentiated between verbs and deverbal nouns.
// It can get a little confusing using a human brain to parse which of those options each meow is.
class Cat {
init(meow: String = "Meow.") {
// How this might look in Swift in the future.
// self.meow.init(meow: meow)
// How I have been emulating that
// Pronounce 🐣 as "hatch" to understand its purpose.
@JessyCatterwaul
JessyCatterwaul / UIControl+EventDispatcher.swift
Created August 8, 2015 04:47
The multiclosures get released before "event" returns; I need to figure out why, or another method to keep them around.
extension UIControl {
override public func didMoveToSuperview()
{
super.didMoveToSuperview()
alterControlEventsAssignment(addTarget)
}
override public func removeFromSuperview()
{
super.removeFromSuperview()
@JessyCatterwaul
JessyCatterwaul / gist:4143961df81216a7ddf6
Created December 1, 2014 16:09
Coroutine continue failure
using System.Collections;
using UnityEngine;
public class CoroutineContinueFailure: MonoBehaviour {
void Start() {
LogTimeCoroutine = StartCoroutine(LogTime());
}
Coroutine LogTimeCoroutine;