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
# let's imagine you didn't care about | |
# the `output_filename` or the `extensions` | |
def decorator(f): | |
def inner(*args, **kwargs): | |
f(*args, **kwargs) | |
save(plt) | |
return inner | |
def plot_something(foo: int, bar: int) -> None: |
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
-- given tables a, b | |
-- equivalent SQLAlchemy models A, B | |
-- a has many b, joined on a_id | |
-- a has l non-id fields, b has m | |
a_id | x1 | x2 | x... | xl | |
b_id | a_id | y1 | y2 | y... | ym | |
-- let's do a joined load: |
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
// Get a recent version of node installed with npm | |
node --version | |
npm --version | |
// Make a new directory | |
mkdir ts-quickstart | |
cd ts-quickstart | |
// Get everything set up | |
npm init |
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 StringIO import StringIO | |
from itertools import islice, izip_longest, tee | |
import pandas as pd | |
from pandas.util.testing import assert_frame_equal | |
def read_data_frame_str(s, first_col_index=False): | |
"""Read a markdown-style description of a table into a DataFrame. | |
:param str s: | |
:param bool first_col_index: if `True`, use the first column as an index. |
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
"""This isn't the most efficient, but is the most "natural" to me. | |
match(i, j) => do letters `s[:i]` match chars `p[:j]` | |
- If i == -1, return False | |
- Set letter to the last of letters and char to last of chars | |
- If chars is empty, the only match is if letters is empty | |
- If char is *, did s[:i-1] match p[:j] or did s[:i] match p[:j-1]? | |
- Else does char match letter and did s[:i-1] match p[:j-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 base64 | |
from functools import lru_cache | |
import logging | |
from time import sleep, time | |
from typing import Dict, TypedDict, Tuple, List, TypeVar | |
import requests | |
from google.auth.transport.requests import AuthorizedSession | |
import google.auth |
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
# 105 line parser and interpreter for a small language with | |
# integers, assignments, lexical scope, first class functions | |
from __future__ import annotations | |
from dataclasses import dataclass, replace | |
from typing import Callable, Union | |
source = """ | |
(#{ | |
(#= x 5) | |
(#= f |
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
// 80 line parser and interpreter for a small language with | |
// integers, assignments, lexical scope, first class functions | |
const source = ` | |
(block | |
(assign x 5) | |
(assign f | |
(function | |
(a b) | |
(block | |
(assign c (+ a b)) |
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
// ___________________________ | |
// _| generic constraint solver |__________________________________________________ | |
type Assignments<V> = {[K: string]: V} | |
type Constraint<V> = (assignments: Assignments<V>) => boolean | |
type KProperties<V> = { | |
domain: V[] | |
constraints: Constraint<V>[] | |
} | |
type Problem<V> = { |
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
# This is a version of https://gist.github.com/natekupp/1763661 without | |
# using mutation and with some other simplifications. Hopefully it's slightly | |
# easier to follow. Performance wise - from some small benchmarking - it has | |
# the same O(N) characteristics/memory usage, but is about twice as slow. | |
# | |
# Use it like: | |
# | |
# b = Node([], []) | |
# b = add(b, n) | |
# print(pp(b)) |
OlderNewer