❯ ls -alrt
total 0
drwxr-xr-x 152 hughbrown staff 4864 Jan 15 12:00 ..
drwxr-xr-x 9 hughbrown staff 288 Jan 15 12:00 .git
-rw-r--r-- 1 hughbrown staff 0 Jan 15 12:00 x644
-rwxr-xr-x 1 hughbrown staff 0 Jan 15 12:01 x755
-rw------- 1 hughbrown staff 0 Jan 15 12:01 x600
drwxr-xr-x 6 hughbrown staff 192 Jan 15 12:01 .
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
os.environ["NUMBA_LOOP_VECTORIZE"] = "0" | |
os.environ["NUMBA_SLP_VECTORIZE"] = "0" | |
from datetime import datetime | |
from numba import jit, uint32, uint64 | |
import numpy as np | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from graphlib import TopologicalSorter | |
>>> data = {"A": ["B", "D"], "B": [], "D": [], "C": ["A"]} | |
>>> ts = TopologicalSorter(data) | |
>>> for a in ts.static_order(): | |
... print(a) | |
... | |
B | |
D | |
A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
FORMAT = '%(asctime)s %(message)s' | |
logging.basicConfig( | |
format=FORMAT, | |
datefmt="%Y-%m-%dT%H:%M:%S", | |
# logger levels are: DEBUG, INFO, WARNING, ERROR, CRITICAL | |
level=os.environ.get('LOGLEVEL', 'INFO').upper(), | |
) | |
logger = logging.getLogger() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-------------------- 2019-01-01 hacker-news-2019-01-01.txt: 782 | |
-------------------- 2019-02-01 hacker-news-2019-02-01.txt: 702 | |
-------------------- 2019-03-01 hacker-news-2019-03-01.txt: 759 | |
-------------------- 2019-04-01 hacker-news-2019-04-01.txt: 757 | |
-------------------- 2019-05-01 hacker-news-2019-05-01.txt: 829 | |
-------------------- 2019-06-01 hacker-news-2019-06-01.txt: 675 | |
-------------------- 2019-07-01 hacker-news-2019-07-01.txt: 767 | |
-------------------- 2019-08-01 hacker-news-2019-08-01.txt: 741 | |
-------------------- 2019-09-01 hacker-news-2019-09-01.txt: 615 | |
-------------------- 2019-10-01 hacker-news-2019-10-01.txt: 733 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from pathlib import Path | |
from PIL import Image, ImageChops | |
def trim(im): | |
bg = Image.new(im.mode, im.size, im.getpixel((0,0))) | |
diff = ImageChops.difference(im, bg) | |
diff = ImageChops.add(diff, diff, 2.0, -100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# This is a simulation of the results for the first problem given here: | |
# https://fdpinstitute.org/resources/FDP%203.0/2024-Q2/Limited%20Sample%20MC%20Questions%20Q2-2024.pdf | |
# | |
# The expected answer given by the FDP Institute is 0.84. This is incorrect, as this simulation shows. | |
# The problem is that FDP has used the Bayesian formula incorrectly. Instead of using a weighted average | |
# of outcomes as the prior probability, FDP uses only the P(potted|~Simon) as the prior. | |
from collections import Counter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import cycle | |
def spiral(n): | |
matrix = [[0] * n for _ in range(n)] | |
x, y = 0, 0 | |
x0, y0, xn, yn = 0, 0, n, n | |
directions = cycle([ | |
(1, 0, (0, 0, 1, 0)), | |
(0, 1, (0, -1, 0, 0)), | |
(-1, 0, (0, 0, 0, -1)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import hashlib | |
from bitarray import bitarray | |
class BloomFilter: | |
def __init__(self, n_items, fp_prob): | |
''' | |
n_items : int | |
Number of items expected to be stored in bloom filter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
You're given a list of elements. Each "element" has a unique id and 3 properties. | |
Two elements E1 and E2 are "similar" if they share any of their 3 properties. | |
Please write a function that takes a list of elements as input, and returns all "similar" groups of elements. | |
Example Input: [E1, E2, E3] | |
E1: (id1, p1, p2, p3) | |
E2: (id2, p1, p4, p5) | |
E3: (id3, p6, p7, p8) |
NewerOlder