Skip to content

Instantly share code, notes, and snippets.

View inactivist's full-sized avatar
💭
fixing things

Michael Curry inactivist

💭
fixing things
View GitHub Profile
@inactivist
inactivist / shingles.js
Last active April 5, 2018 19:14
Generate w-shingles from a string or array in JavaScript. https://en.wikipedia.org/wiki/W-shingling
/**
* Make w-shingles from a source string or array.
* @param {string} collection The collection (array or string) to shingle.
* @param {string} size The shingle size (4 for 4-shingles, etc.)
* @return {array} An array of shingles.
*/
function shingle(collection, size) {
var shingles = [];
for (var i=0; i<collection.length-size+1; i++) {
shingles.push(collection.slice(i, i+size));
#!/bin/bash
set -o errexit
# Author: David Underhill
# Version: 1.0 (01-Apr-2009)
# Script to permanently delete files/folders from your git repository. To use
# it, cd to your repository's root and then run the script with a list of paths
# you want to delete, e.g., git-delete-history path1 path2
if [ $# -eq 0 ]; then
@inactivist
inactivist / myip.py
Last active December 25, 2015 13:19
Request the current 'external' (Internet-facing) IP address as reported by http://httpbin.org/io and send it to stdout. Useful if you are running on a 'net connection with a non-static IP address. This probably won't do much for you if you're behind a proxy.
#!/usr/bin/env python
"""
Get the 'external' IP address using httpbin.org JSON API.
(http://httpbin.org/ip)
Author: Michael Curry (thatmichaelcurry [at] gmail)
Requires requests 2 or higher.
@inactivist
inactivist / lps.py
Last active December 16, 2015 02:39
"Quick and dirty" Python script for counting the lines per second pulled from stdin.
#!/usr/bin/python
"""Print stats about stdin per-line timings."""
import signal
import sys
import time
start = time.time()
count = 0
try:
@inactivist
inactivist / tweepy_raw_response_json.py
Last active December 26, 2020 12:11
How to get the raw Twitter API JSON response from a Tweepy request. It provides a simple way to stash the parsed API request results for later use. It stores the parsed JSON in a _payload field in the returned API results, which can then be iterated over. Not as clean as I'd like, but it allows me to leverage all of Tweepy's API methods and stil…
"""
Taken from my suggestion at:
https://groups.google.com/forum/#!msg/tweepy/OSGRxOmkzL4/yaNT9fL9FAIJ
Note that this is an incomplete snippet; you'll need to create the API auth object.
"""
import simplejson as json
import tweepy
@inactivist
inactivist / git-subdir-newrepo.sh
Created December 5, 2012 21:48
Move a subdir from an existing repository into a new repository.
#!/bin/bash
# Extract a subproject's master branch from a specified repo into a new
# repository in the target directory, preserving history.
# usage: git-subdir-newrepo.sh path/to/repo newrepo_path subproject_path
# Based on stuff I found here:
# http://airbladesoftware.com/notes/moving-a-subdirectory-into-a-separate-git-repository
EXPECTED_ARGS=3
E_BADARGS=65