Skip to content

Instantly share code, notes, and snippets.

@msszczep
msszczep / gist:11266360
Created Apr 24, 2014
Reconnection in Langohr
View gist:11266360
;;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
@msszczep
msszczep / gist:12168573f29159e86dfc
Created Jul 22, 2014
Build an evaluator in Clojure (Lambda Jam 2014)
View gist:12168573f29159e86dfc
; 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" +})
@msszczep
msszczep / scramboni.clj
Last active Apr 1, 2018
Scramboni in Clojure
View scramboni.clj
(defn scramboni [rack]
"Find all playable words in a given Scrabble rack. Use asterisks for blanks."
(letfn [(every-but-n? [n pred coll]
(->> coll
(map (comp (fn [x] (if x :true :false)) pred))
frequencies
(merge {:false 0})
:false
(>= n)))]
(let [scrabble-words (->> "/home/mitchells/Desktop/npr_sunday_puzzle_solutions/resources/ospd3.txt"
@msszczep
msszczep / gist:a436e25601a6a031f5e1
Created Dec 8, 2014
Clojure Bridge exercise: Caesar Cipher
View gist:a436e25601a6a031f5e1
(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))))
@msszczep
msszczep / gist:b20b847a7e8ddc6fbad4
Created Dec 10, 2014
Proposed Clojure Bridge Exercise: Caesar cipher
View gist:b20b847a7e8ddc6fbad4
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"
@msszczep
msszczep / gist:4b5409d5a256a0717585
Created Mar 20, 2015
Clojure exercise: Sentiment Scoring for Words
View gist:4b5409d5a256a0717585
(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
(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
(let [d ["Project #1"
"Project #2"
"Project #3"
"Project #4"
"Project #5"
"Project #6"]]
(rand-nth d))
@msszczep
msszczep / gist:d572f265e8318ccddbcd
Last active Aug 29, 2015
Clojure rewrite of Scrabble surnames' scorer
View gist:d572f265e8318ccddbcd
; 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)
@msszczep
msszczep / gist:52fe8c2ab63065793dca
Last active Apr 22, 2016
Wikipedia Wordcloud in Wolfram
View gist:52fe8c2ab63065793dca
CloudDeploy[FormFunction[{"article" -> "String"},Show[WordCloud[DeleteStopwords[WikipediaData[#article]], ImageSize -> Large]] &,
"GIF", AppearanceRules -> <|"Title" -> "Wikipedia Wordcloud", "Description" -> "Type in the name of a Wikipedia article
and get a word cloud of the article."|>, FormTheme -> "Blue" ], Permissions->"Public"]
https://www.wolframcloud.com/objects/f7615524-b20b-4427-b4fa-ac4dec8dd651