Skip to content

Instantly share code, notes, and snippets.

Lucas Wiman lucaswiman

Block or report user

Report or block lucaswiman

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
View cv2_noise.py
import numpy as np
import cv2
def sp_noise(image, prob):
'''
Add salt and pepper noise to image
prob: Probability of the noise
'''
output = image.copy()
View threaded_map.py
from typing import Callable, Iterable, T
from multiprocessing.pool import ThreadPool
def threaded_map(f: Callable[..., T], it: Iterable, num_threads: int) -> Iterable[T]:
pool = ThreadPool(num_threads)
try:
results = pool.map(f, it)
finally:
pool.close()
@lucaswiman
lucaswiman / field-serialize.py
Created Jul 18, 2018
Serialize/deserialize from a django model field.
View field-serialize.py
class _Stub(object):
pass
def serialize(model_class, field_name, value):
field = model_class._meta.get_field(field_name)
obj = _Stub()
setattr(obj, field.attname, value)
return field.value_to_string(obj)
View jsonpatch-trigger.sql
DROP TABLE IF EXISTS mytable;
DROP TABLE IF EXISTS mytable_patches;
CREATE TABLE mytable(
id SERIAL PRIMARY KEY,
data JSON
);
CREATE TABLE mytable_patches(
id SERIAL PRIMARY KEY,
@lucaswiman
lucaswiman / runtime_union.py
Last active Jun 25, 2017
It is hard to use Union in runtime type checks
View runtime_union.py
>>> type(Union[int, str])
typing.Union
>>> type(Union[int, str]) == Union
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/lucaswiman/.pyenv/versions/3.6/lib/python3.6/typing.py", line 760, in __eq__
return self._subs_tree() == other
File "/Users/lucaswiman/.pyenv/versions/3.6/lib/python3.6/typing.py", line 760, in __eq__
return self._subs_tree() == other
File "/Users/lucaswiman/.pyenv/versions/3.6/lib/python3.6/typing.py", line 760, in __eq__
@lucaswiman
lucaswiman / .sh
Created Jun 10, 2017
grep co-occurrences
View .sh
function git-co-occurrences() {
pattern1="$1"
pattern2="$2"
comm -12 <(git grep -E "$pattern1" | cut -d ':' -f1 | sort | uniq) <(git grep -E "$pattern2" | cut -d ':' -f1 | sort | uniq)
}
@lucaswiman
lucaswiman / Ties+regular+expression.ipynb
Created Mar 11, 2017
Playing with a regular language for tying ties.
View Ties+regular+expression.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View Dockerfile
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get -y install apt-utils
RUN apt-get -y install git
RUN git clone https://github.com/pygraphviz/pygraphviz.git /root/pygraphviz
RUN apt-get -y install build-essential
RUN apt-get -y install python
RUN apt-get -y install python-dev
RUN apt-get -y install python-setuptools
RUN apt-get -y install autoconf
View bubble-generator.tcl
canvas .c -bg white
# Graphs:
#
set all_graphs {
sql-stmt-list {
toploop {optx sql-stmt} ;
}
sql-stmt {
line
View gist:9bd35274c1899242c3f3e30dc97c112b
rm *.png; /usr/local/bin/gs -sDEVICE=png16m -r600 -o page-%03d.png example.pdf
You can’t perform that action at this time.