Skip to content

Instantly share code, notes, and snippets.

devforfu

Block or report user

Report or block devforfu

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@devforfu
devforfu / example.py
Last active Aug 25, 2019
Catalyst example. (Doesn't work as expected).
View example.py
import os
import re
from pdb import set_trace
from multiprocessing import cpu_count
from pprint import pprint as pp
from imageio import imread
import numpy as np
import pandas as pd
import PIL.Image
@devforfu
devforfu / concat_and_make_cli.py
Last active Jul 2, 2019
Converting function signature into CLI
View concat_and_make_cli.py
import argparse
from pathlib import Path
import signature
def concat(folder: str, output: str = 'concat.txt', include_names: bool = True):
"""Concatenates a list of files from a folder and saves them into a single file."""
p = Path(folder)
files = []
for filename in p.iterdir():
@devforfu
devforfu / parsing_signature.py
Last active Jun 30, 2019
Construct CLI from a signature
View parsing_signature.py
import argparse
import signature
def make_cli(func: callable):
parser = argparse.ArgumentParser()
sig = inspect.signature(func)
empty = inspect._empty
for param in sig.parameters.values():
annot = param.annotation
@devforfu
devforfu / ancli.py
Last active Jul 1, 2019
Converting function into CLI
View ancli.py
from pathlib import Path
def concat(folder: str, output: str = 'concat.txt', include_names: bool = True):
"""Concatenates a list of files from a folder and saves them into a single file."""
p = Path(folder)
files = []
for filename in p.iterdir():
content = filename.open('r').read().strip()
if include_names:
content = f'{filename}\n{content}\n'
@devforfu
devforfu / sample_test.py
Last active Mar 19, 2019
An illustrative snippet for the blog post
View sample_test.py
import pytest
@pytest.mark.parametrize('state', [
'ooo|x.x|..x',
'xo.|xo.|x..',
'x..|.xo|o.x'
])
def test_game_has_winner(state):
game = Game(state)
assert game.has_winner()
View xx_final.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View xx_final.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@devforfu
devforfu / gendata.py
Created Mar 6, 2019
A simple random dataset generating script
View gendata.py
def generate_dataset(n_rows, num_count, cat_count, max_nan=0.1, max_cat_size=100):
"""Randomly generate datasets with numerical and categorical features.
The numerical features are taken from the normal distribution X ~ N(0, 1).
The categorical features are generated as random uuid4 strings with
cardinality C where 2 <= C <= max_cat_size.
Also, a max_nan proportion of both numerical and categorical features is replaces
with NaN values.
"""
@devforfu
devforfu / cursed.py
Created Feb 16, 2019
An illustration of the debugging issues when using curses
View cursed.py
import curses
def main(term):
term.clear()
for i in range(10):
# try to debug after curses mangled the terminal
breakpoint()
term.addstr(i, 0, f'String: {i + 1:d}')
term.refresh()
term.getkey()
View example_click.py
from itertools import chain
import click
import matplotlib.pyplot as plt
from matplotlib import rcParams
default_style = {
'font.family': 'monospace',
'font.size': 18,
'figure.figsize': (8, 6)
You can’t perform that action at this time.