Skip to content

Instantly share code, notes, and snippets.

@ampersanda
ampersanda / read_password_cli.clj
Created October 28, 2019 23:33
CLI - read password
;; password input is visible when use run
;; but it's invincible if it's executed using java -jar target/your-uberjar-standalone.jar
(defn read-password [prompt]
;; Based on https://groups.google.com/forum/#!topic/clojure/ymDZj7T35x4
(if (= "user" (str (.getName *ns*)))
(do
(print (format "%s [will be echoed to the screen]" prompt))
(flush)
(read-line))
@zehnpaard
zehnpaard / simple-hiccup.core.clj
Last active March 25, 2023 02:04
Simple Ring/Compojure/Hiccup Demo
(ns simple-hiccup.core
(require
[ring.adapter.jetty :refer [run-jetty]]
[simple-hiccup.middleware :as m]
[simple-hiccup.routes :as r]
))
(def app
(-> r/routes
m/logger
@rday
rday / numpy_ma.py
Created June 5, 2013 18:53
Numpy moving average
import numpy as np
def moving_average(data_set, periods=3):
weights = np.ones(periods) / periods
return np.convolve(data_set, weights, mode='valid')
data = [1, 2, 3, 6, 9, 12, 20, 28, 30, 25, 22, 20, 15, 12, 10]
ma = moving_average(np.asarray(data), 3)
assert (np.around(ma, decimals=2)==np.array([2.0, 3.67, 6.0, 9.0, 13.67, 20.0, 26.0, 27.67, 25.67, 22.33, 19.0, 15.67, 12.33])).all() == True