Skip to content

Instantly share code, notes, and snippets.

View littleli's full-sized avatar

Aleš Najmann littleli

View GitHub Profile
@littleli
littleli / paillier.clj
Last active July 20, 2021 11:49
The implementation of Paillier cryptosystem for Clojure and Babashka
(ns fun.clojure.paillier
(:import [java.math BigInteger]
[java.security SecureRandom]
[java.nio.charset StandardCharsets]))
(defn- random-number! [end]
(let [start (BigInteger/valueOf 2)
interval (.subtract end start)
i (BigInteger. (.bitCount interval) (SecureRandom.))]
(.add start i)))
@littleli
littleli / SoABenchmark.java
Created January 18, 2021 21:16 — forked from twolfe18/SoABenchmark.java
Does SoA (structure of arrays) beat AoS (array of structures) for Java?
package sandbox;
import java.util.Arrays;
import java.util.Random;
public class SoABenchmark {
public static Random rand = new Random(9001);
public static int NUM_LABELS = 10;
public static Struct[] aos;
@littleli
littleli / output.calva-repl
Last active October 6, 2020 15:56
Calva error reporting
clj::littleli.clj-dremel=>
; Syntax error compiling deftype* at (src/littleli/clj_dremel.clj:50:1).
; Unable to resolve symbol: IDeref in this context
[{:file "Compiler.java" :line 7115 :method "analyzeSeq" :flags [:tooling :java]}
{:file "Compiler.java" :line 6789 :method "analyze" :flags [:tooling :java]}
{:file "Compiler.java" :line 6745 :method "analyze" :flags [:dup :tooling :java]}
{:file "Compiler.java" :line 6118 :method "parse" :flags [:tooling :java]}
...]
@littleli
littleli / strdist.clj
Last active June 6, 2020 23:42
String distance function
(ns strdist
(:require [clojure.core.match :refer [match]]
[clojure.string :as str]))
(defn -distance
[s1 s2]
(match [s1 s2]
[nil _] (.length s2)
[_ nil] (.length s1)
[([l & ls] :seq) ([r & rs] :seq)] (min (+ (if (= l r) 0 1) (-distance ls rs))
@littleli
littleli / spike-day-02-03-20.md
Created March 23, 2020 21:32 — forked from cldwalker/spike-day-02-03-20.md
GraalVM dive in Clojure at work

Spike

I looked into the state of GraalVM and Clojure and wrote some small work-related scripts.

GraalVM Build Tools

@littleli
littleli / clojure.rb
Created February 22, 2020 14:37
Clojure homebrew formula
class Clojure < Formula
desc "The Clojure Programming Language"
homepage "https://clojure.org"
url "https://download.clojure.org/install/clojure-tools-1.10.1.510.tar.gz"
sha256 "c6e003f612bdd7f9a9baa6d86deafb2d51b411310077c83c9ed13bc649c13b18"
revision 1
bottle :unneeded
depends_on "rlwrap"
# Check your changes compared to master with clj-kondo:
git diff `git merge-base origin/master HEAD` --name-only |grep -e '.clj$' | (cd `git root`; xargs clj-kondo --lint)
@littleli
littleli / log.txt
Created November 24, 2019 19:18
clj-kondo/windows-tests
==== Testing JVM version
==== Testing JVM version
lein test clj-kondo.analysis-test
lein test clj-kondo.compojure-test
lein test clj-kondo.core-test
lein test :only clj-kondo.core-test/run!-test
@littleli
littleli / transducers.md
Created April 17, 2019 16:59 — forked from pjstadig/transducers.md
The secret feature of transducers that no one talks about!

The Pledge

One thing that always made me a little sad about transducers was how map lost its ability to iterate multiple collections in parallel. This is actually my favorite feature of map. For example:

(map + (range 5) (range 5 10))
=> (5 7 9 11 13)

One somewhat practical use of this is if you want to compare two sequences, pairwise, using a comparator. Though I wish that every? took multiple collections, this is an adequate substitute: