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 / 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
@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 / 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 / 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.
#!/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 / 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));
#==============================================================
# .picasa.ini FILE STRUCTURE
#
# reverse-engineered by Franz Buchinger <[email protected]>
# licensed to the public domain
#
# Picasa Version(s): 3.8.0
#
# Changelog:
# v0.1: initial release
@inactivist
inactivist / flask_pymongo_retry_on_reconnect_error.py
Created February 19, 2014 05:10
Simple decorator for flask and mongoengine/pymongo to auto-retry with delay on pymongo.errors.AutoReconnect exception in a view or other function
"""
Simple view decorator for flask and mongoengine/pymongo to auto-retry with delay on
pymongo.errors.AutoReconnect exception.
"""
from functools import wraps
import time
from pymongo.errors import AutoReconnect
import flask
@inactivist
inactivist / is_heroku.py
Created July 15, 2014 11:35
is_heroku: Q&D method to detect running on Heroku container.
import os
def is_heroku():
"""Hack to return true if we're running inside a Heroku container.
Tested on Cedar stack.
"""
return os.environ.get('PYTHONHOME', '').find('.heroku') != -1
@inactivist
inactivist / cffi_to_dict.py
Last active March 15, 2023 15:21
Convert CFFI cdata structure to Python dict.
"""
Convert a CFFI cdata structure to Python dict.
Based on http://stackoverflow.com/q/20444546/1309774 with conversion of
char[] to Python str.
Usage example:
>>> from cffi import FFI
>>> ffi = FFI()