Skip to content

Instantly share code, notes, and snippets.

View carl-mastrangelo's full-sized avatar
💭
I may be slow to respond.

Carl Mastrangelo carl-mastrangelo

💭
I may be slow to respond.
View GitHub Profile
@carl-mastrangelo
carl-mastrangelo / build.gradle.kts
Created April 3, 2024 23:47
Debug Javac and Annotation Processors On Gradle
tasks.withType<JavaCompile> {
options.setFork(true)
options.forkOptions.jvmArgs = listOf("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=127.0.0.1:5009")
}
𓏺ᵎʹˈˌᑊ꘡ᡃᎥʾʿˑːϳ𓏤𓏪ᣟilᴉіʻʼʽjȷƖјɾɿ𐅛𛱻ᐝᐧꞁɉǀ𑫥łᣞ𛲄𛲔ⲓɩ𛱆ᶅꝉᶖ𛰀𓏬ᓫ𑇁𐑦ɭᱸᱹᱺꞌꞋꜝꜞꜟ𖭐𖾖𖾘𐍘𐍭յլͿ𓏻𛰂𛰇𛰌ıӏΙІIǃӀᶘʝʆιtʇʈfɟ𓈒ˁˀ𐏔ᣳ𔖳ɪ𔓄Ⲓ𐌉𛱈𛱉𛰁ꭵ𖼨𐔎𓌀𛲀𛲂𛲐𛲒𔒨𐒃𓌁ⵏꓲⵑ𓊧ꓸꓽꓹꓼ𖾓𓊤ⵂՙᡟꞲ𑅠𓌃𐌹𓌠ⱁꞏᣚ𖾙ʺⱜ𛱧𛱪𖾔ꜗᔉᔊ𓐫𑫯𑫰𑇜ᣴ𖾗𐎃ŧᵻⵗ𑀭ꜣ෦ꭇᱼẝẜ𑛀𓎗𖡡𛲈𛲘ᒾꞙᑋ𓌙𖾝𔗷𓇩ˊˋˎˏɹɺrɼɽˮˆˇˬˉˍ𐊊𓌐𔖭𔖮𔖰ꤷ𓂭𔓯𐝓𛲅𛲕𖾕𓎘𐑢𐑘𓍐ꟾ𑃵𐑶𐑬𓌱Ɨƚɨ𓇋𓆬𑃶𛱩𖤱𖾜𖾞𑃸ᶂꬵꝇᣘꙇ𓍛ᵼᴊ𑃳ᔋ𑃷𓇞𓎫𐎇𐏒ⱡ𛱨𓌞𛲙𓇛ɬ𓌉ғ𛱤𐎂𐏑ⱃ𛰄ᣵⳋᵮᵳৎᵵ𛱑𛱒𛱓𑣡𑃹Ⳕƪ𖼩𔕿ꭍ𐑐𐑓𐑚𐑝𓄤𐕆᧒𓏰ꖎᣖᣗƭƫᕑ𓎄𓎆𓎇𓄥𑃱𑃲ଽ𛱥𓋩𖨘𓌜𓋿ꫴɫⳕ𖩙𖨄ᛵ𛱣𓀾ᡰ𐕇𐑪𐑨𐑩𐑧𖥣𑫫𑫬𑫳𑫴𑫵ⲣ𑣑𑁦ৰৱꜢⲝꬸ𛱦𑃨𓉼ⳇ𐑑𐑛𓍗ⲃȴ𖣣𔖱𔕻𔕽𔕺𔕼𓂆𓐪ᐦᒻᒽ𛱇𛱌𛱍𛱎𛱺𛱼𓌟ॱⰬ𓏯ȶ𛲆𛲖ᐨᐤᐩᕀᐡᐢᐪґ𐝁ɍⱦͱꙆ𑢱ⳉᝢ𓍙𑣁𓏜𑃴ꬹ𐙂ᐣꡲ𓌢𔓽রব𛱢𛱁𑛇෭ꜘᵲ𔘗𔔵𐑟𐑕𓐮ᗮᙾᙿ𐐮𔗌𓎿ꜥꞎট𓊪ⲋ𐑣𐑙г𔓈𓍢ʃʄ𓊢ঠչ𐑰𓏡ⲍ𑇐𖠣ᒃᒄ𛰅ነⳤচঢ𑃒𖦔𔖩𔖪𓉺𐎓𐏓Ⱁ𐝀𓍱ᶉ𓄉𓄻𐃊ꜰⱹꝼꞅ𓍲𓍋𓍌𓋾𓉶ꬲꞧ𒁹𛱂𓍏𓄈𖭁𓋴𖢞𐔺ꞈ𑅑দᔅᔇᔾᕐᖮ𛱡𑚤𖧻꣑𖽐𑆫ᔆ𓍘𖦕ꜱꬷ𓇪𖨷𓇜𓍡ᴯᐟᐠꔧᶋ𖠜𓇕𓇟𐑮𐑤𖦅𔒫ᴤʅ𐑱𐑲𓂂𖧹ⱐ𐊖𐑳𑆆ᡣꡱᰅʬ𖡐𔖸𓏼𓏾𓏿𓋽𓌂𓐂𖨮𑚙𛰔ǁ𔐓𔘅𓄽𛱏ⲅⲧধযएऍऎऐ𖠎𔘏ӻᑦᒡᒢւ𒑖𒑉ⳑⰽ𛰆𛰗रӷ𐐹𐑃𖦻𓌚𑅛১𖧳ꧏ𐔶ꝲ𖥾𔘸𔔥𓄙𓎛𓏹ⲥᝈঘ𖨣ꭋ𔓡𓐬𑚆𑚇𐌆𐌝𔕑𐑥𐑯ঽɻᴦ𓌑ᴌⳆ𐌔𐝕𑙓ऽͰ𑓑𐑠𐑖ζ𖨈𖢟𔗦𓎭𑂠දඳⲉꘓ𖠙ষনⅎ𔘊𓌰𓆄𐅗Ꭻ𖧖𔑏𔑐༥𔘭꣒𑃣𑫨ꀤꀫ𑃞𑅫𛱊𛱋𛱃𖣅𐑾𖼷𖼸𖼹Ꜥ𔗶ᡕᣕ𓆳𓆴𓆶ர𐕡ᓑꡨ𑂩𓄠𓌣𓆼𖦋𔖏𔖨𑅖Ⴈꈌ𖠵𐘍ꈋ𑛈𑃦𑃖𔔴𓋃ⲕಽ𖨙𖨋𔕮𑇗ᛳ𛰖𑊚ԁ𓄊𖥫𖧰𖨂𖢴ꈥᔈ𖨆মꤱꤶϝꋽ𖣢ꋼ𑣇ꬽꬾ𔖫𓍊ণহ𑚖᥉ⲭꜙ𑀤ꔪ𓃉𓃊𐚉ꆹ𖩚ꡡ𑅟ꆸ𐐾ƾ𑙘𐕁𖧾𔗨𔖒𓍍ⳁइईⱻᴇꛐ𔖀𔘱ᘤᘥᘦᘧ𛲃𛲓𔗎𔗏ⱉᴛᐥꫲᖟᣙ𔓸ꈤꈣ𖣻ገፃየখ𑫦𖡏𖤲𔓱𔗵𔘦𓉽𑛃𑋉ᙆᙇ𖥏𐑒𐑜𔑈𓋀ꛬꙋⳟ𓌹𓌺𛲇𛲗𔗐ȥᴢᶎⴭ𑚟ᵶɀⲹʐꜚ᱇Ⱃⲗ𒋙𑃟𖦸𑙄꣖𑅭ꙁꙃ𑛉𐝏𓏌𖢔𔕔Ꭸᛶꝛꝭ𐑄𑫧𔐔𖦾𑅕𑃚𑃤𐙧𑊁𐔻ꌅꌕꌖꑍꌄꌔ𖥈𑍝ꉂꉁꤰꤴꤳꤹথꊤꊣꉧꚃ𑣂ꭻⱈꞩꏂꏁꊫ𓊽ʂ𐑈ᶊꙅȿ𖡉𑙒২ᴠᵴपषꚹ𔗍𐐽𐑋ᶗꜿꞔⰵ𐑡𐑗ꞓ𐙆ኔፅ𖧱৯ঌগৡꄧꄦ𔘙𔔃𑙖ꃘ৬ꭉꮪ𖼳ⱛ𖠗ᳯᢃᢄ᱔ꛌꮷ𑇒ঙ𔗩𔓹ϛꅪꊰꑌꅩꊯꑋ༡ⰰᕁᕽ𑀟𑃙𑃜𑃠ꮀ𐐰𓐩𑅰ꅓꜛꜜꅒᣛ𔒽𐑂हꆾꝻꞄ𓋂𖥉᥋ꔷꆽꆼ𑇕ꊉꚍꚑ𑓗𑅞Ғ𖧩𖤃ꋊ𐐩𑃑ⲟⱶ᱁ꄔꆻ᱀𖠴𔘤𑚝૧ꛨƽᴣᶚᶔꞇ𑊟ѯⴾ𓄹𓄼𖤣𖤥𑇘𑚡𐙿𐚒ꏲꏱ𖦧ҁ᥍᥌𑆉᥏உबवॿʟᚆᚁᚐ𐒗𐒑𔖧ꄜꄛ꣓Ⳋꮞⲑᶓ𖦬ᴻ𖠱ᐜꇱ𑣎ꅨ𐘄𐘅ꀯ𖨚𐜥𓇡Ϟʏዕᠵᠶᡷ𐝃𖼴ꇻꊱ𐝄৪𐒦𑙑𑃧𑢡ઢઽ୯᥈᥎𑃰𖥮ꄡꄤꉖ
@carl-mastrangelo
carl-mastrangelo / Queens.java
Created March 24, 2023 21:11
Find covering positions of a Chess board using a minimum number of queens.
package com.carlmastrangelo;
import java.util.SplittableRandom;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveAction;
import java.util.concurrent.atomic.AtomicLong;
public final class Queens {
public static void main(String [] args) throws Exception {
@carl-mastrangelo
carl-mastrangelo / foo.java
Last active February 26, 2023 20:30
Small number encoder
// Writes numbers less than 172 in one byte, numbers less than 1936 in 2 bytes.
private static void writeInt(OutputStream os, int i) throws IOException {
if (i < 0) {
throw new UnsupportedOperationException("no neg");
} else if (i < 172) {
os.write((byte) i);
} else if (i < 1936) {
i -= 172;
os.write((byte)(172 + 42 + (i % 42)));
os.write((byte)(172 + (i / 42)));
@carl-mastrangelo
carl-mastrangelo / perf.java
Created February 20, 2023 21:32
Sleep Executors
/*
Benchmark (executor) (sleepMillis) (sleeps) Mode Cnt Score Error Units
SleeperBenchmark.Bench.run CACHED 1 1 ss 30 1.180 ± 0.028 ms/op
SleeperBenchmark.Bench.run CACHED 1 8 ss 30 1.227 ± 0.044 ms/op
SleeperBenchmark.Bench.run CACHED 1 64 ss 30 1.365 ± 0.045 ms/op
SleeperBenchmark.Bench.run CACHED 1 512 ss 30 3.764 ± 0.476 ms/op
SleeperBenchmark.Bench.run CACHED 1 4096 ss 30 13.375 ± 0.996 ms/op
SleeperBenchmark.Bench.run FIXED 1 1 ss 30 1.234 ± 0.035 ms/op
SleeperBenchmark.Bench.run FIXED 1 8 ss 30 1.362 ± 0.084 ms/op
SleeperBenchmark.Bench.run FIXED 1 64 ss 30 9.433 ± 0.409 ms/op
@carl-mastrangelo
carl-mastrangelo / ntru.py
Last active October 8, 2022 17:37
NTRU Prime encoder
# From page 16 of https://ntruprime.cr.yp.to/nist/ntruprime-20201007.pdf
# Linked from https://www.imperialviolet.org/2021/08/26/qrencoding.html
def rebase(innums, indenoms, limit, newbase):
if len(innums) != len(indenoms):
raise "Bad"
syms = []
if len(innums) == 1:
num, denom = innums[0], indenoms[0]
while denom > 1:
@carl-mastrangelo
carl-mastrangelo / b58encode.py
Created July 31, 2022 06:45
Base 58 Encode
# From https://datatracker.ietf.org/doc/html/draft-msporny-base58-03
# The description on that page is misleading or just wrong.
# This was derived from converting the Rust code here:
# https://github.com/hachi-bitto/btc-wallet/blob/5dde65a262d3239a23292fc2a4a692994603aeb0/wallet/src/base58.rs
TABLE = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
FORWARD = {k:v for (k, v) in enumerate(TABLE)}
BACK = {k:v for (v, k) in enumerate(TABLE)}
@carl-mastrangelo
carl-mastrangelo / factorial.py
Last active July 17, 2022 22:41
factorial encoder
ordered = ["A", "B", "C", "D", "E", "F"]
def encode_permutation(permutation, ordered):
ordered = ordered.copy()
size = len(ordered)
encoded = 0
for (i, value) in enumerate(permutation):
fact = factorial(size - i - 1)
idx = ordered.index(value)
ordered.remove(value)
#!/usr/bin/env python3
from PIL import Image
from math import sin, cos, pi
width = 1440
height = 800
midw = width / 2
midh = height / 2
lesser = min(midw, midh)
import jdk.internal.platform.Metrics;
public class Foo {
static volatile long bah;
public static void main(String [] args) {
Metrics metrics = Metrics.systemMetrics();
// com.sun.management.internal.OperatingSystemImpl