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
require 'nokogiri' | |
require 'net/http' | |
require 'dm-core' | |
class Prediction | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :snapshot | |
property :minutes, Integer | |
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
(defn compare-tuples [tuple-1 tuple-2] | |
(or (first (remove zero? (map compare tuple-1 tuple-2))) 0)) | |
(defn get-values-at [record keys] | |
(map #(get record %) keys)) | |
(defn sort-by-keys [keys to-sort] | |
(sort-by #(get-values-at % keys) compare-tuples to-sort)) | |
(def people [ |
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
(defn sort-by-lambdas [lambdas to-sort] | |
(sort-by | |
#(mapv (fn [lambda] (lambda %)) lambdas) | |
to-sort)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;test | |
(describe "sorting" | |
(it "sorts by lowercased name" | |
(let [people [{:name "aaa"} {:name "BBB"}]] |
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 gapsize(biggersize, smallersize) | |
num_gaps = smallersize + 1 | |
total_of_all_gaps = biggersize - smallersize | |
total_of_all_gaps / num_gaps | |
end | |
def gap_sequence(bigger_list, smaller_list) |
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 kill-spaces #(clojure.string/replace % " " "")) | |
(-> "a b c" kill-spaces) | |
;"abc" | |
(-> "a b c" #(clojure.string/replace % " " "")) | |
;kaboom!!!!! |
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 wat(): | |
z=1 | |
def inner(x): | |
return (z + x) | |
return inner | |
z=55 | |
print wat()(5) |
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
(defmacro make-it [name args defaults & exprs] | |
`(defn ~name | |
(~args | |
(~name ~@(concat args (vals defaults))) | |
) | |
(~(vec (concat args (keys defaults))) | |
~@exprs))) | |
(prn (macroexpand-1 '(make-it bar [a b] {c +} (prn "HI") (c a b)))) |
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
(defmacro def-defaults [name args defaults & exprs] | |
`(defn ~name [~@args & {:keys ~(vec (keys defaults)) :or ~defaults}] | |
~@exprs)) | |
(def-defaults use-the-operator [a b] {operator +} (operator a b)) | |
(prn "--------------------------") | |
(prn (use-the-operator 1 2)) ; --> 3 | |
(prn (use-the-operator 1 2 :operator *)) ; --> 2 | |
(prn "--------------------------") |
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 LinkedList | |
class Node | |
attr_accessor :value, :next_node | |
def initialize(value, next_node = nil) | |
@value = value | |
@next_node = next_node | |
end | |
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
require 'json' | |
class SmartphoneSpy | |
def do_spying | |
recorded_activities = {bus_trip: 5.5, ate_meal: "chicken"} | |
message_to_send = recorded_activities.to_json | |
send_via_internet_to_HQ(message_to_send) | |
end | |
def send_via_internet_to_HQ(message_to_send) |