This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import groupby | |
def cumulative(arr): | |
return [arr[i] - arr[i - 1] for i in range(1, len(arr))] | |
def stable_particle(arr): | |
""" | |
>>> stable_particle([-1, 1, 3, 3, 3, 2, 3, 2, 1, 0]) | |
5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List | |
from random import randint | |
def findMedianSortedArrays(nums1: List[int], nums2: List[int]) -> float: | |
n1: int = len(nums1) | |
n2: int = len(nums2) | |
if n1 > n2: | |
return findMedianSortedArrays(nums2, nums1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reimplementation of tfidf.py here: | |
# https://gist.github.com/sloria/6407257 | |
from math import log | |
from collections import Counter | |
class TFIDF(object): | |
def __init__(self, corpus): | |
self.corpus = corpus | |
self.ndocs = len(corpus) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on this repository of coronavirus data: | |
# git clone [email protected]:nytimes/covid-19-data.git | |
from csv import DictReader | |
from collections import defaultdict | |
from pprint import pprint | |
# fields = ['date', 'state', 'cases', 'deaths'] | |
# Selecting on 'cases' gives results that appear influenced by testing. | |
# Using 'deaths' appears less influenced by noise and human factors, in my opinion. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def load(): | |
with open("config/create_index.js") as handle: | |
data = [line.rstrip() for line in handle] | |
coll_iter = (line.split('.') for line in data) | |
return [ | |
(i, coll[0] + '.' + coll[1]) | |
for i, coll in enumerate(coll_iter) | |
if len(coll) >= 2 and coll[0] == 'db' | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os.path | |
from csv import DictReader | |
datafile = os.path.normpath(os.path.expanduser("~/workspace/DataRobot/tests/testdata/10k_diabetes.csv")) | |
with open(datafile) as handle: | |
reader = DictReader(handle) | |
fields = reader.fieldnames | |
rows = list(reader) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from queue import Queue | |
from pprint import pprint | |
def neighbors(coord): | |
x, y = coord | |
return { | |
(x - 1, y), | |
(x + 1, y), | |
(x, y - 1), | |
(x, y + 1), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
class SedFile(object): | |
def __init__(self, filename): | |
self.filename = filename | |
self.modified = False | |
with open(self.filename, "r") as handle: | |
self.data = [line.rstrip() for line in handle] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""Resolve where some test fixture lives | |
Provides CLI: | |
* start -- location in tree of directories to start | |
* resolve -- resource to resolve | |
""" | |
from glob import glob |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""Resolve where some test fixture lives | |
Provides CLI: | |
* start -- location in tree of directories to start | |
* resolve -- resource to resolve | |
""" | |
from glob import glob |