Skip to content

Instantly share code, notes, and snippets.

@marqsm
marqsm / url_params_to_object.js
Created August 26, 2019 07:38
Url params to object
a.replace('?', '')
.split('&')
.reduce((accumulator, currentValue) => {
const pos = currentValue.indexOf('=');
const key = currentValue.slice(0, pos);
const value = currentValue.slice(pos+1);
accumulator[key] = value;
return accumulator;
}, {});
var Model = Backbone.Model.extend({});
var CollectionModel = Backbone.Model.extend({});
var Collection = Backbone.Collection.extend({
model: CollectionModel
});
var View = Backbone.Marionette.ItemView.extend({
tagName : 'li',
template: _.template("Number = <%= number %>")
@marqsm
marqsm / Git tag dates
Last active December 31, 2015 20:09
Git, see dates for tags in condensed format.
git log --tags --simplify-by-decoration --pretty="format:%d %ai %d"
@marqsm
marqsm / setup quick web server (osx) on localhost:31337
Last active December 31, 2015 16:29
Run quick test server on OSX (localhost:31337)
python -m SimpleHTTPServer 31337
@marqsm
marqsm / .bowerrc
Created December 17, 2013 21:21 — forked from facultymatt/.bowerrc
{
"directory": "components"
}
@marqsm
marqsm / backbone_collection_applyRecursive
Created December 10, 2013 12:45
Backbone collection - applyRecursive. To facilitate applying functions that need to traverse collection models and all their children.
// runs parameter function on all collection models (including children). Expects child collection to be defined in model as "nodes".
applyRecursive: function(func) {
// takes the last given function parameter - recursion makes arguments array more complex, se need to flatten it out.
var lastArg = _.chain(arguments).toArray().flatten().last().value();
this.each(function(model) {
func.call(model, func, lastArg); // run function in context of the model.
// if has nodes, apply function to nodes.
if ((typeof model.nodes !== 'undefined') && (typeof model.nodes.models !== 'undefined') && (model.nodes.models.length > 0)) {
@marqsm
marqsm / gist:7813089
Created December 5, 2013 20:16
Very simple compose-function in PHP
// Can manage multiple argumets for function, but can compose only 2 functions...
function compose($a, $b) {
return function() use ($a, $b) {
return $a(call_user_func_array($b, func_get_args()));
};
}
@marqsm
marqsm / gist:7770428
Created December 3, 2013 14:53
Underscore-template in Jade
script#tmpl-tree-node(type='text/template')
<li><%= nodeName %></li>
@marqsm
marqsm / fastLiveFilter-highlight-callback.js
Created February 15, 2013 13:06
Highlight for fastLiveFilter
$('#searchTerm').fastLiveFilter('#eventList', {
callback:function(total) {
$('#myList').unhighlight();
searchTerm = $("#searchTerm").val();
if (searchTerm.length > 0) {
$('#myList').highlight(searchTerm);
}
}
});