Skip to content

Instantly share code, notes, and snippets.

View mminer's full-sized avatar

Matthew Miner mminer

View GitHub Profile
@mminer
mminer / searchpy.sh
Created January 7, 2014 17:49
Performs a recursive grep search, looking only at Python files. The first argument is the search string, the second on is the directory to search through. Handy when aliased to a command like "searchpy".
#!/bin/bash
grep -r --include='*.py' "$1" ${2:-.}
@mminer
mminer / exportgithubissues.py
Last active August 29, 2015 13:56
Exports a GitHub repository's issues to CSV format.
#!/usr/bin/env python
"""Exports a GitHub repository's issues to CSV format."""
from __future__ import print_function
import argparse
import csv
import getpass
import requests
@mminer
mminer / taghashes.sh
Created November 20, 2014 00:44
Lists a Git repository's tags with their corresponding SHA1 hashes.
#!/usr/bin/env bash
tags="$(git tag --list)"
for tag in $tags; do
hash="$(git rev-list $tag | head -n 1)"
echo "${hash} ${tag}"
done
@mminer
mminer / cmd.py
Created November 20, 2014 22:50
Python function that runs a shell command and returns output as string.
from subprocess import Popen, PIPE
def cmd(*args):
"""Runs a shell command and returns the output as a string."""
out, err = Popen(args, stdout=PIPE, stderr=PIPE).communicate()
# Convert output from byte array to string.
out = out.decode('utf-8')
err = err.decode('utf-8')
@mminer
mminer / dockerpsjson.py
Last active June 4, 2023 11:36
Shell script thats prints the output of `docker ps` in JSON format.
#!/usr/bin/env python3
"""Parses and encodes the result of `docker ps` in JSON format."""
import json
import sys
from collections import namedtuple
from subprocess import Popen, PIPE
@mminer
mminer / gitgraph
Created December 2, 2014 00:48
My preferred Git log format.
git log --graph --all --oneline --decorate
@mminer
mminer / socketadapter.py
Created January 5, 2015 17:30
Connection adapter for Requests that allows it to talk with raw UNIX sockets.
"""
Connection adapter for Requests that allows it to talk with raw UNIX sockets.
Adapted from requests-unixsocket, which itself was adapted from docker-py.
https://github.com/msabramo/requests-unixsocket
https://github.com/docker/docker-py/blob/master/docker/unixconn/unixconn.py
"""
import socket
from urllib.parse import unquote, urlparse
@mminer
mminer / cachedecorator.py
Created January 12, 2015 23:57
An example of a Python decorator to simplify caching a function's result.
"""An example of a cache decorator."""
import json
from functools import wraps
from redis import StrictRedis
redis = StrictRedis()
def cached(func):
@mminer
mminer / postMainThreadNotification.swift
Last active October 18, 2017 04:54
Swift function for posting notifications on main thread.
// NSNotificationCenter isn't thread-safe, so this ensures that notifications are posted on the main thread.
func postMainThreadNotification(notification: Notification) {
DispatchQueue.main.async { NotificationCenter.default.post(notification) }
}
@mminer
mminer / PreferencesViewController.swift
Last active February 5, 2021 19:43
NSTabViewController for preferences window that resizes itself to fit activated tab view.
import AppKit
class PreferencesViewController: NSTabViewController {
private lazy var tabViewSizes: [NSTabViewItem: NSSize] = [:]
override func tabView(_ tabView: NSTabView, didSelect tabViewItem: NSTabViewItem?) {
super.tabView(tabView, didSelect: tabViewItem)
if let tabViewItem = tabViewItem {