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
""" | |
Given a set of file names, line numbers, and lines of text in `grep -n` format, | |
update the file with altered text. | |
Suppose you have added a bunch of lines of code to your code base that have double | |
quotes when it is your company practice to use single quotes. When you are cleaning | |
up your code for a pull-request, you find all the changes with double quotes, | |
drop extraneous lines, change all the double quotes to single quotes in the | |
grep output, and use this python code to apply changes to your files. |
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 functools import wraps | |
try: | |
from functools import lru_cache | |
except ImportError: | |
def lru_cache(user_function): | |
cache = {} | |
@wraps(user_function) | |
def wrapper(*args): | |
key = tuple(args) |
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 pandas as pd | |
df = pd.DataFrame({ | |
'date': list(range(20)), | |
'value': list(reversed(range(20))), | |
'series_id': [1, 2, 3, 4] * 5, | |
}) | |
gr = df.groupby(["series_id"]) | |
hist = { |
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 logging | |
import os | |
import os.path | |
import re | |
from itertools import tee, izip | |
re_class_start = re.compile(r'^class\s+(?P<name>[^(]+).*$') | |
re_func_start = re.compile(r'^\s*def\s+(?P<name>[^(]+).*$') | |
re_patch_start = re.compile(r'^.*patch.*\.start\(.*$') |
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
#!/bin/bash | |
[[ $UID == 0 ]] || { echo "run as sudo to install"; exit 1; } | |
REPO="https://github.com/BurntSushi/ripgrep/releases/download/" | |
RG_LATEST=$(curl -sSL "https://api.github.com/repos/BurntSushi/ripgrep/releases/latest" | jq --raw-output .tag_name) | |
RELEASE="${RG_LATEST}/ripgrep-${RG_LATEST}-x86_64-unknown-linux-musl.tar.gz" | |
TMPDIR=$(mktemp -d) | |
cd $TMPDIR | |
wget -O - ${REPO}${RELEASE} | tar zxf - --strip-component=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
#!/bin/sh | |
# Cat a JSON file and send it as the data argument to curl in a | |
# POST request to DataRobot prediction API | |
cat <JSON-FILE> | | |
curl -H "Content-Type: application/json" \ | |
-X POST -d @- \ | |
-u <USER-NAME>:<API-KEY> \ | |
http://<HOST>/predApi/v1.0/<PROJECT-ID>/<MODEL-ID>/predict |
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 | |
""" | |
Python module to create and diff checkpoints on mongo databases. | |
""" | |
import logging | |
# import json | |
from uuid import uuid4 | |
from pprint import pprint | |
from datetime import datetime # pylint: disable=unused-import |
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
#!/bin/sh | |
# Based on: | |
# http://anbasile.github.io/programming/2017/06/25/jupyter-venv/ | |
mkvirtualenv --python=`which python3` ADRPython | |
workon ADRPython | |
pip3 install \ | |
jupyter jupyterlab jupyterthemes \ | |
scipy \ |
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 numberToBase(n, b): | |
def _divmod(n, b): | |
while n: | |
n, q = divmod(n, b) | |
yield q | |
return [0] if not n else list(reversed(list(_divmod(n, b)))) |
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 | |
""" | |
git-bisect code for PRED-1765 | |
""" | |
import os | |
import os.path | |
import sys | |
import subprocess | |
import logging | |
from datetime import datetime |