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
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc. | |
# Initialization code that may require console input (password prompts, [y/n] | |
# confirmations, etc.) must go above this block; everything else may go below. | |
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then | |
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" | |
fi | |
# If you come from bash you might have to change your $PATH. | |
# export PATH=$HOME/bin:/usr/local/bin:$PATH |
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
# mock_process.py | |
"""Make a process single threaded for testing.""" | |
import multiprocessing | |
def f(x): | |
return x | |
def target(): | |
"""Run a process by specifying a target function.""" |
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
# barrier_example.py | |
"""Example usage of barrier.""" | |
import multiprocessing as mp | |
import itertools | |
def worker(barrier:mp.Barrier, q:mp.Queue=None): | |
print(mp.current_process().name, 'waiting') | |
i = barrier.wait() | |
if i == 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
"""Implements an approximate BPE encoding over bytes with some tricks for efficiency. | |
https://arxiv.org/pdf/1508.07909.pdf section 3.2. | |
Basic algorithm from the paper: | |
Initialize the vocab with the character vocabulary | |
Each word is a sequence of characters plus an enod of word symbol '·' | |
Count all symbol pairs | |
Replace each occurence of the most frequent pair ('a', 'b') with 'ab'. | |
Each merge represents a character n-gram |
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
"""Practice implementation of binary search.""" | |
import pytest | |
from typing import Sequence | |
def binary_search(sorted_arr: Sequence[int], target:int) -> int: | |
"""Find the index of target in sorted_arr. | |
Returns: | |
Index of the target or -1 if not found. Picks the first match randomly if there are multiple. |
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
"""Calculate N-gram counts as fast as possible for a large encoded file.""" | |
import numpy as np | |
from collections import deque | |
import multiprocessing as mp | |
from typing import Any, Iterable, Generator | |
import time | |
from collections import Counter | |
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor | |
from functools import partial |
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 requests | |
import re | |
from typing import List, Sequence | |
from collections import Counter | |
import numpy as np | |
TEST_URL = 'http://titan.dcs.bbk.ac.uk/~kikpef01/testpage.html' | |
URL_RE = re.compile(r'href="(http.+?)"') | |
TOKENIZER_RE: re.Pattern = re.compile(r'\w+') |
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
"""Read files using threading and multiprocessing. | |
Execute on https://coderpad.io/sandbox | |
""" | |
from concurrent.futures import ThreadPoolExecutor, as_completed | |
from multiprocessing.dummy import Pool | |
import multiprocessing | |
from collections import Counter | |
import glob |
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
""" | |
TDD solution to: | |
Input: a bunch of times, minutes and seconds, formatted as a single string like: "12:32 34:01 15:23 9:27 55:22 25:56" | |
Output: the sum of the times, hours, minutes, and seconds, formatted as a single string like: "2:32:41" | |
https://github.com/cjdev/interview-preparation | |
https://coderpad.io/sandbox | |
""" | |
import pytest |
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
======================================== SAMPLE 1 ======================================== | |
breakfast," the janitor said. "I'm assuming it's an abundance day so everyone has extra for one coming to go," he added. The cream and butter was nice and fluffy, though I | |
======================================== SAMPLE 2 ======================================== | |
French recipe before I went to college so I've learned a lot here. I'm not going to spend too much time about it, but for those of you who don't, it's a simple | |
======================================== SAMPLE 3 ======================================== | |
meal from New Order for the last few weeks, and don't think that I can take days off." | |
Little did she know, the waiter was among the first to take advantage of both the | |
======================================== SAMPLE 4 ======================================== | |
white pepper cake with my boyfriend. |
NewerOlder