Skip to content

Instantly share code, notes, and snippets.

View pmarreck's full-sized avatar

Peter Marreck pmarreck

  • formerly desk.com, thredup.com and lifebooker.com. currently Director of Engineering @addigence
  • Long Island, NY
  • 04:16 (UTC -04:00)
View GitHub Profile
@pmarreck
pmarreck / flake.nix
Last active February 11, 2024 23:41
A basic flake.nix file for cross-platform Python projects. Use with "nix develop". pip, etc. should work via venv.
{
description = "A flake for pythonification";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils, ... }@inputs:
flake-utils.lib.eachSystem ["x86_64-darwin" "aarch64-darwin" "x86_64-linux" "aarch64-linux"] (system:
@pmarreck
pmarreck / generate_uuidv7.sql
Created December 13, 2023 04:45
Generate a UUIDv7 with a PL/pgSQL function
-- IETF Draft Spec: https://www.ietf.org/archive/id/draft-peabody-dispatch-new-uuid-format-01.html
CREATE SEQUENCE uuidv7_seq MAXVALUE 4095; -- A 12-bit sequence
CREATE OR REPLACE FUNCTION generate_uuidv7()
RETURNS uuid AS $$
DECLARE
unixts bigint;
msec bigint;
seq bigint;
@pmarreck
pmarreck / ollama2_hallucination.txt
Created November 26, 2023 03:52
ollama2-uncensored:70b hallucinating some bullshit about the limitations of 64 bits
20231124224207 ~/📄 bash> ollama run llama2-uncensored:70b
>>> Could the number 2137940590027877530 be nanoseconds since epoch?
No, it's not possible for that number to represent nanoseconds since epoch. The Unix timestamp system uses a base 10 representation of time, with each unit representing a
specific period of time. A nanosecond is one billionth of a second, so the maximum number of nanoseconds that can be represented by a 64-bit integer is 2^63 or
approximately 252 trillion. However, the number you provided is much larger than this and would therefore not represent any valid unit of time in the Unix timestamp
system.
>>> Apparently it translates to a date and time of 2037-09-30 16:23:10 UTC since Unix epoch when considered as nanoseconds
Yes, that is correct. When the number you provided is converted from its current representation to a base 10 format and interpreted as nanoseconds since epoch, it does
correspond to September 30th, 2037 at 4:23 PM UTC. However, as I mentioned earlier, this is not a va
@pmarreck
pmarreck / postscript_line_wrapping.ps
Created October 27, 2023 18:25
An example of a text wrapping function in pure PostScript
%!PS
%%BoundingBox: 0 0 612 792
/Times-Roman findfont 12 scalefont setfont
% Define the starting coordinates
/x 72 def
/y 720 def
% Routine to wrap lines
/wordbreak ( ) def
@pmarreck
pmarreck / heresies_within_the_bible.txt
Created October 3, 2023 16:32
Bible passages that refute the notion that Jesus only came to save the believers
(Mainly because I love defeating people's arguments by using their own sources against them...)
1 John 2:2 "My little children, these things write I unto you, that ye sin not. And if any man sin, we have an advocate with the Father, Jesus Christ the righteous: He is the propitiation for our sins, and not for ours only but also for the sins of the whole world."
1 Corinthians 3:15 "If anyone's work is burned up, he will suffer loss, though he himself will be saved, but only as through fire. 15 But if the work is burned up, the builder will suffer great loss. The builder will be saved, but like someone barely escaping through a wall of flames."
1 Timothy 4:10 "For to this end we toil and strive, because we have our hope set on the living God, who is the Savior of all people, especially of those who believe..."
1 Peter 3:18 "For Christ also suffered once for sins, the righteous for the unrighteous, to bring you to God."
1 Corinthians 15:22 "For as in Adam all die, even so in Christ shall all be made alive."
a few tests using `cjxl` (the reference `jpeg-xl` converter) I performed on a 120.7 MB PNG (the Carina Nebula, first photo from the James Webb Space Telescope):
there's 2 main parameters, "distance" (where 0 is lossless and 1 is the least detectable lossy; higher numbers are more lossy) and "effort" (compression effort, where 1 is quick and 9 is exhaustive/very long)
distance 0 effort 9 took 3 hours (obviously this is for a "write once, read many" sort of archival use-case) and got it down to about half of PNG, 67.2 MB; not bad for maintaining lossless.
distance 0 effort 6 took 1m43s, got it down to 75 MB, about 63% of PNG.
distance 1 effort 8 took 3 minutes and got it down to 7.7 MB which is about 1/15th of the PNG.
distance 1 effort 6 took 4s; got it to 7.1 MB... wait, _whut?_ That's... odd. Smaller than with effort 8. Anyway.
All encodings only used 1 of my 128 cores. Whole-image compression of this nature may not be "trivially parallellizable" ::shrug::
@pmarreck
pmarreck / convert_font_filenames
Last active July 25, 2023 17:49
Convert terrible 8.3-formatted font filenames to their internal fullname using the Fontconfig library tools.
#!/usr/bin/env bash
needs() {
local bin="$1";
shift;
command -v "$bin" > /dev/null 2>&1 || {
printf "%s is required but it's not installed or in PATH; %s\n" "$bin" "$*" 1>&2;
return 1
}
}
@pmarreck
pmarreck / hendricks_formatter.ex
Created July 25, 2023 14:02
An Elixir formatting module for `mix format` that converts leading spaces to tabs.
defmodule HendricksFormatter do
@moduledoc """
This module is a formatter plugin for Elixir's `mix format` task
that converts leading whitespace to tabs.
It tries to intelligently determine the tab width based on the most common
counts of leading space runs in the file.
It allows additional space characters for minor adjustments that are below the tab width.
OK, why tabs? Why resurrect this age-old nerd debate again?
Very simple: It's an accessibility issue:
https://adamtuttle.codes/blog/2021/tabs-vs-spaces-its-an-accessibility-issue/
@pmarreck
pmarreck / randompass.js
Created July 19, 2023 14:52
Put this as the URL of a browser bookmark and now you have a good password generator.
javascript:(function(){var%20password;var%20regex=/^(?=.*[A-Z].*[A-Z])(?=.*[a-z].*[a-z])(?=.*\d.*\d)(?=.*[!@#$%^&*].*[!@#$%^&*]).{20,}$/;do{password=Array.from(crypto.getRandomValues(new%20Uint32Array(25)),%20x%20=>%20"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*"[x%20%%2070]).join('');}while(!regex.test(password));alert(password);})()
@pmarreck
pmarreck / elixir_concurrency_demo.exs
Created July 17, 2023 20:39
Elixir concurrency demo: 1 million process spawn and garbage-collect.
#!/usr/bin/env elixir
# make sure to bump max erlang processes limit first:
# export ERL_FLAGS="+P 2000000"
defmodule Concurrency do
def millions_of_us(n) do
receive do
{sender_pid, message} ->
Process.sleep(:rand.uniform(2000))