Skip to content

Instantly share code, notes, and snippets.

import pathlib
import string
import itertools
import random
from typing import Callable
roots = "select 100 as id"
def sql(nodes):
return "UNION ALL".join(["select 100 as id from {{ ref('%s') }}" % n for n in nodes])
@wrgoldstein
wrgoldstein / i.py
Last active December 20, 2023 17:29
dead simple activity recorder.
#!/opt/homebrew/bin/python3
import datetime
import sys
import os
from pathlib import Path
home = os.path.expanduser('~')
fname = f"{home}/whatidid"
if not os.path.isfile(fname):
import os
import requests
import collections
headers = {
'Accept': 'application/vnd.github+json',
'Authorization': 'Bearer ' + os.getenv('GITHUB_API_TOKEN', ''),
'X-GitHub-Api-Version': '2022-11-28',
}
from collections import Counter
from itertools import combinations
types = [1,2,3,4]
# creatures have 2 of the 4 types
# so there are c(4,2) = 6 creatures
creatures = list(combinations(types, 2))
# there are four creatures in each ocean
import pathlib
import collections
import jinja2
import graphlib
class Engine:
current = None
graph = collections.defaultdict(lambda: dict(deps=[], compiled=None, config={}))
env = jinja2.Environment(
import time
from random import randint
# make some dumb fake data
def make_row(r):
r = randint(1, 200)
s = [randint(r - min(r - 1, 15), r + 15) for _ in range(randint(1,6))]
return [r, s]
rows = [make_row(r) for r in range(500_000)]
@wrgoldstein
wrgoldstein / exla_gpu_instructions.txt
Last active April 19, 2023 15:08
Getting set up to do GPU accelerated machine learning in Elixir on a fresh Google Cloud Platform VM
# So you want to do machine learning in elixir on a fresh GCP VM with a GPU?
=== setup a VM ===
1. chose a gpu (T4), make sure you use debian 11 bullseye and the right region
2. dont use the default boot disk
3. do change the boot disk to have 50GB of space
4. get yourself a bunch of ram (for re-training BERT with 250 text samples 15Gb wasn't enough)
5. ssh in:
gcloud compute ssh instance-6
@wrgoldstein
wrgoldstein / psql_wire_protocol.exs
Last active February 16, 2023 01:26
A simple tcp server that speaks postgres, ported from https://gist.github.com/eatonphil/079f8654174b9b9c1953b76008d024ae
"""
Elixir server that partially speaks the PG wire protocol. Run:
```
mix run psql_wire_protocol.exs
```
and run psql at a separate terminal prompt:
```

Simple physics:

  • velocity = distance / time
  • momentum = mass x velocity

An analogy:

  • The distance traveled by a single developer in a set amount of time is "velocity"
  • The movement of the organization as a whole is "momentum" (the sum of individual velocities)
  • If you add more people but reduce velocity then momentum decreases (this is why small teams are sometimes more productive than big teams).
"""
A cli to populate a local database with production
data. Expects a companion file called tables.py to exist
with the following structure:
```python
# tables.py
# any tables that should be downloaded in their entirety
small_tables = [