Skip to content

Instantly share code, notes, and snippets.

View mminer's full-sized avatar

Matthew Miner mminer

View GitHub Profile
@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 / gitgraph
Created December 2, 2014 00:48
My preferred Git log format.
git log --graph --all --oneline --decorate
@mminer
mminer / Macros.cs
Created May 16, 2011 20:46
Unity editor script to invoke undocumented MacroEvaluator class.
using UnityEditor;
using UnityEditor.Macros;
using UnityEngine;
/// <summary>
/// Allows use of the undocumented MacroEvaluator class. Use at your own risk.
/// </summary>
public class Macros : EditorWindow
{
string macro = "";
@mminer
mminer / showinvisibles.sh
Created May 16, 2011 21:27
Shell script to toggle invisible files in Finder.
#!/bin/bash
STATUS=`defaults read com.apple.finder AppleShowAllFiles`
if [ "$STATUS" = TRUE ]; then
defaults write com.apple.finder AppleShowAllFiles FALSE
else
defaults write com.apple.finder AppleShowAllFiles TRUE
fi
@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 / parentPath.swift
Created September 16, 2016 18:10
Function that walks up directory tree to find given path's parent directory.
func parent(ofPath path: String, levels: Int) -> String {
var parentPath = path
for _ in 1...levels {
parentPath = (parentPath as NSString).deletingLastPathComponent
}
return parentPath
}
@mminer
mminer / homeDirectory.swift
Last active September 17, 2016 19:15
Finds the user's home directory inside a sandboxed Cocoa application.
import Foundation
let homeDirectory: String = {
let home = getpwuid(getuid()).pointee.pw_dir!
return FileManager.default.string(withFileSystemRepresentation: home, length: Int(strlen(home)))
}()
@mminer
mminer / isPortInUse.swift
Last active September 17, 2016 19:33
Determines whether an HTTP port is being used by a process.
import Foundation
func isPortInUse(_ port: Int) -> Bool {
// Use netstat to find ports in use then grep for one we're interested in.
// See this solution for piping shell commands: http://stackoverflow.com/a/16650638
let process = Process()
process.launchPath = "/bin/sh"
process.arguments = ["-c", "netstat -an | grep '\\b\(port)\\b' | grep LISTEN"]
process.standardOutput = Pipe()
process.launch()