Skip to content

Instantly share code, notes, and snippets.

View mpdaugherty's full-sized avatar

Michael Daugherty mpdaugherty

View GitHub Profile
@mpdaugherty
mpdaugherty / listBranches.sh
Created October 6, 2023 13:25
View local git branches ahead/behind of main
#!/bin/bash
for branch in $(git branch | sed 's/* //'); do
ahead=$(git log --oneline main..$branch | wc -l | tr -d ' ');
behind=$(git log --oneline $branch..main | wc -l | tr -d ' ');
printf "+%5s, -%5s : %s\n" "$ahead" "$behind" "$branch";
done
@mpdaugherty
mpdaugherty / url2png-v6.php
Created September 24, 2012 08:49 — forked from url2png/url2png-v6.php
v6 Examples
<?php
function url2png_v6($url, $args) {
# Get your apikey from http://url2png.com/plans
$URL2PNG_APIKEY = "PXXXX";
$URL2PNG_SECRET = "SXXXX";
# urlencode request target
$options['url'] = urlencode($url);
@mpdaugherty
mpdaugherty / plain_text_utils.py
Created July 12, 2012 00:50
plain text indent django template tag
from django import template
register = template.Library()
@register.filter(name='indent')
def indent_string(val, num_spaces=4):
return val.replace('\n', '\n' + ' '*num_spaces)
@mpdaugherty
mpdaugherty / right_radios.html
Created July 7, 2012 06:23
Example of how to correctly use radio inputs with Angular JS's ng:Repeat directive
<div ng-repeat="m in milestone_choices" class="row-fluid">
<label><input type="radio" name="meaningless" value="(( $index ))" ng-model="milestone_data.index" />
&nbsp;<span ng-bind="m.title"></span></label>
</div>
@mpdaugherty
mpdaugherty / bash_source_test.sh
Created May 14, 2012 03:17
A test file that illustrates the use of $BASH_SOURCE and $FUNCNAME
#!/bin/bash
function f1() {
echo 'In f1'
echo ''
echo ${BASH_SOURCE[0]} + ${FUNCNAME[0]}
echo ${BASH_SOURCE[1]} + ${FUNCNAME[1]}
}
echo 'in bash_source_test.sh'
@mpdaugherty
mpdaugherty / gist:2691564
Created May 14, 2012 03:11
Get the containing directory of the currently executing shell script, regardless of whether it is called or sourced.
#!/bin/bash
# Temporarily save the old values so we can restore them after execution
SOURCE_TEMP=$SOURCE
DIR_TEMP=$DIR
SOURCE="${BASH_SOURCE[0]}"
# Go through all symlinks to find the ultimate location of the source file
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
# Get an absolute path to the directory that contains this file
@mpdaugherty
mpdaugherty / .gitignore
Created April 20, 2012 06:41 — forked from amix/amazon_sender.py
Amazon SES helper script using boto
*.pyc
# cd into the root code directory
cd `git rev-parse --show-cdup`.
diffJSFiles=`git diff origin/master HEAD --name-only | grep "\.js$"`
echo "Validating Javascript Files with JS Lint:"
echo "$diffJSFiles"
jsPassed=0
for jsFile in $diffJSFiles; do
#!/bin/sh
# Check if the individual developer has his own hook
CMD_NAME=`basename $0`
if [ -f $GIT_DIR/hooks/personal/$CMD_NAME ]
then
# If so, run it. $@ passes all the command line arguments passed to this function
# If the personal hook fails, fail this one as well
if ! $GIT_DIR/hooks/personal/$CMD_NAME $@
then
# Only counts the file types listed below. Possible improvements would be to add more
# or add arguments to handle that.
# Only executes in the current directory. Possible improvement - make it an argument
find . | egrep '(\.py)|(\.php)|(\.js)|(\.css)' | xargs wc -l