Skip to content

Instantly share code, notes, and snippets.

View mchampine's full-sized avatar

Mark Champine mchampine

View GitHub Profile
(ns mlstudy.linalgbook
(:require [uncomplicate.neanderthal.linalg :as linalg]
[tech.viz.vega :as vega])
(:use [uncomplicate.neanderthal core native vect-math]
[clojure.repl]))
;;; See also
;; https://dragan.rocks/articles/21/Hello-World-Programming-with-Linear-Algebra
;; Based on Gareth Williams 9th Edition - Linear Algebra with Applications 2017
@mchampine
mchampine / gist:dca965226148dfd19d5e4d7f3d4600c5
Created July 6, 2020 05:31
Poker Hand Scoring in Clojure
(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 January 2, 2019 18:15
Beginners SQL translated to DataScript
(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
<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
(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 March 13, 2011 19:13
Strong password hasher/verifier for Clojure - incorporating salt and iterations
(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