View creating_a_new_stack_project_in_haskell.md

Creating a new Stack Project in a Nix Shell

There are so many different ways of building and maintaining Haskell projects.

I'm going to talk about using nix-shell and stack.

First you want a ~/.stack/config.yaml:

 local-bin-path: /home/USERNAME/.stack/bin
View transpose.py
l = [
[1,2,3,4],
[5,6,7,8],
[9,10,11,12]
]
# the result shape will always produce from shortest row
lt = list(map(list, zip(*l)))
# [
View join_shell_array_with_separator.sh
#!/usr/bin/env bash
text=(
'a'
'b'
)
IFS=: eval 'text="${text[*]}"'
echo "$text" # a:b
View argparse_verbose_count.py
import argparse
import logging
def verbose_to_loglevel(c):
loglevel = logging.WARNING
if c == 1:
loglevel = logging.INFO
elif c >= 2:
loglevel = logging.DEBUG
View conversion_between_coordinate_origins.md

Conversion between Coordinate Origins

  • T - Top
  • B - Bottom
  • L - Left
  • R - Right

Remember that images loaded into a matrix uses the height as rows and width as columns. So x,y coordinates are flipped y,x to get i,j coordinates.

Subpixel Coordinates

View sample_reservoir.py
import random
def sample_reservoir(size, samples):
reservoir = [None] * size
k = size - 1
for i in range(size):
reservoir[i] = samples[i]
for i in range(k + 1, len(samples)):
j = random.randint(0, i)
if j <= k:
View jumpdir.py
import os
import contextlib
@contextlib.contextmanager
def jumpdir(path):
old_dir = os.getcwd()
os.chdir(path)
try:
yield
View resolve_mask_occlusions.py
from sortedcontainers import SortedDict
def resolve_mask_occlusions(mask, z_index):
if (len(mask.shape) != 3 or mask.shape[2] != len(z_index)):
raise TypeError('Mask shape depth must match the z_index')
z_index_map = SortedDict()
for mask_index, mask_depth in enumerate(z_index):
if mask_depth in z_index_map:
z_index_map[mask_depth].append(mask_index)
else:
View python_setuptools.md

Python Setuptools

Python setuptools package replaces the distutils package. You use this in order to allow your Python package to be redistributable. Not just for PyPi but also for source distributions or private distributions.

First you need a setup.py at your project root:

View Draw Shape and Masks.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.