This file contains 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 re | |
def sanitize(regex): | |
if regex.startswith('r"'): | |
regex = regex[2:] | |
elif regex.startswith('"'): | |
regex = regex[1:] | |
if regex.endswith('"'): | |
regex = regex[:-1] | |
return regex |
This file contains 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 json | |
def json_load(path: str) -> dict: | |
if not path: | |
return {} | |
try: | |
with open(path, 'r') as p: | |
return json.load(p) # expect dict | |
except (FileNotFoundError, json.decoder.JSONDecodeError) as e: | |
print(f"[WARNING] No recipients discovered. Reason: {e}") |
This file contains 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
<!-- On Squarespace config --> | |
<!-- In your blog post (text section), make an "insert point" (teardrop on the side) and choose code block. --> | |
<!-- In the code block on the top right, select "Markdown" display (but don't click on Display source checkmark) --> | |
<!-- Place footnote like below - populate slug https://support.squarespace.com/hc/en-us/articles/205814578: --> | |
A very long blog post, please see minor point[<div id="footnote-1-back"><sup>1</sup></div>](my_site.com/slug/#footnote-1) | |
A second but more major point[<div id="footnote-2-back"><sup>2</sup></div>](my_site.com/slug/#footnote-2) | |
This file contains 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 python3 | |
import argparse | |
import random | |
def main(path, samplesize): | |
""" | |
Prints random samples in order of selection. |
This file contains 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
https://superuser.com/a/752510 |
This file contains 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
curl -s -o /dev/null -w "%{http_code}" http://cuonly.cs.cornell.edu/ | grep -q 200 || sudo vpnc-connect |
This file contains 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 python3 | |
# coding: utf-8 | |
import pandas as pd | |
import sys | |
import os | |
# pass in infile and CMSX assignment name as commandline args | |
if len(sys.argv) < 3: | |
print("Usage: python3 {}".format(os.path.basename(__file__))\ |
This file contains 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
du -cha --max-depth=2 /home/ | grep -E "M|G" | sort -rh |
This file contains 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 sklearn.model_selection import KFold | |
from sklearn.base import clone | |
def cross_validate(features, labels, nsplits, model): | |
'''Returns tuple of (scores : list, average_score : float) over K folds. | |
Keyword arguments: | |
nsplits : int -- the number of folds to perform cross validation on. | |
model -- an object that is the model for CV. Assumes fit() and score() methods, | |
akin to sklearn model APIs. | |
features : pandas.DataFrame -- a Pandas DataFrame containing preprocessed training data features. |
This file contains 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
''' | |
Get full human-readable labels for Android permissions. | |
Run `adb shell pm list permissions -g -f > permissions_dump.txt` on an Android device, | |
then run this Gist to convert to pandas-friendly CSV. | |
''' | |
from rsonlite import simpleparse | |
import pandas as pd | |
OUTFILE = 'android_permissions.csv' | |
def permission_labels(permissions_dumpfile): | |
print('Parsing permissions dumpfile...') |
NewerOlder