Skip to content

Instantly share code, notes, and snippets.

@jtenner
jtenner / Silly Bootstrap Ajax Dropdown Code
Last active December 25, 2015 14:39
Requires Underscore: Ajax dropdown list pattern for bootstrap and lodash. This snippet will fire your ajax event for a dropdown-menu on a text box only after waiting 400 ms for the last input. Afterwards it hooks up a click event to the body to close the dropdown. Yes, I used jquery. No, it isn't required. I personally prefer vanilla javascript.
(function(){
var debouncedKeyPress;
function wrapper(e){
var keycode = e.keyCode||e.which;
debouncedKeyPress(this);
if(keycode === 13)//prevent form submission
{
e.preventDefault();
return false;
}
@jtenner
jtenner / gist:7162176
Created October 25, 2013 21:33
hoodie gist for gr2m
var app = new Hoodie("http://localhost:6001/");
app.account.signIn("admin", "admin").done(function (user) {
app.store.findAll('callback').done(function (callbacks) {
for (var i = 0, _len = callbacks.length; i < _len; i++) {
$(".target").append(JSON.stringify(callbacks[i]) + "<br />")
}
});
console.log(user)
$("#add").click(function () {
function SubArray(length){
Array.call(this); //"Magic"
if(typeof length === "number" && length%1===0&&arguments.length===1){
this.length = length; //Length has to be set manually for some reason.
}
else{
var _len = arguments.length;
this.length = _len;
for(var i = 0; i<_len; i++)
this[i] = arguments[i];
@jtenner
jtenner / gist:7307358
Created November 4, 2013 18:49
Cross prototype example
var arrayObject = ["What", "is", "going", 0,"on", 111,"..", "here"];
String.prototype.slice.call(arrayObject);
//"What,is,going,0,on,111,..,here"
String.prototype.concat.call(arrayObject);
//"What,is,going,0,on,111,..,here"
String.prototype.substring.call(arrayObject,1,10)
//"hat,is,go"
String.prototype.indexOf.call(arrayObject, "n,111")
//17
@jtenner
jtenner / gist:7307423
Last active December 27, 2015 09:59
Topics for today
var topics = ["idea","examples","post some code"];
//["idea","examples","post some code"]
topics.shift();
//"idea"
topics.shift();
//"examples"
topics.shift();
//"post some code"
@jtenner
jtenner / gist:7310280
Last active December 27, 2015 10:19
String prototype Template function
String.prototype.template = function(templateObject){
return this.replace(/\{\{([a-zA-Z\_0-9\.]*?)\}\}/g, function(match){
var temp = templateObject;
match.slice(2,-2).split('.').forEach(function(item){
temp = temp[item];
});
return temp;
});
};
Object.prototype.template = function(templateStr){
var that = this;
return templateStr.replace(/\{\{([a-zA-Z\_0-9\.]*?)\}\}/g, function(match){
match.slice(2,-2).split('.').forEach(function(item){
that = that[item];
});
return that;
});
};
function HandleBar(templateStr, templateObject){
var that = templateObject;
return templateStr.replace(/\{\{([a-zA-Z\_0-9\.]*?)\}\}/g, function(match){
match.slice(2,-2).split('.').forEach(function(item){
that = that[item];
});
return that;
});
};