Skip to content

Instantly share code, notes, and snippets.

@rhowardiv
rhowardiv / oo.php
Created October 6, 2010 14:38 — forked from dhotson/oo.php
<?php
// You should make this something that is sensible for your application
namespace gist;
/**
* You can't set functions as callable properties on a normal generic
* object. You can on instances of this class.
*
* You can't use "$this," however, so the function will always receive a
@rhowardiv
rhowardiv / nargs
Created December 9, 2010 21:11
nargs -- a wrapper for xargs -d'\n' that cleans leading/trailing whitespace
#!/bin/bash
sed 's/^[ ]\+//' | sed 's/[ ]\+$//' | xargs -d'\n' $@
@rhowardiv
rhowardiv / pptail
Created January 7, 2011 20:05
Tail a file across multiple servers
#!/bin/bash
F=$1
shift
echo $@ | xargs -n1 -P4 ptail $F
@rhowardiv
rhowardiv / svn-rebase.sh
Created April 18, 2011 21:38
Rebasing in SVN
# First look what happens with a simple but naive approach.
# I'll try recreating the branch in-place and merging in changes from the old version.
# Should be easy, right? svn never forgets, right? ...
cd ~/mybranch
SVH=/repo/root
# (for this approach we need the rev #'s for the start and end of the branch)
START_REV=$(svn log --stop-on-copy | grep '^r[0-9]' | tail -n 1 | sed s/^r// | awk '{print $1}')
END_REV=$(svn log --stop-on-copy | grep '^r[0-9]' | head -n+1 | sed s/^r// | awk '{print $1}')
@rhowardiv
rhowardiv / svn-list-tags
Created October 3, 2011 20:18
Fetch latest tags from a directory in a Subversion repository and show them with their source path and rev#
#!/bin/bash
#
# Fetch latest N tags and show from where and which revision they were copied
function usage()
{
echo "
Usage: $0 [-n N] URL [REGEX]
-n Number of tags to fetch
@rhowardiv
rhowardiv / charCount.js
Created December 14, 2011 20:47
jQuery plugin for word / character counting
/*
* Character Count Plugin - jQuery plugin
* Dynamic character count for text areas and input fields
* written by Alen Grakalic
* http://cssglobe.com/post/7161/jquery-plugin-simplest-twitterlike-dynamic-character-count-for-textareas
* and Richard Howard, Roubini Global Economics
* http://www.roubini.com
*
* Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
@rhowardiv
rhowardiv / contentCall.twitter.js
Created December 14, 2011 20:51
contentCall function for charCount plugin to take twitter URL-shortening into account
function contentWithTwitterURLShortening(c) {
// t.co URLs are currently max 20 chars, but since that is subject to
// expansion we're leaving some elbow room and assuming 25
return c.replace(/http(s?):\/\/[-\w]+(\.\w[-\w]*)+(:\d+)?(\/[^.!,?;"'<>()\[\]{}\s\x7F-\xFF]*(?:[.!,?]+[^.!,?;"'<>()\[\]{}\s\x7F-\xFF]+)*)?/g, "http$1://t.co/xxxxxxxxxxxxx");
}
@rhowardiv
rhowardiv / syncdaemon
Last active October 1, 2015 14:28
my bash wrapper around lsyncd; daemonize this
#!/bin/bash
# Just a wrapper around lsyncd
# Keep two places in sync
HERE=/home/rhoward/ayi/
THERE=rhoward-dev.ayisnap.com:/var/www/html/areyouinterested.com
# Check that no previously running syncs are still running;
# this causes boffo logging
CURRENT_SYNC=$(ps aux | grep "rsync.\+$HERE" | grep -v '0 grep')
@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