Skip to content

Instantly share code, notes, and snippets.

View msszczep's full-sized avatar

Mitchell Szczepanczyk msszczep

View GitHub Profile
@msszczep
msszczep / gist:fadb318cadb286ffffbc
Last active November 4, 2015 07:36
Instant average
(defn instant-avg [nums]
[(apply + nums)
(/ (float (apply + nums)) (count nums))
(count nums)])
;; assumes nums is a vector of integers
@msszczep
msszczep / gist:7f713a7bbdd75220313e
Created December 12, 2015 17:23
Coffee in Java and Clojure
// 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:
@msszczep
msszczep / gist:08dda9b2f4e1cdad2c00
Last active January 6, 2018 07:01
Subanagram Generator Draft in Clojure
(defn subanagram-generator [submitted-word]
(let [words (->> (slurp "/Users/msszczep1/Scripts/npr_puzzle_scripts/ni2.txt")
(clojure.string/split-lines))
submitted-word-freqs (merge
(zipmap "abcdefghijklmnopqrstuvwxyz" (repeat 26 0))
(frequencies (clojure.string/lower-case submitted-word)))]
(->> words
(filter (fn [word]
(let [lc-word (clojure.string/lower-case word)]
(every? #(<= ((frequencies lc-word) %)
@msszczep
msszczep / gist:5d15b2ad8efa4faebdca
Created February 20, 2016 02:27
What are the most frequently used letters in English?
(->> (slurp "ni2.txt")
clojure.string/split-lines
(map clojure.string/lower-case)
(map #(map char %))
flatten
frequencies
(map #(vector (key %)
(read-string
(format "%.2f" (* 100 (/ (val %) 2251877.0))))))
(sort-by last)
@msszczep
msszczep / gist:f327c2f46d1503361a1b
Created March 10, 2016 03:38
Two hard problems
for (i=0; i< 2; i++) {
if (i == 0) {printf "naming";}
if (i == 1) {invalidate_cache;}
if (i == 2) {printf "off by 1 error";}
}
@msszczep
msszczep / jfile.html
Created March 28, 2016 18:09
Map of Jeopardy! airtimes across USA
<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {'packages': ['geochart']});
google.setOnLoadCallback(drawMarkersMap);
function drawMarkersMap() {
var data = google.visualization.arrayToDataTable([
['City', 'Time', 'Size'],
#!/usr/bin/python
# Source: http://ubuntuforums.org/showthread.php?t=1215158
import urllib2
import sys
from BeautifulSoup import BeautifulSoup
file = sys.argv[1]
# assumes file is a list of valid URLs, one URL per line
@msszczep
msszczep / gist:5b55a9f87e8941d58a63e27a1a613e5b
Last active May 7, 2016 13:24
Dead or Not Dead (in Wolfram Language)
CloudDeploy[APIFunction[{"p" -> "String"}, DateString[Interpreter["Person"][#p]["DeathDate"], {"MonthName", " ", "DayShort", ", ", "Year"}] &]]
-- e.g., https://www.wolframcloud.com/objects/29dd4c7b-77f3-49ff-84be-fc557ddfc9a0?p=Michael+Jackson
-- https://www.wolframcloud.com/objects/fa2cf38e-b000-4762-b249-8d19bfaef1a0?p=Doris+Day
CloudDeploy[APIFunction[{"p" -> "String"}, Which[
FailureQ[Interpreter["Person"][#p]],
"I'm sorry, but I cannot determine that.",
MissingQ[Interpreter["Person"][#p]["DeathDate"]],
StringJoin[#p, " is still alive, and is ", ToString[Floor[DateDifference[Interpreter["Person"][#p]["BirthDate"], Now, "Year"]]], " old." ],
@msszczep
msszczep / gist:710dafcd2d0119e934759a71fd6f1af1
Created May 4, 2016 04:18
Wolfram Language: NYTimes Noun Wordcloud
CloudDeploy[WordCloud[Flatten[TextCases[StringCases[URLFetch["www.nytimes.com"], Shortest["<p class=\"summary\" ~~ x__ ~~ "</p>"] -> x], "Noun"]]]]
https://www.wolframcloud.com/objects/aad30d4c-cce8-45c2-b0c3-afa03f606f64
@msszczep
msszczep / gist:daff445a6d7107d31933a72c7e21a2f6
Created May 26, 2016 00:19
Notes From React/Trivia Meetup (May 25, 2016)
Round {question: {}, responses: []} // initial state
Actions Actions {answerQuestion(choice) advanceQuestion()}
Redux Act