Skip to content

Instantly share code, notes, and snippets.

@keksipurkki
keksipurkki / unrank.js
Created January 23, 2024 21:58
Unrank a permutation rank (https://doi.org/10.3390/a14030097)
// Cyann Donnot, Antoine Genitrini, Yassine Herida. Unranking Combinations Lexicographically: an
// efficient new strategy compared with others. 2020. hal-02462764
// https://hal.sorbonne-universite.fr/hal-02462764v1/preview/paper.pdf
const crypto = require("crypto");
function randomBigInt(bitLength) {
const u = crypto.randomBytes(bitLength / 8);
return BigInt("0x" + u.toString("hex"));
}
@keksipurkki
keksipurkki / Makefile
Created November 26, 2023 09:07
Makefile template
# Generic GNUMakefile
# Just a snippet to stop executing under other make(1) commands
# that won't understand these lines
ifneq (,)
This makefile requires GNU Make.
endif
PROGRAM = foo
C_FILES := $(wildcard *.c)
@keksipurkki
keksipurkki / hello_world.mjs
Created October 15, 2023 16:34
hello_world.mjs
#!/usr/bin/env node
import * as readline from "node:readline/promises";
const { stdin: input, stdout: output } = process;
const rl = readline.createInterface({ input, output });
const name = await rl.question("What is your name? ");
console.log(`Hello there, ${name}`);
@keksipurkki
keksipurkki / vanilla.txt
Last active August 4, 2023 12:50
Vanilla logs
2023-08-04T15:07:37+03:00 net.keksipurkki.demos.Application INFO Starting Application()
2023-08-04T15:07:37+03:00 net.keksipurkki.demos.HelloWorld INFO Deploying HelloWorld()
2023-08-04T15:07:37+03:00 net.keksipurkki.demos.Application INFO Deployment complete. Success = true
2023-08-04T15:07:44+03:00 net.keksipurkki.demos.Application INFO Handling request. Method = GET. URI = http://localhost:8080/hello-world
2023-08-04T15:07:44+03:00 net.keksipurkki.demos.HelloWorld INFO {"message":"Hello world!"}
2023-08-04T15:07:45+03:00 net.keksipurkki.demos.Application INFO Handling request. Method = GET. URI = http://localhost:8080/hello-world
2023-08-04T15:07:46+03:00 net.keksipurkki.demos.HelloWorld INFO {"message":"Hello world!"}
@keksipurkki
keksipurkki / Bug.java
Created June 16, 2023 17:11
Vert.x and Jackson Databind
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import io.vertx.core.json.Json;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.jackson.DatabindCodec;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import java.util.Map;
@keksipurkki
keksipurkki / NullableEnumConverter.java
Created June 8, 2023 13:04
NullableEnumConverter.java
public class NullableEnumConverter implements ModelConverter {
@Override
public Schema<?> resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) {
var schema = chain.next().resolve(type, context, chain);
if (isNull(schema)) {
return schema;
}
@keksipurkki
keksipurkki / dictionary.ts
Last active September 16, 2022 18:01
The classic dictionary
import * as fs from "fs";
import * as assert from "assert";
type DictionaryEntry<K, V> = [key: K, value: V];
const DICT_INITIAL_SIZE = 8;
const DICT_MAX_LOAD_FACTOR = 0.75;
class Dictionary<V> implements Iterable<[string, V]> {
private _entries = 0;
@keksipurkki
keksipurkki / main.clj
Last active September 7, 2022 20:41
My first Clojure program
; clojure -M main.clj 3
; 000
; 001
; 010
; 011
; 100
; 101
; 110
; 111
const fs = require("fs");
const cartesian = (...a) => a.reduce((a, b) => a.flatMap(d => b.map(e => [d, e].flat())));
const intersection = (a, b) => new Set([...a].filter((x) => b.has(x)));
const letters = [
["n", "h", "i", "m", "w"],
["a", "h", "y", "i", "m"],
["c", "b", "x", "o", "l"],
["k", "o", "i", "u"],
@keksipurkki
keksipurkki / getenv.sh
Created March 15, 2022 08:57
SSM parameters to .env file
#!/bin/sh
set -e
function usage()
{
echo "Usage: $(basename $0) PATH"
}
function to_env()