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
h1 Page Title
p This is a sentance, woo!
@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)
@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 / _.get.js
Created August 31, 2012 23:41
Underscore mixin get object property with default value
//get a key from an object if it exists, otherwise use default
_.mixin({
get: function(obj, key, default_val){
if (obj && _.has(obj, key)){
return obj[key];
}
else{
return default_val != undefined ? default_val : '';
}
}
@lstebner
lstebner / _.remove.js
Created August 31, 2012 23:44
Underscore mixin to delete an object property
// remove key from object
_.mixin({
remove: function(obj, key){
delete obj[key];
return obj;
}
});
@lstebner
lstebner / _.slugify.js
Created September 4, 2012 01:03
Underscore Mixin to create Slugs
_.mixin({
slugify: function(title){
var replace = '-';
var str = title.toString()
.replace(/[\s\.]+/g,replace)
.toLowerCase()
.replace(new RegExp('[^a-z0-9'+replace+']','g'), replace)
.replace(new RegExp(replace+'+','g'),replace)
;
//border radius, takes any acceptable border-radius string
.border-radius(@rad){
border-radius: @rad;
-moz-border-radius: @rad;
-webkit-border-radius: @rad;
}
//round top corners
.border-radius-top(@rad){
.border-radius(@rad @rad 0 0);
@lstebner
lstebner / cache_helper.js
Created March 5, 2014 22:00
This little helper can save/load data into files for easy access.
module.exports = function(opts){
var fs = require('fs')
,md5 = require('MD5')
,_ = require('underscore')
,cache_helper = {}
,settings = _.extend({
cache_dir: __dirname + '/cache/'
}, opts || {})
,timenow = function(){
return (new Date()).getTime();
@lstebner
lstebner / ColorWheel.coffee
Created July 31, 2014 23:43
ColorWheel is a class that contains some static properties to assist with converting color values between hex and rgb(a).
# This class has a few static methods to help with color conversions between rgb and hex.
class ColorWheel
# Convert an rgb string to hex
@rgb_string_to_hex: (rgb="255, 255, 255") ->
#convert the string into the 3 int's that actually make up r, g & b
pieces = rgb.split(',')
rgb = []
for p, i in pieces
rgb[i] = parseInt(p)
@lstebner
lstebner / gist:aa7dcf8f951cbb56a8b1
Created August 23, 2014 16:39
These are the bash alias' I use, mostly git shortcuts
alias g='git'
alias o='open .'
alias x='gitx'
alias log='git log --name-only'
alias ci='git commit'
alias st='git status'
alias co='git checkout'
alias br='git branch'
alias rb='git rebase'
alias rbm='git rebase origin/master'