Skip to content

Instantly share code, notes, and snippets.

@aglove2189
aglove2189 / blockchain.py
Last active April 3, 2024 19:57
barebones blockchain example
import hashlib
import time
class Block:
def __init__(self, data, previous_hash=None):
self.data = data
self.previous_hash = previous_hash
self.nonce = 0
self.hash = self.calculate_hash()
@aglove2189
aglove2189 / oracle.py
Created June 29, 2023 15:22
Aaronson Oracle
from collections import defaultdict, deque
class Model:
def __init__(self):
self.counts = defaultdict(lambda: {"f": 0, "d": 0})
self.last_six = deque(maxlen=6)
self.num_correct = 0
self.num_predictions = 0
@aglove2189
aglove2189 / BuildingDataProducts.md
Last active November 3, 2023 16:24
How to Build Resilient Data Products

How to Build Resilient Data Products

Every aspect of your product should contribute to one of these 5 principles:

  1. Small
  2. Fast
  3. Reproducible
  4. Transparent
  5. Frictionless

@aglove2189
aglove2189 / numerize.py
Last active April 25, 2023 15:51
numerize - shorthand format of numbers for humans
import math
def numerize(num, precision=1):
if num == 0:
return "0"
num = float(f"{num:.3g}")
m = int(math.log10(abs(num)) // 3)
numf = f"{num / 1000.0**m:.{precision}f}".rstrip("0").rstrip(".")
return f"{numf}{['', 'K', 'M', 'B', 'T', 'G'][m]}"
@aglove2189
aglove2189 / requirements.txt
Last active January 30, 2023 14:51
minimal python packages
# data / ml
numpy
pandas
scikit-learn
shap
sqlalchemy
lightgbm
# inspection
tqdm
@aglove2189
aglove2189 / leetcode.py
Created April 17, 2022 22:13
leetcode solutions
import string
import collections
from typing import List
# https://leetcode.com/problems/rotate-array/
def rotate(nums: List[int], k: int) -> None:
k = k % len(nums)
nums[:] = nums[-k:] + nums[:-k]
return nums
@aglove2189
aglove2189 / sql_cache.py
Last active April 16, 2021 14:48
pd.read_sql but with a time to live (ttl) cache.
# -*- coding: utf-8 -*-
import os
import hashlib
import pandas as pd
def read_sql_cache(sql, con, ttl=None, dirname="_cache", **kwargs):
"""
pd.read_sql but with a time to live (ttl) cache.

Keybase proof

I hereby claim:

  • I am aglove2189 on github.
  • I am aglove2189 (https://keybase.io/aglove2189) on keybase.
  • I have a public key ASATX83xHP59rWWRENkl2UKrcDjWeViiLIqlqPQM3QLuugo

To claim this, I am signing this object:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install chrome
choco install git
choco install cmder
choco install vscode
choco install anaconda3
conda config --add channels conda-forge
conda install black hyperopt lightgbm loguru mlxtend pandas-profiling pyarrow shap tokei
Start-Process "chrome.exe" "https://www.lfd.uci.edu/~gohlke/pythonlibs/#xgboost"
@aglove2189
aglove2189 / git.py
Created November 1, 2018 16:16
Bulk clone and/or pull a list of repos
# -*- coding: utf-8 -*-
import os
import re
pat = '\w*(?=\.git$)'
with open('git.sh', mode='w') as f:
f.write('#!/usr/bin/env bash\n')