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
  • 07:55 (UTC -04:00)
View GitHub Profile
@pmarreck
pmarreck / cobalt.json
Created June 5, 2024 22:04
Cobalt theme (the original one from TextMate) for the Zed editor
{
"$schema": "https://zed.dev/schema/themes/v0.1.0.json",
"name": "Cobalt",
"author": "Jacob Rus",
"theme.translator": "Peter Marreck",
"themes": [
{
"name": "Cobalt",
"appearance": "dark",
"style": {
@pmarreck
pmarreck / holidays.ex
Created May 23, 2024 19:13
Computing holidays with a DSL in Elixir
defmodule Addigence.Holidays do
use Timex
@holidays [
{:new_years_day, [:fixed, 1, :January]},
{:new_years_day_observed, [:nearest_weekday_to, 1, :January]},
{:martin_luther_king_jr_day, [:third, :monday, :January]},
{:washingtons_birthday, [:third, :monday, :February]},
{:good_friday, &Addigence.Holidays.compute_good_friday/1},
{:memorial_day, [:last, :monday, :May]},
@pmarreck
pmarreck / compact_datetime_ms.exs
Created May 22, 2024 22:52
Compact datetime format for Elixir use
# requires the Timex library though
Timex.format!(Timex.now(), "%Y%m%d%H%M%S.%L", :strftime)
@pmarreck
pmarreck / simple_llm_question.md
Last active April 20, 2024 19:32
gpt4 vs llama3 on a book content question

Me: What are the algorithms in "50 Algorithms Every Programmer Should Know" by Imran Ahmad?

ChatGPT: I don't have direct access to the specific content of books or their indexes, including "50 Algorithms Every Programmer Should Know" by Imran Ahmad. However, I can suggest some common algorithms that are likely to be included in a book aimed at covering essential algorithms for programmers: (invented list of algorithms follows)

Me posing the same question to the newly-released Llama3:70b :

bash> ollama run llama3:70b
>>> What are the algorithms in "50 Algorithms Every Programmer Should Know" by Imran Ahmad?
@pmarreck
pmarreck / cusip_validator.ex
Last active April 8, 2024 22:56
CUSIP Validator in Elixir
defmodule CUSIP do
@spec valid?(String.t) :: boolean
def valid?(cusip) when is_binary(cusip) do
validate_format(cusip) && validate_checksum(cusip)
end
@spec validate_format(String.t) :: boolean
def validate_format(cusip) when is_binary(cusip) do
Regex.match?(~r/^[a-zA-Z0-9]{5}[a-zA-Z0-9\*@\#]{3}[0-9]?$/, cusip)
@pmarreck
pmarreck / pg_dump command
Created April 1, 2024 22:12
Dumping an entire postgres database
#!/usr/bin/env bash
datetimestamp() {
local datebin="date";
$datebin --resolution > /dev/null 2>&1 || datebin="gdate";
$datebin --resolution > /dev/null 2>&1 || datebin="date";
local format=${DATETIMESTAMPFORMAT:-'+%Y%m%d%H%M%S'};
case "$1" in
--date=* | -d=*)
$datebin --date="${1#*=}" "$format"
@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