View gist:11266360
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
;;adapted from http://clojurerabbitmq.info/articles/error_handling.html | |
(ns killwabbit.core | |
(:gen-class) | |
(:require [langohr.core :as rmq] | |
[langohr.channel :as lch] | |
[langohr.queue :as lq] | |
[langohr.exchange :as lx] | |
[langohr.consumers :as lc] | |
[langohr.basic :as lb]) | |
(:import java.io.IOException |
View gist:12168573f29159e86dfc
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
; variable evaluation: find and substitute | |
; look for Var X in B and substitute a | |
; environment, symbol | |
(def MyEnv {"One" 1 | |
"Two" 2 | |
"Three" 3 | |
"MyAdd" +}) | |
View gist:a436e25601a6a031f5e1
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 mystring "my name is stephanie") | |
(def alphabet "abcdefghijklmnopqrstuvwxyz") | |
(def alphabet-chars (map char alphabet)) | |
alphabet-chars | |
(def alphabet-shifted (drop 5 (take 100 (cycle alphabet-chars)))) |
View gist:b20b847a7e8ddc6fbad4
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
A Caesar cipher is a very simple kind of encoding of alphabetic text (like English) | |
in which each letter in the text is replaced by another letter some fixed number of | |
positions down the alphabet. For example, the string | |
"hello" | |
can be replaced by a Caesar cipher one letter down the alphabet to the following: | |
"ifmmp" |
View gist:4b5409d5a256a0717585
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
(defn sentiment-scorer [& maps] | |
(letfn [(sentiment-scorer-intermediate [m] | |
(let [words (-> (:c m) | |
(clojure.string/lower-case) | |
(clojure.string/replace #"[\.\!\@]" "") | |
(clojure.string/split #"\s+")) | |
rs (repeat (count words) [(:r m)])] | |
(apply hash-map (interleave words rs))))] | |
(let [intermediate-map (->> (apply map sentiment-scorer-intermediate maps) | |
(apply merge-with concat))] |
View gist:fdcd541c03314b574100
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
(let [d {1 "Project #1" | |
2 "Project #2" | |
3 "Project #3" | |
4 "Project #4" | |
5 "Project #5" | |
6 "Project #6"}] | |
(d (-> (rand-int 6) | |
inc))) |
View gist:f79adaa77128a51fa5fc
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
(let [d ["Project #1" | |
"Project #2" | |
"Project #3" | |
"Project #4" | |
"Project #5" | |
"Project #6"]] | |
(rand-nth d)) |
View gist:d572f265e8318ccddbcd
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
; See http://www.szcz.org/blog/?cat=33 for context | |
(let [surnames (->> (slurp "/Users/msszczep1/current_2011-01-2.txt") | |
(clojure.string/split-lines) | |
distinct) | |
points {\A 1 \B 3 \C 3 \D 2 \E 1 \F 4 \G 2 \H 4 \I 1 \J 8 \K 5 \L 1 \M 3 | |
\N 1 \O 1 \P 3 \Q 10 \R 1 \S 1 \T 1 \U 1 \V 4 \W 4 \X 8 \Y 4 \Z 10 \- 0 \' 0} | |
scores (map #(reduce + (map points (seq %))) surnames)] | |
(->> (zipmap surnames scores) | |
(sort-by val) |
View gist:fadb318cadb286ffffbc
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
(defn instant-avg [nums] | |
[(apply + nums) | |
(/ (float (apply + nums)) (count nums)) | |
(count nums)]) | |
;; assumes nums is a vector of integers |
View gist:7f713a7bbdd75220313e
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
// https://www.facebook.com/WondersofEngineering/photos/a.255298751271223.61509.255293124605119/701667366634357/?type=3&theater | |
Coffee coffee = new Coffee(); | |
if (coffee.Empty) { | |
coffee.Refill(); | |
} else { | |
coffee.Drink(); | |
} | |
;; I can rewrite it in Clojure in two lines: |
OlderNewer