Skip to content

Instantly share code, notes, and snippets.

View designfrontier's full-sized avatar

Daniel Sellers designfrontier

View GitHub Profile
@designfrontier
designfrontier / jquery.pinme.0.1.js
Created November 2, 2011 21:37
Pin me... an awesome jQuery plugin
//pins elements in place with JS
(function($){
$.pinme = function(el){
var base = this;
// Access to jQuery and DOM versions of element
base.$el = $(el);
base.el = el;
// Add a reverse reference to the DOM object
@designfrontier
designfrontier / titleCase
Created February 2, 2012 16:03
Some code extending the JavaScript string prototype for working with titles and headers
String.prototype.titleCaps = function(){
var thisString = this.replace(/( )([a-z])/g, function(m, $1, $2){return $1 + $2.toUpperCase();});
//remove and, the, or of from caps if they are not the first element in the string
thisString = thisString.replace(/(and|of|to|the|or)/ig, function(m,$1){return $1.toLowerCase();});
thisString = thisString.replace(/(^[a-z])/,function(m,$1){return $1.toUpperCase();});
return thisString;
};
@designfrontier
designfrontier / newPadssview.sublime-snippet
Created September 24, 2012 19:06
snippet for creating a new PadssView based view
<snippet>
<content><![CDATA[
define([
'modules/PadssView'
], function(
PadssView
) {
return PadssView.extend({
events: {
@designfrontier
designfrontier / gist:4048217
Created November 9, 2012 21:03
crazy router for matching any part an url hash to a naming convention
var window = arr.length;
for(var i = 0; < arr.length; i++){
for(var index = i; index >= 0; index--){
loopOverWindow(arr,window,index);
}
window --;
}
@designfrontier
designfrontier / gist:4495292
Created January 9, 2013 18:00
Some nasty and fascinating JS recursion or your viewing pleasure. Paste in web inspectors js console and then work your way down through the arrays...
t = ['john'];
c = ['daniel','joe'];
t.push(c);
c.push(t);
c;
@designfrontier
designfrontier / compressed version
Last active December 25, 2015 15:39
line length marker now with Jquery inclusion built in
javascript:!function(){var a=document.createElement("script"),b=function(){var a=$("p"),b=0,c="",d="";for(b=0;b<a.length;b++)c=$(a[b]).text(),d=c.slice(0,45)+"*"+c.slice(45,70)+"*"+c.slice(70),$(a[b]).text(d)};a.src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js",document.getElementsByTagName("head")[0].appendChild(a),setTimeout(b,500)}();
@designfrontier
designfrontier / gist:8029846
Created December 18, 2013 21:07
creates a 200 char summary with html tags intact
var createSummary = function(str){
var str = str
//tag replacement stuff
, tagRegex = /<[^>]*>?/g
, markerRegexGlobal = /~/g
, markerRegex = /~/
, marker = '~'
//other vars that we will need
, refString = str.replace(tagRegex, marker) //replace out tags
, i = 0
@designfrontier
designfrontier / gist:f1644994ae8c10c1bd74
Created November 13, 2014 21:15
interview.js solution with modern schtuff
function delegate (childIn) {
var child = childIn;
return function me(){
var that = this,
oper = Object.getOwnPropertyNames(that).filter(function (attrib) {
return(typeof that[child][attrib] === 'function' && me === that[attrib]);
})[0];
return that[child][oper].apply(this[child], arguments);
@designfrontier
designfrontier / Gulpfile.js
Last active August 29, 2015 14:17 — forked from webdesserts/Gulpfile.js
node restarter in gulp specifically for monument based web apps
// NOTE: I previously suggested doing this through Grunt, but had plenty of problems with
// my set up. Grunt did some weird things with scope, and I ended up using nodemon. This
// setup is now using Gulp. It works exactly how I expect it to and is WAY more concise.
var gulp = require('gulp'),
spawn = require('child_process').spawn,
node;
/**
* $ gulp server
* description: launch the server. If there's a server already running, kill it.
@designfrontier
designfrontier / gist:77f5d768e77bb7604065
Last active August 29, 2015 14:25
pre-bernstein promise chains
somePromiseReturningFunction.then(function(data){
data.num++;
return data;
}).then(function(data){
data.num++;
return data;
}).then(function(data){
data.num++;
return data;
}).then(function(data){