Skip to content

Instantly share code, notes, and snippets.

View msszczep's full-sized avatar

Mitchell Szczepanczyk msszczep

View GitHub Profile
@msszczep
msszczep / gist:11266360
Created April 24, 2014 19:22
Reconnection in Langohr
;;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 July 22, 2014 20:38
Build an evaluator in Clojure (Lambda Jam 2014)
; 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 April 1, 2018 04:06
Scramboni in Clojure
(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 December 8, 2014 00:22
Clojure Bridge exercise: Caesar Cipher
(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 December 10, 2014 14:25
Proposed Clojure Bridge Exercise: Caesar cipher
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 March 20, 2015 19:09
Clojure exercise: Sentiment Scoring for Words
(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))]
(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)))
(let [d ["Project #1"
"Project #2"
"Project #3"
"Project #4"
"Project #5"
"Project #6"]]
(rand-nth d))
@msszczep
msszczep / gist:d572f265e8318ccddbcd
Last active August 29, 2015 14:19
Clojure rewrite of Scrabble surnames' scorer
; 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 April 22, 2016 01:31
Wikipedia Wordcloud in Wolfram
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