Skip to content

Instantly share code, notes, and snippets.

@swerwath
swerwath / count_types.sh
Created October 7, 2019 22:15
Regex for counting Python type hints in a diff file
grep -o -E '^\+.*(\) ->|[^\W0-9\)]\w*:) [^\W0-9]\w*' <DIFF FILE> | wc -l
@swerwath
swerwath / python_json_types.py
Created September 29, 2019 02:38
JSON type hints for Python
from typing import List, Mapping, Union
JNumber = Union[int, float]
JSON = Union[JNumber, str, bool, None, Mapping[str, 'JSON'], List['JSON']]
@swerwath
swerwath / split_csv.py
Created June 3, 2018 17:15
Split a CSV into training and testing sets
import argparse
import csv
from random import shuffle
parser = argparse.ArgumentParser(description='Randomly splits a CSV\'s rows into two sets')
parser.add_argument('input_path', help='input path of CSV to be split')
parser.add_argument('portion', type=float, help='portion of CSV for the first output')
args = parser.parse_args()
from mpi4py import MPI
comm = MPI.COMM_WORLD # All our nodes in this cluster
rank = comm.Get_rank() # Our node's "ID"
if rank == 0: # If we're the root/base node, we'll be the one distributing the data
data = [1,2,3,4,5]
else:
data = []
@swerwath
swerwath / socket.js
Created August 17, 2016 00:01
Structure of socket.io's Socket object, to depth 3
Socket {
nsp:
Namespace {
name: '/',
server:
Server {
nsps: { '/': [Circular] },
_path: '/socket.io',
_serveClient: true,
_adapter: [Function: Adapter],