Skip to content

Instantly share code, notes, and snippets.

@swerwath
swerwath / count_types.sh
Created Oct 7, 2019
Regex for counting Python type hints in a diff file
View count_types.sh
grep -o -E '^\+.*(\) ->|[^\W0-9\)]\w*:) [^\W0-9]\w*' <DIFF FILE> | wc -l
@swerwath
swerwath / python_json_types.py
Created Sep 29, 2019
JSON type hints for Python
View python_json_types.py
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 Jun 3, 2018
Split a CSV into training and testing sets
View split_csv.py
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()
View MPI_map.py
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 Aug 17, 2016
Structure of socket.io's Socket object, to depth 3
View socket.js
Socket {
nsp:
Namespace {
name: '/',
server:
Server {
nsps: { '/': [Circular] },
_path: '/socket.io',
_serveClient: true,
_adapter: [Function: Adapter],