Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Champine mchampine

View GitHub Profile
View gist:dca965226148dfd19d5e4d7f3d4600c5
(defn score
"Return a tuple representing the best score that can be made from the hand."
[hand]
(let [isflush (apply = (map second hand))
ranks (map first hand)
rsranks (reverse (pk-ranksort ranks))
fq (frequencies ranks)
keyswith (partial getkeyswithval fq)
fs (sort (vals fq))
match-ranks? #(= (set ranks) (set %))
@mchampine
mchampine / gist:f6e88b97dd76617d1f4ac8db38e43bed
Last active Jan 2, 2019
Beginners SQL translated to DataScript
View gist:f6e88b97dd76617d1f4ac8db38e43bed
(ns trydatahike.beginnersql
(:require [datahike.api :as d :refer :all :exclude [filter]]
[clojure.string :as string]))
;; DUMP or RESTORE
;;(require '[datahike.migrate :refer [export-db import-db]])
;;(export-db @bookconn "src/trydatahike/begsqldump.edn")
;;(import-db new-conn "src/trydatahike/begsqldump.edn")
;; SQL example translated to DataScript
View gist:dd3b875994bb68f219123dec2e601280
<pre><code class="language-klipse">
(def default-config
{:chart {:zoomType :xy
:type :scatter}
:legend {:layout :vertical
:align :left
:verticalAlign :top
:x 100
:y 70
:floating :true
View ufo.clj
(ns ufo.core
(:use (incanter core stats charts datasets))
(require [clojure.data.json :as json]
[clj-time.format :as tf]
[net.cgrand.enlive-html :as html]
[clojure.string :as string]))
;; URL with one month of data (january, 2015)
(def ufourl "http://www.nuforc.org/webreports/ndxe201501.html")
@mchampine
mchampine / pwprot.clj
Created Mar 13, 2011
Strong password hasher/verifier for Clojure - incorporating salt and iterations
View pwprot.clj
(ns pwprot
(:import (java.security MessageDigest Security)))
;;generate n random chars
(defn gensalt [n]
(let [charseq (map char (concat
(range 48 58) ; 0-9
(range 97 123)))] ; 0-z
(apply str
(take n
You can’t perform that action at this time.