Skip to content

Instantly share code, notes, and snippets.

View jvillste's full-sized avatar

Jukka Villstedt jvillste

View GitHub Profile
@jvillste
jvillste / cider-eval-commands.el
Last active February 21, 2024 15:42
Emacs commands for evaluating code so that stdout stderr go to the cider result buffer along with the result
(defun juvi-pprint-eval-to-result-buffer (form)
(cider-interactive-eval form
(nrepl-make-response-handler (cider-popup-buffer cider-result-buffer nil 'clojure-mode 'ancillary)
(lambda (buffer value)
(cider-emit-into-popup-buffer buffer value))
(lambda (buffer out)
(cider-emit-into-popup-buffer buffer out))
(lambda (buffer err)
(cider-emit-into-popup-buffer buffer err))
'())
(ns ansible
(:require
[clojure.java.shell :as shell]
[clojure.string :as string]
[clojure.test :refer [deftest is]]))
(defn- keyword-to-string [x]
(if (keyword? x)
(name x)
x))
(ns experimentation.kertotaulu
(:require
[clojure.string :as string]))
(defn multiplications [numbers]
(mapcat (fn [a]
(for [b numbers]
[a b]))
numbers))
@jvillste
jvillste / dynamic_varialbe_access_benchmark.clj
Created February 10, 2023 07:29
benchmark of dynamic variable access in clojure
(ns dynamic-varialbe-access-benchmark
(:require [criterium.core :as criterium]))
(def ^:dynamic dynamic-x 1)
(def nondynamic-x 1)
(defn add-dynamic []
(+ 1 dynamic-x))
@jvillste
jvillste / employees.clj
Last active November 14, 2022 13:18
interview
(defn load-employees-from-db []
[{:name "Mary" :salary 6000}
{:name "John" :salary 4000}])
(let [sum (atom 0)]
(doseq [e (load-employees-from-db)]
(reset! sum (+ @sum (:salary e))))
(/ @sum
(count (load-employees-from-db))))
(ns parser-combinator
"A parser combinator library.
A parser is a function that takes a sequence of tokens and returns
all possible partial parses, or nil if the parising fails. A partial
parse is a pair of a parse and a sequence of remaining tokens. A
parse is a sequence of values or tagged values. A tagged value is a
vector containing a keyword followed by values.
A parser combinator is a function from one or more parsers to a
(ns flow-gl.swing.render-loop-test
(:import [java.awt Canvas Color Font]
java.awt.geom.Rectangle2D$Double
javax.swing.JFrame))
(defn start []
(let [last-paint-time-atom (atom (System/currentTimeMillis))
frame-rates-atom (atom [])
j-frame (JFrame.)
canvas (Canvas.)]
(ns serialization
(:require [clojure.java.io :as io]
[taoensso.nippy :as nippy])
(:import [java.io DataInputStream DataOutputStream EOFException]
clojure.lang.IReduceInit
clojure.lang.IReduce))
(defn with-data-output-stream [file-name function]
(with-open [data-output-stream (DataOutputStream. (io/output-stream (io/file file-name)))]
(function data-output-stream)))
(ns experimentation.sähkökalusteet
(:require [clojure.set :as set]
[flow-gl.graphics.buffered-image :as buffered-image]
[flow-gl.gui.animation :as animation]
[flow-gl.gui.visuals :as visuals]
[fungl.application :as application]
[fungl.component.text-area :as text-area]
[fungl.dependable-atom :as dependable-atom]
[fungl.layouts :as layouts]))
Katkaise 2640 4500 pitkästä palasta
palat: []
Katkaise 2640 4500 pitkästä palasta
palat: [1860]
Katkaise 2520 4500 pitkästä palasta
palat: [1860 1860]
Katkaise 2520 4500 pitkästä palasta
palat: [1860 1860 1980]
Katkaise 2520 4500 pitkästä palasta
palat: [1860 1860 1980 1980]