Skip to content

Instantly share code, notes, and snippets.

View devth's full-sized avatar
Deep Work

Trevor Hartman devth

Deep Work
View GitHub Profile
(def m {:from #<IMAPAddress [email protected]>,
:subject "Re: A friendly message",
:sender #<IMAPAddress foo.com>,
:multipart? true,
:content-type "multipart/ALTERNATIVE; boundary=bcaec5524106840d9e04d4ee1246",
:body [{"TEXT/PLAIN; charset=ISO-8859-1" "Lol.\r\n\r\n\r\nOn"} {"TEXT/HTML; charset=ISO-8859-1" "<div dir=\"ltr\">Lol.</div>"}]})
(defn- plain-key [m] (first (filter #(re-find #"TEXT/PLAIN" %) (keys m))))
(defn- plain-body [m] (let [body (first (:body m))]
(body (plain-key body))))
@devth
devth / matches.clj
Last active December 15, 2015 07:39
(ns user)
(def matches?
(let [match-map {\{ \}
\[ \]
\( \)}
open-set (set (keys match-map))
close-set (set (vals match-map))]
(fn [input]
(try
object BT {
case class BNode(v: Int, l: Option[BNode], r: Option[BNode])
val bt = BNode(5,
Some(BNode(4, Some(BNode(3, None, None)), None)),
Some(BNode(10, None,
Some(BNode(15, None, None)))))
def bt2Sorted(bt: BNode, l: List[Int] = List[Int]()): List[Int] = {
bt match {
@devth
devth / change.hs
Last active December 18, 2015 19:29
Given an amount of money (in cents), determine all the ways to make change given a list of denominations.
change :: Int -> [Int] -> [[Int]]
change amt [] = [[]]
change amt [d] = [replicate (quot amt d) d]
change amt (d:denoms) =
if d <= amt then
reverse [0..(quot amt d)] >>= \x ->
[(replicate x d) ++ c | c <- (change (amt - (x*d)) denoms)]
else
change amt denoms
-- find the elements of two 3-element sets whose cartesian products, when multiplied
-- form a 5-element set
setMembers = head [[a, b, c, d, e, f] | a <- [1..10], b <- [2..14], c <- [4..20], d <- [6..24],
e <- [7..25], f <- [6..30],
length [a, b, c, d, e, f] == length (nub [a, b, c, d, e, f]),
length (nub [x*y | x <- [a, b, c], y <- [d, e, f]]) == 5]
Caused by: clojure.lang.ExceptionInfo: :peer/timeout Transaction timed out. {:db/error :peer/timeout}
at clojure.core$ex_info.invoke(core.clj:4227)
at datomic.error$raise.invoke(error.clj:24)
at datomic.error$raise.invoke(error.clj:20)
at datomic.peer$await_tx_result.invoke(peer.clj:75)
at datomic.peer.Connection.transact(peer.clj:125)
at datomic.api$transact.invoke(api.clj:64)
at datomico.db$transact.invoke(db.clj:55)
at datomico.db$transact_BANG_.invoke(db.clj:61)
at datomico.db$load_schemas.invoke(db.clj:67)
@devth
devth / weird.scala
Last active December 19, 2015 20:48
"abc/xyz.lol" split("/").reduceLeft((a, b) => b) // => Array[String] = Array(abc, xyz.lol)
"abc/xyz.lol" split("/") reduceLeft((a, b) => b) // => String = xyz.lol
"abc/xyz.lol".split("/").reduceLeft((a, b) => b) // => String = xyz.lol
// Why does the first line result in the full Array?
(def bal
(insta/parser
"expr = group
<cmd> = word (space word)*
sub-expr = <dollar> <lparen> group <rparen>
<group> = lparen cmd rparen | cmd
<word> = sub-expr | group | #'[^ ()]*'
space = <' '>+
<dollar> = '$'
<lparen> = '('
@devth
devth / sunset
Created September 23, 2013 18:25
trevorhartman at host-174-45-234-173 in ~/work/sunset on master!
± ./deploy.sh
DEPLOY SUNSET
|
\ / _\/_
.-'-. //o\ _\/_
-- / \ -- | /o\
~^~^~^~^~^~^~^~^~^~^-=======-~^~^~^~~^~^~^~|~~^~^|^~
THANKS FOR ALL THE FISH |
#include <TinkerKit.h>
TKMosFet mos(O0);
// TKPotentiometer pot(I0);
int val = 10;
void setup() {
}