Skip to content

Instantly share code, notes, and snippets.

View rickw's full-sized avatar

Rick Windham rickw

View GitHub Profile
@rickw
rickw / bumpme
Last active August 6, 2018 01:19
Mon Aug 6 01:19:07 UTC 2018

Keybase proof

I hereby claim:

  • I am rickw on github.
  • I am rcw (https://keybase.io/rcw) on keybase.
  • I have a public key whose fingerprint is ADA1 A75D B48A 86A8 4047 6D34 64C1 C602 D9CD 1760

To claim this, I am signing this object:

@rickw
rickw / StringScoreExtension.swift
Created July 7, 2015 20:01
StringScore in Swift - from the Objective-C then JavaScript repos of the same name
//
// StringScoreExtension.swift
//
//
// Created by Rick Windham on 6/23/15.
//
//
import Foundation
@rickw
rickw / ReachabilityExample.swift
Last active August 29, 2015 14:14
Reachability Callback Setup
import Foundation
import SystemConfiguration
var reach:SCNetworkReachability!
reach = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, "apple.com").takeRetainedValue()
typealias ChangeBlock = (UInt32) -> ()
let block:ChangeBlock = {status in
@rickw
rickw / xlog.swift
Last active June 25, 2017 11:30
Quick log to NSTextView in Swift
extension NSTextView {
func appendText(line: String) {
Async.main {
let attrDict = [NSFontAttributeName: NSFont.systemFontOfSize(18.0)]
let astring = NSAttributedString(string: "\(line)\n", attributes: attrDict)
self.textStorage?.appendAttributedString(astring)
let loc = self.string?.lengthOfBytesUsingEncoding(NSUTF8StringEncoding)
let range = NSRange(location: loc!, length: 0)
self.scrollRangeToVisible(range)
@rickw
rickw / Fibber.swift
Last active November 10, 2017 17:22
Fibonacci sequence in Swift
func fibber(n:Int) -> Int {
switch n {
case 0:
return 0
case 1:
return 1
default:
return fibber(n-1) + fibber(n-2)
}
}
@rickw
rickw / gist:110596
Created May 12, 2009 17:00
a weighted random method
#
# a weighted random
#
the_list = { "five" => 5, "three" => 3, "one" => 1 }
result_hash = { "five" => 0, "three" => 0, "one" => 0 }
count = 3
def weighted_random(list, count)
weighted_list = []
@rickw
rickw / gist:110522
Created May 12, 2009 14:48
A different way to "try"
#
# method messing try a different way
#
class Object
def try
Try.new self
end
end
class Try