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 / 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)
View example_docopt.py
"""
Scatter plots generator.
Usage:
scatter <filename> <X> <Y> (<X> <Y>)...
"""
from itertools import chain
import docopt
import matplotlib.pyplot as plt
View example_fire.py
import fire
import matplotlib.pyplot as plt
from matplotlib import rcParams
default_style = {
'font.family': 'monospace',
'font.size': 18,
'figure.figsize': (8, 6)
}
@devforfu
devforfu / argparse_plotter.py
Last active Feb 11, 2019
Argparse final version with all tips and tricks
View argparse_plotter.py
"""plotter.py generates simple plots configured from standard input or JSON.
A user is required to provide list of points to be plotted and canvas
parameters to define image rendering style properties.
examples:
$ python plotter.py stdin -p '1,2;2,3'
$ python plotter.py stdin -p '1,1;2,2;3,3' -o plot -f svg --show-grid
$ python plotter.py json -j path/to/the/config.json
"""
@devforfu
devforfu / argparse_subcommands.py
Last active Feb 11, 2019
Argparse subcommands
View argparse_subcommands.py
from argparse import ArgumentParser, ArgumentError, ArgumentTypeError
from functools import partial
import json
from os.path import exists
import matplotlib.pyplot as plt
def main():
parser = create_parser()
args = parser.parse_args()
You can’t perform that action at this time.