Skip to content

Instantly share code, notes, and snippets.

swerwath /
Created Oct 7, 2019
Regex for counting Python type hints in a diff file
grep -o -E '^\+.*(\) ->|[^\W0-9\)]\w*:) [^\W0-9]\w*' <DIFF FILE> | wc -l
swerwath /
Created Sep 29, 2019
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 /
Created Jun 3, 2018
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]
data = []
swerwath / socket.js
Created Aug 17, 2016
Structure of's Socket object, to depth 3
View socket.js
Socket {
Namespace {
name: '/',
Server {
nsps: { '/': [Circular] },
_path: '/',
_serveClient: true,
_adapter: [Function: Adapter],