Skip to content

Instantly share code, notes, and snippets.

View thinkclay's full-sized avatar

Clay Unicorn thinkclay

View GitHub Profile
// 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:
// Throws errors
let immutableString = "Clay is"
immutableString += " awesome"
// Works
var mutableString = "Clay is"
mutableString += " a big nerd"
// foo is automatically set to the `String` type
let foo = "Hello"
@IBAction func submitTapped(sender: AnyObject) {
validator.validateFieldByKey(Fields[0], delegate:self)
validator.validateFieldByKey(Fields[1], delegate:self)
}
@thinkclay
thinkclay / Keychain.swift
Last active August 30, 2016 12:13
Dead simple keychain access
import Security
public class Keychain
{
public class func set(key: String, value: String) -> Bool
{
if let data = value.dataUsingEncoding(NSUTF8StringEncoding)
{
return set(key, value: data)
}
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var buttonWithBorderLeft: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

Keybase proof

I hereby claim:

  • I am thinkclay on github.
  • I am unicorn (https://keybase.io/unicorn) on keybase.
  • I have a public key whose fingerprint is EAE4 4A12 A705 9427 1413 2E74 0F75 CB27 7787 5FA5

To claim this, I am signing this object:

@thinkclay
thinkclay / NoAutocompleteInput.jsx
Created December 26, 2016 23:06
This react input gets rid of form autocomplete with some little hacks
const Input = (props) => {
const onFocus = (e) => {
let input = e.target
if (input.hasAttribute('readonly'))
{
input.removeAttribute('readonly')
input.blur()
input.focus()
}

Keybase proof

I hereby claim:

  • I am thinkclay on github.
  • I am thinkclay (https://keybase.io/thinkclay) on keybase.
  • I have a public key ASC7hdnNRAeJLwErhAM6aCSlVsQ6hVO-GGH4s8pK0Kohcgo

To claim this, I am signing this object:

@thinkclay
thinkclay / mailer_injection.rb
Last active April 26, 2017 10:24
Rails Mailer Injection
# config/initializers/mailer_injection.rb
# This allows `request` to be accessed from ActionMailer Previews
# And @request to be accessed from rendered view templates
# Easy to inject any other variables like current_user here as well
module MailerInjection
def inject(hash)
hash.keys.each do |key|
define_method key.to_sym do