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 sys | |
import io | |
def _text_encoding(encoding, stacklevel=2, /): # pragma: no cover | |
return encoding | |
try: | |
text_encoding = io.text_encoding |
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
const d6 = () => String.fromCodePoint(0x2680 + Math.floor(Math.random() * 6)) | |
function d6() { | |
const faceIdx = Math.floor(Math.random() * 6); | |
const codePoint = 0x2680 + faceIdx; | |
return String.fromCodePoint(codePoint) | |
} |
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
body { | |
background-size: 40px 40px; | |
background-image: | |
linear-gradient(to right, lightblue 1px, transparent 1px), | |
linear-gradient(to bottom, lightblue 1px, transparent 1px); | |
} |
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 math | |
def entropy(vec): | |
norm = sum(vec) | |
p = (x / norm for x in vec) | |
return -sum(p_k * math.log(p_k) for p_k in p if p_k) | |
import numpy as np | |
def entropy(p): |
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
function stringTruncator (numChars, buffer) { | |
buffer = buffer || 3 | |
return function (str) { | |
return function (str) { | |
let cutoff = str.slice(0, numChars).lastIndexOf(' ') | |
if (cutoff === -1) cutoff = numChars | |
str = str.slice(0, cutoff) + '…' | |
} | |
return str | |
} |
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 collections import namedtuple | |
DataRow = namedtuple('DataRow', ['header', 'data']) | |
def flatten_botometer_result(result): | |
''' | |
Flattens a botometer response object. | |
Parameters: | |
result: A botometer result object |
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
#!/bin/bash | |
set -uo pipefail | |
IFS=$'\n\t' | |
if [[ $# -eq 0 ]]; then | |
echo "usage: $0 <target_directory>" | |
exit 1 | |
fi | |
TARGET_DIR=$1 |
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
def lrange_iter(r, key, N_max=None, step=10**5): | |
if N_max is None: | |
starts = itertools.count(step=step) | |
else: | |
starts = range(0, N_max, step) | |
for start in starts: | |
end = start + step - 1 | |
if N_max is not None: | |
end = min(end, N_max - 1) |
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 math | |
from collections import namedtuple | |
def haversine_distance(origin, destination): | |
""" Haversine formula to calculate the distance between two lat/long points on a sphere """ | |
radius = 6371 # FAA approved globe radius in km | |
dlat = math.radians(destination.lat-origin.lat) | |
dlon = math.radians(destination.lng-origin.lng) |
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
''' | |
(c)2016 Clayton A Davis | |
''' | |
import itertools | |
import random | |
import time | |
from html.parser import HTMLParser | |
from urllib.parse import urlparse, urljoin, unquote |
NewerOlder