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 textwrap | |
import tiktoken | |
from colorama import Back | |
def pprint(enc: tiktoken.Encoding, text: str) -> None: | |
tokens = enc.encode(text) | |
colors = [Back.CYAN, Back.GREEN, Back.LIGHTRED_EX, Back.RED, Back.BLUE] | |
current = [] | |
i, j = 0, 0 |
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 string import ascii_uppercase | |
import pandas as pd | |
import pyarrow as pa | |
strings = pd.Categorical([a + b for a in ascii_uppercase for b in | |
ascii_uppercase]) | |
print(strings) | |
""" |
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 typing import Tuple | |
import numpy as np | |
import polars as pl | |
from numba import njit | |
from pyarrow import fs | |
pl.toggle_string_cache(True) | |
PERPETUALS = {'ALT-PERP', 'HUM-PERP', 'BSV-PERP', 'BNB-PERP', 'LEO-PERP', |
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 subprocess | |
from io import BytesIO | |
import pyarrow as pa | |
def append_format(query: str) -> str: | |
sans_semicolon = query.rstrip(" ;") # trim spaces + semi-colons | |
return sans_semicolon + " FORMAT ArrowStream;" |
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
static void switchStatement() { | |
consume(TOKEN_LEFT_PAREN, "Expect '(' after 'switch'."); | |
expression(); | |
consume(TOKEN_RIGHT_PAREN, "Expect ')' after expression."); | |
consume(TOKEN_LEFT_BRACE, "Expect '{' before cases."); | |
int jumpAfter = -1; | |
int jumpBefore = -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 polars as pl | |
from pyarrow import fs | |
trades = pl.read_parquet('crypto-exchange-pds/ftx-trades/', | |
filesystem=fs.S3FileSystem(), | |
filters=[[('ds', '>=', '2021-10-24'), ('ds', '<=', '2021-10-31')]], | |
columns=['market', 'time', 'id', 'price', 'size']) | |
trades['market'] = trades.market.cast(pl.datatypes.Categorical) |
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 string import ascii_uppercase | |
import numpy as np | |
import polars as pl | |
N = 5 # N > 4 to break to_parquet/read_parquet | |
# for smaller N, categories need to be multiple characters | |
cats = [a + b for a in ascii_uppercase for b in ascii_uppercase][:N] |
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
class Point { init(x, y) { this.x = x; this.y = y; } } | |
class LinkedList { | |
init(item, tail) { | |
this.item = item; | |
this.tail = tail; | |
} | |
class prepend(item, list) { | |
return LinkedList(item, list); |
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
def symmetric_difference(a: set, b: set) -> set: | |
return {elt for elt in a | b if (elt in a) ^ (elt in b)} | |
symmetric_difference({'bread', 'butter'}, {'bread', 'jam'}) | |
# {'butter', 'jam'} | |
{'bread', 'butter'} ^ {'bread', 'jam'} | |
# {'butter', 'jam'} |
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
{'bread'} < {'bread', 'butter'} | |
# True | |
{'bread'} < {'bread'} | |
# False |
NewerOlder