Skip to content

Instantly share code, notes, and snippets.

View thinkclay's full-sized avatar

Clay Unicorn thinkclay

View GitHub Profile
@IBAction func submitTapped(sender: AnyObject) {
validator.validateFieldByKey(Fields[0], delegate:self)
validator.validateFieldByKey(Fields[1], delegate:self)
}
// foo is automatically set to the `String` type
let foo = "Hello"
// Throws errors
let immutableString = "Clay is"
immutableString += " awesome"
// Works
var mutableString = "Clay is"
mutableString += " a big nerd"
// As an example, let's look at a reduction that creates a total sum
// of an array of Floats with a different approaches, all with the same outcome:
let total: [Float] -> Float = { $0.reduce(0, combine: +) }
let total = transactions.reduce(0, {$0 + $1})
// It's easy to swap out operators to make it a multiplication, division,
// or some other custom block execution.
// Here we want to know if an entire list of booleans is true:
protocol PrintStrategy
{
func printString(string: String) -> String
}
class CurrencyFactory
{
class func currencyForCountry(country:Country) -> Currency?
{
switch country
{
case .Spain, .France :
return Euro()
case .UnitedStates :
class SingletonClass
{
class var shared : SingletonClass
{
struct Static
{
static let instance : SingletonClass = SingletonClass()
}
​return Static.instance
class DepositsController < BaseController
include Manageable
end
@thinkclay
thinkclay / server.go
Last active September 2, 2024 03:48
Basic Encryption and Decryption with a Golang Web Server Application
package main
import (
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"fmt"
"io/ioutil"
"log"
"net/http"
@thinkclay
thinkclay / GameScene.swift
Created August 3, 2014 02:50
Jumping action
import SpriteKit
class GameScene: SKScene, SKPhysicsContactDelegate
{
// Our main scene. Everything is added to this for the playable game
var moving: SKNode!
// Our running man! Defaults to a stand still position
let heroAtlas = SKTextureAtlas(named: "hero.atlas")
var hero: SKSpriteNode!