This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns drum-machine.core | |
| (:require [om.core :as om :include-macros true] | |
| [sablono.core :as html :refer-macros [html]])) | |
| (enable-console-print!) | |
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; UI | |
| (def tau 6.2831853071) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env xcrun swift | |
| // http://learnyouahaskell.com/functionally-solving-problems | |
| enum Label : String { case A = "A", B = "B", C = "C" } | |
| typealias Section = (Int, Int, Int) | |
| typealias RoadSystem = [Section] | |
| typealias Path = [(name:Label, price:Int)] | |
| // Helpers, A little bit of F# in my life | |
| infix operator |> { associativity left } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func unwrap<T1, T2>(optional1: T1?, optional2: T2?) -> (T1, T2)? { | |
| switch (optional1, optional2) { | |
| case let (.Some(value1), .Some(value2)): | |
| return (value1, value2) | |
| default: | |
| return nil | |
| } | |
| } | |
| func unwrap<T1, T2, T3>(optional1: T1?, optional2: T2?, optional3: T3?) -> (T1, T2, T3)? { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void -[UIPopoverPresentationController dimmingViewWasTapped:](void * self, void * _cmd, void * arg2) { | |
| esi = self; | |
| edi = @selector(delegate); | |
| if ([esi delegate] != 0x0) { | |
| eax = [esi delegate]; | |
| var_10 = @selector(popoverPresentationControllerShouldDismissPopover:); | |
| eax = [eax respondsToSelector:@selector(popoverPresentationControllerShouldDismissPopover:)]; | |
| if (LOBYTE(eax) != 0x0) { | |
| eax = [esi presented]; | |
| if (LOBYTE(eax) != 0x0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| class Box<T> { | |
| let unbox: T | |
| init(_ value: T) { self.unbox = value } | |
| } | |
| struct Notification<A> { | |
| let name: String | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // CalculatorView.swift | |
| // as seen in http://nshipster.com/ibinspectable-ibdesignable/ | |
| // | |
| // (c) 2015 Nate Cook, licensed under the MIT license | |
| /// The alignment for drawing an String inside a bounding rectangle. | |
| enum NCStringAlignment { | |
| case LeftTop | |
| case CenterTop | |
| case RightTop |
There are three easy to make mistakes in go. I present them here in the way they are often found in the wild, not in the way that is easiest to understand.
All three of these mistakes have been made in Kubernetes code, getting past code review at least once each that I know of.
- Loop variables are scoped outside the loop.
What do these lines do? Make predictions and then scroll down.
func print(pi *int) { fmt.Println(*pi) }
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // NSScanner+Swift.swift | |
| // A set of Swift-idiomatic methods for NSScanner | |
| // | |
| // (c) 2015 Nate Cook, licensed under the MIT license | |
| import Foundation | |
| extension NSScanner { | |
| // MARK: Strings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // NSCalendar+Swift.swift | |
| // A set of Swift-idiomatic methods for NSCalendar | |
| // | |
| // (c) 2015 Nate Cook, licensed under the MIT license | |
| extension NSCalendar { | |
| /// Returns the hour, minute, second, and nanoseconds of a given date. | |
| func getTimeFromDate(date: NSDate) -> (hour: Int, minute: Int, second: Int, nanosecond: Int) { | |
| var (hour, minute, second, nanosecond) = (0, 0, 0, 0) | |
| getHour(&hour, minute: &minute, second: &second, nanosecond: &nanosecond, fromDate: date) |