Skip to content

Instantly share code, notes, and snippets.

{
"glossary": {
"title": "example glossary ABC",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
@imehr
imehr / gist:5267592
Created March 28, 2013 23:14
javascript #module pattern
// http://stackoverflow.com/questions/12042260/how-to-use-the-javascript-module-pattern-in-a-real-example
var myApp = (function() {
var someElement = $("#foo"); //some element I know I'll use lots
var addMessage = function(message) {
$.ajax({
url: '/test',
type: 'POST',
@imehr
imehr / gist:5231238
Created March 24, 2013 09:47
javascript: jquery: #not() #delegate #multiple selector
$("#test_form").delegate("input:not([id*='_submit']), select", "blur", function(e) {
// Does something
});
@imehr
imehr / gist:5230000
Created March 24, 2013 01:12
javasctipt: #table, #clone-header
$(document).ready(function() {
TABLE.repeatHeader('#celebs', 10)
});
var TABLE = {};
TABLE.repeatHeader = function(table, every){
$(table).each(function() {
var $this = $(this);
var rowsLen = $this.find('tr:not(:first)').length;
@imehr
imehr / gist:5229995
Created March 24, 2013 01:10
javascript: #table, #fix-header #scroll
$(document).ready(function() {
TABLE.fixHeader('table')
});
var TABLE = {};
TABLE.fixHeader = function(table) {
$(table).each(function() {
var $table = $(this);
var $thead = $table.find('thead');
@imehr
imehr / gist:5227092
Created March 23, 2013 09:11
#css - Image replacement
.ir {
border: 0;
font: 0/0 a;
text-shadow: none;
color: transparent;
background-color: transparent;
}
@imehr
imehr / gist:5226810
Created March 23, 2013 07:29
#javascript - Fisher-Yates shuffle
jQuery.fn.shuffleChildren = (function(){
function fisherYatesShuffle(arr) {
// Fisher-Yates shuffle has been proven
// to be more random than the conventional
// arr.sort(function(){return Math.random()-.5})
// http://www.robweir.com/blog/2010/02/microsoft-random-browser-ballot.html
var i = arr.length,
@imehr
imehr / fiddle.css
Created March 2, 2012 23:39
Using Gist and Jsfiddle
body {
font-family: Helvetica, Verdana
}
p {
padding: 7px 10px;
}
#demo {
border: 1px solid #999;
}
@imehr
imehr / gist:1844243
Created February 16, 2012 11:34
_.bindAll()
/*
_.bindAll() ensures that all the functions you indicate are always invoked in the specified context. This is especially useful for event callbacks, as their context is always changing.
*/
Account = Backbone.Model.extend({
initialize: function() {
_.bindAll(this, 'removeElement');
},
removeElement: function() {
@imehr
imehr / gist:1835449
Created February 15, 2012 12:49
BackboneJS View
/*el is created using the attributes from the view’s tagName, className, or id properties. If none of these is specified, el is an empty div:
*/
var UserView = Backbone.View.extend({
tagName: "span",
className: "users"
});
// Binding a view onto an existing element in the page.
// Make sure the view is set up after the page has loaded.