Skip to content

Instantly share code, notes, and snippets.

View tincho's full-sized avatar

Martin tincho

View GitHub Profile
@tincho
tincho / element.fillWith.js
Last active December 29, 2016 15:44
Element.fillWith basic "template filling" function
/**
* replaces variables in element innerHTML, e.g.
* DOM: <span id="fillMe">hey {{#}}, whats up {{#}}</span>
* Code: document.querySelector('#fillMe').fillWith('bro')
* Output: hey bro, whats up bro
*
* DOM: <span id="fillMe">the {{animal}} is sitting at the {{forniture}}</span>
* Code: document.querySelector('#fillMe').fillWith({'animal': 'cat', 'forniture': 'table'});
* Output: the cat is sitting at the table
*/
@tincho
tincho / array.prefixEach.js
Created December 29, 2016 15:41
Array.prefixEach preppends string to every element in array
/**
* Prefixes each array element with given
* @param {String} prefix
* @usage e.g var pfixed = ["one", "two", "three"].prefixEach("number: ");
*/
Array.prototype.prefixEach = function(prefix) {
return this.map(_ary(String.prototype.concat.bind(prefix)));
};
function _ary(fn, arity) {
@tincho
tincho / ajaxSubmit.js
Created December 29, 2016 15:23
intercept form and submit it via ajax (requires jQuery)
function _noop() {}
function _constant(v) { return function() { return v; }; }
/**
* intercept <form> and submit it via XHR
* @param {String} formSelector
* @param {Function} successCallback
* @param {Function} errorCallback
* @param {Function} beforeSubmit
*/
@tincho
tincho / daysbetween.py
Created December 29, 2016 15:21
days between two dates
#!/usr/bin/python
# -*- coding: utf-8 -*-
import datetime
import sys
def compare(dates):
if len(dates) < 2:
/**
* vainilla js simple slider
* source: http://cssdeck.com/labs/image-slider-1
*/
/**
css:
.image-slider-wrapper{
overflow: hidden;
}