Skip to content

Instantly share code, notes, and snippets.

View jaymody's full-sized avatar
🙈
ignoring bugs

Jay Mody jaymody

🙈
ignoring bugs
View GitHub Profile
@jaymody
jaymody / p10k.zsh
Created April 14, 2020 16:47
powerlevel10k configuration for a powerline-like theme from bash-it.
######## temp setup ########
'builtin' 'local' '-a' 'p10k_config_opts'
[[ ! -o 'aliases' ]] || p10k_config_opts+=('aliases')
[[ ! -o 'sh_glob' ]] || p10k_config_opts+=('sh_glob')
[[ ! -o 'no_brace_expand' ]] || p10k_config_opts+=('no_brace_expand')
'builtin' 'setopt' 'no_aliases' 'no_sh_glob' 'brace_expand'
######## main ########
() {
######## colors ########
@jaymody
jaymody / tqdm_reset.py
Created May 27, 2020 17:54
Resetting/fixing multiline tqdm output without having to restart a jupyter notebook.
# source - https://stackoverflow.com/a/61230293/11070463
#
# Often, i'll be working in on a jupyter notebook and an error/bug will
# interrupt the execution of something that was wrapped with the tqdm
# function. This has the annoying side effect where your next tqdm call
# will be multilined. To fix this, you can the below two lines of code
# and it'll be fixed! (if tqdm gets interrupted again, you'll have the
# run these two lines again).
while len(tqdm._instances) > 0:
tqdm._instances.pop().close()
@jaymody
jaymody / data.py
Last active November 3, 2020 19:00
Combining varying datasets into a single consistent schema for Fake News Detection. A great example of inheritance and other neat OOP python features.
"""Data classes and loading functions."""
import os
import glob
import json
import shutil
import logging
import collections
import multiprocessing
import bs4
@jaymody
jaymody / get_send.py
Created March 4, 2021 20:43
Get and send data asyncio queue.
import asyncio
from queue import Queue
q = asyncio.Queue()
async def get_data():
while True:
await asyncio.sleep(0.5) # simulate work
print("receiving:", await q.get())
@jaymody
jaymody / broadcast.py
Last active March 14, 2021 15:59
NumPy operations profiling.
import timeit
import numpy as np
def broadcast():
a = np.random.random(256)
b = np.random.random((2048, 256))
return timeit.timeit(lambda: a - b, number=1000)
import statistics
import seaborn as sns
import matplotlib.pyplot as plt
def stats(values, plot=False):
# statistics.mode throws an error if there are multiple modes
try:
mode = statistics.mode(values)
class Tokenizer:
"""Tokenizes text into tokens and sequence of tokens.
token (str)
the smallest divisable component in a tokenization model
seq (list of str)
a sequence of tokens that encodes some meaning as an ordered (or
unordered) collection
text (str)
a string that can be broken down into a seq
@jaymody
jaymody / main.py
Created August 18, 2021 02:49
A simulation for the TedEd frog riddle: https://www.youtube.com/watch?v=cpwSGsb-rTs
import random
N = 1000000 # number of frogs of each gender
assert N >= 2 # there must be at least 2 frogs of each gender
frogs = ["M"] * N + ["F"] * N
max_num_simulations = 2000000 # number of simulations to run
num_simulations = 0
num_clearing_successes = 0
@jaymody
jaymody / shopify-ds-intern-challenge.ipynb
Last active September 16, 2021 17:37
Shopify DS Intern Challenge
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jaymody
jaymody / main.rs
Created November 23, 2021 21:16
map, reduce, filter, forall, count, group_by in Rust
use std::collections::HashMap;
use std::hash::Hash;
fn map<A, B, F>(l: &Vec<A>, f: F) -> Vec<B>
where
F: Fn(&A) -> B,
{
let mut result = Vec::new();
for e in l.iter() {
result.push(f(e));