This file contains 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
int[][] result; | |
float t, c; | |
float ease(float p) { | |
return 3*p*p - 2*p*p*p; | |
} | |
float ease(float p, float g) { | |
if (p < 0.5) | |
return 0.5 * pow(2*p, g); |
This file contains 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
// trying to keep this Hashable simple while minimizing collisions: | |
struct Simple: Hashable { | |
enum MyEnum: Int { | |
case a,b,c,d | |
} | |
let enumValue: MyEnum | |
let someInt: Int |
This file contains 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
// i often do this just so i can make a variable a constant let and not a var; | |
// with a var I could just use a switch, but it's better to have a let when possible | |
// how to make this prettier? | |
let someConstant: Int64 = | |
someBoolExpression ? 1 : | |
someOtherBoolExpression ? 2 : | |
yetAnotherBoolExpression ? 3 : 0 | |
This file contains 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
var dict = [String: [String: Int]]() | |
if dict["foo"] == nil { | |
dict["foo"] = [:] | |
} | |
dict["foo"]?["bar"] = 5 // safe way to access dictionaries in general | |
dict["foo"]!["bar"] = 6 // we already tested for nil in the if statement, so force unwrap is safe, and maybe faster? |
This file contains 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
if (foo != nil && bar > foo!) || foo == nil { | |
// something | |
} | |
if let foo = foo, bar > foo || self.foo == nil { | |
// something | |
} |
This file contains 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
#if !DEBUG | |
public func print(_ items: Any..., separator: String = " ", terminator: String = "\n") { | |
//does nothing if not in debug build | |
} | |
#else | |
public func print(_ items: Any..., separator: String = " ", terminator: String = "\n") { | |
debugPrint(items) | |
} | |
#endif |
This file contains 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
(def init {:word "XIMEDES" | |
:attempts-left 10 | |
:state :playing | |
:guessed #{}}) | |
(def model (atom init)) | |
(defn show-won [] | |
[:div "Jeej you won!, share it with your friends!"]) |
This file contains 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
;; I think it would be a mistake to introduce temporal coupling to prevent typos. | |
;; The example program below lets you identify "missing" keys specs at | |
;; the time and place of your choosing, and then handle them as you | |
;; deem appropriate, without imposing those decisions on other | |
;; users of spec. | |
(require '[clojure.spec.alpha :as s] | |
'[clojure.set :as set]) |
This file contains 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
;; I think it would be a mistake to introduce temporal coupling to prevent typos. | |
;; The example program below lets you identify "missing" keys specs at | |
;; the time and place of your choosing, and then handle them as you | |
;; deem appropriate, without imposing those decisions on other | |
;; users of spec. | |
(require '[clojure.spec.alpha :as s] | |
'[clojure.set :as set]) |
This file contains 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
;; try this form-by-form at a REPL | |
(require '[clojure.spec.alpha :as s]) | |
;; create an inline DSL to describe the FizzBuzz world | |
(defmacro divides-by | |
[nm n] | |
`(s/def ~nm (s/and pos-int? #(zero? (mod % ~n))))) | |
;; specify FizzBuzz | |
(divides-by ::fizz 3) |