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
  • 01:13 (UTC -04:00)
View GitHub Profile
@pmarreck
pmarreck / randompass.js
Created July 5, 2023 20:06
Generate a random password or randomized multiple-word dictionary password using Javascript (NO other dependencies!)
const CHARSET_LOWER = "abcdefghijklmnopqrstuvwxyz";
const CHARSET_UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const CHARSET_NUM = "0123456789";
const CHARSET_ALPHA = CHARSET_LOWER + CHARSET_UPPER;
const CHARSET_ALNUM = CHARSET_ALPHA + CHARSET_NUM;
const CHARSET_ALNUM_SANE = CHARSET_ALNUM.replace(/O|l|I/g, "");
// const CHARSET_PUNC = "!@#$%^&*-_=+[]{}|;:,.<>/?~";
// I shortened the possible punctuation chars due to incompatibility with various sites:
const CHARSET_PUNC = "!@#$%^&*";
const CHARSET_HEX = CHARSET_NUM + "abcdef";
@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
&gt;&gt;&gt; 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 / darktide_warhammer_quotes.txt
Last active April 8, 2024 12:09
Warhammer: Darktide loading screen quotes
A coward's only reward is to live in fear another day
A dagger in the dark is worth a thousand swords at dawn
A pity it is that we can die but once in the Emperor's service
A small mind is a tidy mind
A suspicious mind is a healthy mind
A swift execution is worth a hundred interrogations
Abhor the mutant
Abhor the Night, it is the Light that Endures
Abhor the xenos
Abhorrence is a gift; use it well
@pmarreck
pmarreck / nix-get-protonup
Created September 7, 2022 03:38
An example of installing a Python executable via pip in NixOS, in this case "protonup", using a virtualenv
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p python311
# set this to wherever you want your virtualenv
venv="$HOME/.pythonsucks-venv"
# set up the venv
python -m venv "$venv"
# activate the venv
source "$venv/bin/activate"
# upgrade pip if necessary
python -m pip install --upgrade pip
@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 / migrations_in_console_cheatsheet.exs
Created September 25, 2017 16:47
How to run Ecto migrations in Elixir/Phoenix from an `iex -S mix` or production console
# How to run Ecto migrations from IEx console... Examples
# preliminaries assumed in the following code, change to fit your environment:
alias YourAppName.Repo
your_app_name_as_atom = :mpnetwork
downto_version = 20170724182558
# Down:
Ecto.Migrator.run(Repo, "priv/repo/migrations/", :down, [to: downto_version])
@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 / kill_steam_proton_pids.bash
Last active January 29, 2024 13:14
Automatically clean up any orphaned Steam or Proton processes on Linux if any didn't exit cleanly
#!/usr/bin/env bash
function kill_steam_proton_pids() {
# This bash one-liner performs the following tasks:
# 1. It sets the PS_PERSONALITY environment variable to 'linux' which standardizes the output format of the 'ps' command.
# 2. Runs the 'ps' command with the following options:
# - 'e' to include processes from all users,
# - 'o pid,args' to only show process ID and command arguments,
# - '--sort=-pid' to sort by process ID in descending order (so it kills the newest processes first),
# - '--no-headers' to not include column headers in the output.
@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/