Skip to content

Instantly share code, notes, and snippets.

View lstebner's full-sized avatar
🍉
plant more seeds

Luke Stebner lstebner

🍉
plant more seeds
View GitHub Profile
function _annotate() {
echo "$(tput setaf 4)>>$(tput sgr0) $@"
eval $@
}
function gup() {
branch=$([[ -n "$1" ]] && echo "$1" || git rev-parse --abbrev-ref HEAD)
dirty=$(git diff --shortstat 2> /dev/null | tail -n1)
_annotate git fetch || return
@lstebner
lstebner / _.replace.js
Created August 30, 2012 19:34
Underscore mixin for making multiple string replacements in one call
//this replace method can take multiple finds and one or multiple replacements at a time
//if find is an array, replace will be called on every find
//if replace is an array, the indexes must match with find to do replacements.
//if replace is a string, it will be used for all replace calls if find is an array
//if find and replace are both strings, this will simply mimmick a normal str.replace(find, replace) call
//the result of all replacements will be returned at the end
_.mixin({
replace: function(str, find, replace){
//if str is null, just give up now
if (str === null){
@lstebner
lstebner / dateformat.js
Created May 16, 2012 00:06
JavaScript Date Format Using PHP Wildcards
Date.format = function(d, format, custom_months, custom_days){
var months = custom_months || ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
,days = custom_days || ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
,replacements = [
//day
[ '%d', (d.getDate() < 10 ? '0' : '') + d.getDate() ] //leading 0: 01-31
, [ '%D', days[ d.getDay() ].substr(0, 3) ] //3 letter representation (Mon-Sun)
, [ '%j', d.getDate() ] //no leading 0: 1-31
, [ '%l', days[ d.getDay() ] ] //[lowercase L], full textual representation (Monday-Sunday)
, [ '%N', (d.getDay() + 1) ] //day #: 1-7 (1=monday, 7=sunday)