Skip to content

Instantly share code, notes, and snippets.

View thomas-shares's full-sized avatar
🏠
Working from home

Thomas thomas-shares

🏠
Working from home
View GitHub Profile
@thomas-shares
thomas-shares / gist:048fdb2eabac62844074
Last active August 29, 2015 14:24
How many ways are there to say "morning" in Clojure?
(->> ((->> [0 2 5 1 -4 1 -6] (map #(partial + %)) (apply juxt)) 109) byte-array (String.))`
morning
(loop [txt ""] (if (= 1803412773 (hash txt)) txt (recur (apply str (repeatedly 7 (fn [] (char (rand-nth [114 105 110 111 109 103]))))))))
(->> "bW9ybmluZw=="
.getBytes
(.decode (java.util.Base64/getDecoder))
(new String))
@thomas-shares
thomas-shares / gist:8a7bb265198f2b735daa
Created May 26, 2015 20:35
Rules engine. ThoughtWorks Clojure DOJO
(ns twrule.core)
;; A is the B
;; fact: '(father a b )
(def facts #{'(father andrew bob) '(father bob charlie)})
;; Grandfather rule: if A is the father of B, and B is the father of C then A is the Grandfather C
(def rules [{:patterns ['(father ?a ?b) '(father ?b ?C)]
:assertions ['(grandfather ?a ?C)]}])
@thomas-shares
thomas-shares / gist:62f9bb2a2fa67ec5b517
Last active August 29, 2015 14:20
trying to set up a OSM map with a marker
;; The problem is that the text in :element of over-lay gets interpreted as text, not really
;; surprising at the moment as it is text, but I don't know what to do with it so that it
;; works like in the example: http://artarmstrong.com/blog/2014/10/28/openlayers-3-custom-markers-by-latitude-longitude/
(ns clojurescript-apis.core
(:require-macros [hiccups.core :as h]
[cljs.core.async.macros :as m :refer [go alt!]])
(:require [clojure.browser.repl :as repl]
[domina :as dom]
[hiccups.runtime :as hiccupsrt]
@thomas-shares
thomas-shares / gist:3277803
Created August 6, 2012 19:29
FizzBuzz, but functional
(def three (cycle [nil nil "fizz"]))
(def five (cycle [nil nil nil nil "buzz"]))
(map vector (range 1 16) three five )
;([1 nil nil] [2 nil nil] [3 "fizz" nil] [4 nil nil] [5 nil "buzz"] [6 "fizz" nil] [7 nil nil] [8 nil nil] [9 "fizz" nil] [10 nil "buzz"] [11 nil nil] [12 "fizz" nil] [13 nil nil] [14 nil nil] [15 "fizz" "buzz"])
@thomas-shares
thomas-shares / permutations.clj
Created April 11, 2012 08:29
Permutations and same start/end
(ns diversen.permutations)
(use 'clojure.math.combinatorics)
(def things '[:a :b :c])
(map #(conj % (last %) ) (permutations things))
;; ((:c :a :b :c) (:b :a :c :b) (:c :b :a :c) (:a :b :c :a) (:b :c :a :b) (:a :c :b :a))