Skip to content

Instantly share code, notes, and snippets.

@tarmann
tarmann / gist:5563455
Last active December 17, 2015 06:09
Shell: simple-http-server
# Start an HTTP server from a directory,
# optional y specifying the port
# Add #!/usr/bin/env python to ~/.zshrc
function server() {
local port="${1:-8000}"
open "http://localhost:${port}/"
python -m SimpleHTTPServer "$port"
}
@tarmann
tarmann / gist:5563498
Last active December 17, 2015 06:09
JavaScript: Backbone.Collection.move Method
/**
* Moves a model to the given index, if different from its current index. Handy
* for shuffling models about after they've been pulled into a new position via
* drag and drop.
*/
Backbone.Collection.prototype.move = function(model, toIndex) {
var fromIndex = this.indexOf(model)
if (fromIndex == -1) {
throw new Error("Can't move a model that's not in the collection")
}
@tarmann
tarmann / gist:5563532
Last active December 17, 2015 06:09 — forked from killerbytes/gist:3280922
CSS: Image Replacement
//image replacement
.ir {
font: 0/0 "image replace";
position: relative;
display: inline-block;
background-repeat: none;
}
@tarmann
tarmann / gist:5571546
Created May 13, 2013 21:08
Shell: Git Alias
alias gl='git pull'
alias gp='git push'
alias gd='git diff'
alias gc='git commit'
alias gca='git commit -a'
alias gco='git checkout'
alias gb='git branch'
alias gs='git status'
alias grm="git status | grep deleted | awk '{print \$3}' | xargs git rm"
@tarmann
tarmann / gist:5618580
Last active December 17, 2015 13:39
JavaScript: Underscore Serialize JSON
_.mixin({
serialize: function (obj) {
var urlParams = _.map(obj, function (val, key) {
var value = (_.isObject(val)) ? JSON.stringify(val) : String(val);
return String(key) + '=' + value;
});
return urlParams.join('&');
}
});
@tarmann
tarmann / gist:5618587
Last active December 17, 2015 13:39
JavaScript: Backbone Sync for legacy web server
Backbone.sync = function (method, model, options) {
var params = _.extend({
type: 'POST',
dataType: 'json',
url: model.url,
traditional: true,
contentType: 'application/x-www-form-urlencoded;charset=UTF-8'
}, options);
@tarmann
tarmann / ui.forms.cascadingdropdowns.js
Created May 21, 2013 09:31
JavaScript: Cascading Dropdowns
/**
* UI Forms Cascading Dropdowns
*
* CHANGES:
* - Remove hardcoded if for 'unit', since this is not part of the module functionality
* - Added extra params functionality on order to send more info on the request
*
* TODO:
* - add option to cache the content
*/
@tarmann
tarmann / Underscore.js
Created May 21, 2013 19:52
JavaScript: Underscore Mixin for Namespacing
_.mixin({
namespace: function (path) {
var objects = path.split('.'),
namespace = window;
_.each(objects, function(obj, i){
namespace[obj] = namespace[obj] || {};
namespace = namespace[obj]
});
@tarmann
tarmann / gist:5626210
Last active December 17, 2015 14:39
JavaScript: Underscore Mixin Namespace
/*
* Usage: _.namespace('App.Namespace.Here');
*
*/
_.mixin({
namespace: function (path) {
var objects = path.split('.'),
namespace = window;
@tarmann
tarmann / mailinator.js
Created October 22, 2013 12:31
Bookmarklet for Mailinator accounts
javascript: (function () {
var user = prompt('What user account you want to access?', 'defaultUser');
window.location.href = 'http://mailinator.com/inbox.jsp?to=' + user;
}());