Skip to content

Instantly share code, notes, and snippets.

View lukeredpath's full-sized avatar
🏠
Working from home

Luke Redpath lukeredpath

🏠
Working from home
View GitHub Profile
@lukeredpath
lukeredpath / FizzBuzz.rb
Last active June 13, 2018 11:30
FizzBuzz with mocks
# Given a range as input, reports fizz, buzz or fizzbuz.
#
# FizzBuzz logic is separated from presentation logic which is a concern for the reporter.
#
class FizzBuzz
def generate(range, reporter)
range.each do |n|
if n % 3 == 0 && n % 5 == 0
reporter.report(:fizzbuzz)
elsif n % 3 == 0
@lukeredpath
lukeredpath / gist:0293dce075c6958f83df2a37c93a53ea
Created June 4, 2018 19:16
Apple WWDC 2018 Keynote notes
WWDC Keynote 2018 Notes
Introduction
* App Store 10 years old this year
* Big push into the education space
* Everyone should learn to code
* All about software today (no hardware?)
iOS 12
* Lots of stuff about how quickly iOS is adopted
@lukeredpath
lukeredpath / morse.swift
Created January 23, 2018 17:24
Find possible values for an ambiguous morse code word
enum Signal: String {
case dot = "."
case dash = "-"
case unknown = "?"
static func parseSignals(from string: String) -> [Signal] {
return string.flatMap() { char in
return Signal(rawValue: String(char))
}
}
// becomes...
NotificationCenter.default.addObserver(forName: .SomethingDidHappen, ...)
master
|
|----feature1
| |
| |----task1
| |
| |----task2
|
|----feature2
@lukeredpath
lukeredpath / typealias.swift
Last active June 28, 2017 18:45
Swift typealias problem
protocol SomeProtocol {
typealias SomeType = String
}
class SomeClass: SomeProtocol {
let something: SomeType
}
// Compiles in Swift 3.1
// Compile error in Swift 3.0.2: "Use of undeclared type SomeType"
@lukeredpath
lukeredpath / interpolate.rb
Created June 20, 2017 12:22
Ruby interpolate array value
class Array
def interpolate(value)
map { |el| [el, value] }.flatten
end
end
[1, 3, 5, 6].interpolate(9) #=> [1, 9, 3, 9, 5, 9, 6, 9]
let collection: Array<Int> = [1, 2, 3]
let optionalCollection: Array<Int>? = .None
expect(optionalCollection).to(equal(collection)) # fail: expected [1,2,3], got <nil>
@lukeredpath
lukeredpath / Result.swift
Created January 12, 2017 15:46
Swift result type
enum Result<T, ErrorType> {
case success(T)
case error(ErrorType)
}
enum MyError: ErrorType {
case itFuckedUp
}
// no longer need unused parameters in completion blocks:
@lukeredpath
lukeredpath / no_roles.rb
Created June 3, 2016 15:46
Defining Pundit policies without delegating to roles
class User
def roles
[:manager, :staff]
end
def has_role?(role)
roles.include?(role)
end
end