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
<html> | |
<head> | |
<script type="text/javascript" src="https://rawgit.com/bjwbell/canvas-geolib/master/geometry.js"></script> | |
<script type="text/javascript" src="utilities.js"></script> | |
<script type="text/javascript"> | |
var healthyShip = function() {return document.getElementById('ship');} | |
var explosion = function() {return document.getElementById('explosion');} | |
var astronaut = function() {return document.getElementById('astronaut');} | |
var getShipImage = function() { |
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
class MockWriter(object): | |
def write_file(self, path, contents): | |
print "ooh look at me, i'm a file writer" | |
print "i perform slow operations and sometimes i fail for no good reason" | |
print "you only use me when you don't have a Real Database to talk to" | |
print "I'm so cool! not!" | |
return 0 |
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
-- pipelining | |
let x = 1 | |
doubled = x * 2 | |
squared = doubled * doubled | |
decremented = squared - 1 | |
in decremented | |
-- composition | |
let x = 1 |
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
(def x (atom 1)) | |
(defmacro foo [] | |
(let [times @x | |
prints (map (fn [_] `(println "hello world")) (range times))] | |
`(do ~@prints))) | |
(defn foo-caller [] (foo)) | |
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
class Foo | |
def yes | |
puts "BORING" | |
end | |
end | |
class Bar | |
def self.go(x) | |
puts x.yes | |
end |
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
module Main where | |
import qualified Data.Text as T | |
import qualified Network.WebSockets as WS | |
import qualified Control.Concurrent as C | |
import qualified Control.Monad as M | |
main :: IO () | |
main = do |
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
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import Data.Text (Text) | |
import qualified Data.Text.IO as T | |
import qualified Network.WebSockets as WS | |
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
user=> (def increment-a-list (map inc)) | |
#'user/increment-a-list | |
;I have partially-applied "map". It didn't blow up with an arity error. Success! | |
;Let's use it | |
user=> (increment-a-list [1,2,3]) | |
#object[clojure.core$map$fn__4549$fn__4550 0x7ebed7f2 "clojure.core$map$fn__4549$fn__4550@7ebed7f2"] | |
;not helpful. it looks like I called a function. What did I call? |
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
user=> (def zing (map (fn [x] (if (= x 100) (/ 1 0) x)) (range 1000))) | |
#'user/zing | |
user=> (first zing) | |
0 | |
user=> (nth zing 5) | |
5 | |
user=> (nth zing 999) | |
ArithmeticException Divide by zero clojure.lang.Numbers.divide (Numbers.java:156) |
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
-- inspired by | |
-- http://stackoverflow.com/a/23660388/1096146 | |
--nestedMap f elements = map (\inner -> map f inner) elements | |
--nestedMap f elements = map (map f) elements | |
--nestedMap f = map (map f) | |
--nestedMap f = (map . map) f | |
--nestedMap = (map . map) | |
nestedMap = map . map |