Skip to content

Instantly share code, notes, and snippets.

String.prototype.pad = function(n, str) { return (new Array(n - this.length)).join(str || "0"); };
(cls\s*:\s*|(class|cssClass|size)=)(['"])([\w\s]*\s)?CLASSNAMEHERE\b
// i18n string format method
// usage: messageFormat("hello {0}, welcome {1}", "James", "Home");
function messageFormat(str) {
var args = arguments;
return str.replace(/{(\d)}/g, function(r, n) { return args[+n+1];});
}
@mobz
mobz / melbjs.html
Created November 10, 2011 02:47
melbjs logo in css
<!DOCTYPE html>
<html>
<head>
<title>MelbJS</title>
<style>
.melbjs-logo {
width: 300px;
height: 300px;
@mobz
mobz / gist:2602772
Created May 5, 2012 14:13 — forked from petermichaux/gist:2593030
Golfing Maria Views
// The following is sugar for writing out in full a view constructor function, its prototype, and the boilerplate
// for inheriting from maria.ElementView. This sugar uses naming conventions to wire together
// the view with its model, controller, and their methods.
//
// A checkit.TodoView will observe a checkit.TodoModel. When the model changes, the update method below is called.
// When a user clicks on the todo element, the handling is delegated to the checkit.TodoController's
// handleRootClick method.
//
maria.ElementView.declareConstructor(checkit, 'TodoView', {
template: '<li><span class="todo-content"></span></li>', // the template can live elsewhere, of course
@mobz
mobz / jstestrunner.html
Created May 6, 2012 09:10
Standalone Test Runner for JSTestDriver
<!DOCTYPE html>
<html>
<head>
<title>Standalone JSTestRunner</title>
<!-- source scripts -->
<script src="../../main/webapp/www/core/jquery.js"></script>
<script src="../../main/webapp/www/core/core.js"></script>
<script src="../../main/webapp/www/core/widgets.js"></script>
@mobz
mobz / DOMj.mdown
Created May 28, 2012 05:53
DOM transport via JSON (DOMj)

DOM transport via JSON (DOMj)

move to repo mobz/domj

@mobz
mobz / api.js
Created June 24, 2013 01:05
localStorage api
this.api = (function() {
var key = localStorage.getItem("_key") || 0;
return {
put: function( o, cb ) {
localStorage.setItem("_key", key++ );
localStorage.setItem( "squares:" + key, JSON.stringify( o ) );
setTimeout( function() {
cb(key);
}, 250 );
},
@mobz
mobz / pre-commit
Created July 26, 2013 03:15
Don't commit jasmine specs containing iit or ddescribe
#!/bin/sh
# don't commit jasmine specs containing a ddescribe or iit
if git diff --cached --name-only | xargs egrep --include "*Spec.js" "\b(iit|ddescribe)\b"
then
echo "found Spec with iit or ddescribe"
exit 1
fi
@mobz
mobz / gist:6522629
Created September 11, 2013 12:02
Generating touch events for hammerjs tests
// === Generated Events === //
function customEvent( el, type ) {
var evt = document.createEvent("UIEvent");
evt.initUIEvent( type , true, true );
evt.touches = [ {} ];
el.dispatchEvent( evt );
}
function mouseEvent( el, type ) {
var evt = document.createEvent("MouseEvents");