Skip to content

Instantly share code, notes, and snippets.

@rhowardiv
rhowardiv / cack
Created March 16, 2012 13:41
ack + context for php
#!/bin/bash
# A wrapper for ack to provide context for results; i.e. name of surrounding function or class
# context regex: match lines that qualify as "context"
# this could certainly be improved but it's okay for now
CONT='\<function\>.*(\|\<class\s\+[a-zA-Z_]\+'
proceed() {
while read LINE; do
@rhowardiv
rhowardiv / pr
Created March 26, 2012 16:26
examine pull requests nicely in vim
#!/bin/bash
# Examine a pull request!
# Usage: $0 <github username> <branch name> OR $0 <pull request #>
# TODO: move to env?
MY_GH_USER=rhowardiv
MY_GH_PASS=XXXXXXXX
GH_REPO=AYI
@rhowardiv
rhowardiv / gist:2727118
Created May 18, 2012 19:14
jshint all the files I've touched
git log --name-status | gawk '/Richard Howard/{c = 1} /^commit/{c = 0} /^M |^A /{ if (c == 1) print $2 }' | grep '.js$\|.html$' | uniq | while read F; do if [ -f "$F" ]; then jshint "$F" --config=~/.jshintrc; fi; done
@rhowardiv
rhowardiv / rpr.sh
Last active October 11, 2015 20:08
Get a random PR checker
#!/bin/bash
# Get a random PR checker
# Loops through everyone before showing the same name twice
ME=rhoward
# Takes optional argument for commit group if you want not from "ALL"
COMMIT_GROUP="ALL"
if [ $# -gt 0 ]; then
COMMIT_GROUP="$1"
@rhowardiv
rhowardiv / gist:4197652
Created December 3, 2012 20:11
PHP magic __get only allows itself on the stack once per property
<?php
class Dumb {
protected $prop;
function __get($p) {
if ($p === 'prop') {
$this->prop = new Dumber($this);
return $this->prop;
}
}
}
@rhowardiv
rhowardiv / gist:7142092
Last active December 26, 2015 11:09
Add length sorting to selecta inputs
$ git diff HEAD^
diff --git a/vimrc b/vimrc
index cada33f..18f0b56 100644
--- a/vimrc
+++ b/vimrc
@@ -275,15 +275,15 @@ endfunction
" Find all files in all non-dot directories starting in the working directory.
" Fuzzy select one of those. Open the selected file with :e.
-nnoremap <leader>f :call SelectaCommand("find * -type f \| lsort", "", ":e")<cr>
@rhowardiv
rhowardiv / syncdaemon
Created September 7, 2012 20:04
remote file sync for Mac
#!/bin/bash
LOG=/tmp/sync.log
SELF=$(basename "$0")
usage() {
echo
echo "Usage: $SELF LOCALDIR REMOTEDIR"
echo "Syncs files in LOCALDIR to REMOTEDIR"
echo "Daemonize this yourself with & or nohup"
@rhowardiv
rhowardiv / pyfunclen.py
Last active October 28, 2016 18:09
Count lines in python functions
#!/usr/bin/env python
"""
Count lines in python functions
"""
import re
def funcs_lengths(lines):
"""
Loop through lines and yield (function name, line length)
@rhowardiv
rhowardiv / dd-log-export.bash
Created August 5, 2019 13:32
Datadog log export -- approach not viable due to rate limit (300 reqs/h)
#!/bin/bash
set -e
if [[ -z "$DD_APP_KEY" ]]; then
echo "I expect the Datadog app key in DD_APP_KEY"
exit
fi
if [[ -z "$DD_API_KEY" ]]; then
echo "I expect the Datadog API key in DD_API_KEY"
exit
@rhowardiv
rhowardiv / ppt.sh
Created October 9, 2012 19:23
powerpoint in bash
#!/bin/bash
usage() {
echo "Interactively show slides from a file"
echo
echo "Usage:"
echo "$0 FILE LINES"
echo
echo "FILE is the file containing the slides."
echo "In the file, each slide is indicated with a simple 'slide' by itself"