Skip to content

Instantly share code, notes, and snippets.

View tracend's full-sized avatar
🎯
Focusing

✌ Makis Tracend tracend

🎯
Focusing
View GitHub Profile
@tracend
tracend / backbone.inherit.js
Last active January 4, 2016 21:29
Backbone.inherit - Combine more than one Parents in one instance #cc
(function(Backbone){
Backbone.inherit = function(){
var classes = Array.prototype.slice.call(arguments, 0);
// prerequisites
if( !classes.length ) return;
var Class = classes.pop();
// loop through objects
for( var i in classes){
@tracend
tracend / common.loading.css
Last active February 21, 2024 11:59
CSS3 Loading Overlay
body.loading:after {
/* with no content, nothing is rendered */
content: "";
position: fixed;
/* element stretched to cover during rotation an aspect ratio up to 1/10 */
top: -500%;
left: -500%;
right: -500%;
bottom: -500%;
z-index: 9999;
@tracend
tracend / underscore.ucwords.js
Created January 15, 2014 10:50
_.ucwords() #underscore #helper #cc
_.mixin({
// Uppercase the first character of each word in a string
// From: http://phpjs.org/functions/ucwords/
ucwords : function(str) {
return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
return $1.toUpperCase();
});
}
});
@tracend
tracend / handlebars.striptags.js
Created January 15, 2014 08:02
striptags() #handlebars #helper #cc
Handlebars.registerHelper("striptags", function( txt ){
// exit now if text is undefined
if(typeof txt == "undefined") return;
// the regular expresion
var regexp = new RegExp('#([^\\s]*)','g');
// replacing the text
return txt.replace(regexp, '');
});
@tracend
tracend / underscore.sortByName.js
Created January 15, 2014 04:52
_.sortByName() #underscore #mixin #cc
_.mixin({
// - Sort a list alphabetically
sortByName : function(a, b) {
var x = a.name.toLowerCase();
var y = b.name.toLowerCase();
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
});
@tracend
tracend / underscore.isInteger.js
Created January 15, 2014 04:51
_.isInteger() #underscore #mixin #cc
_.mixin({
// - Check if a number is an integer
isInteger : function(s){ return parseInt(s,10)===s; }
});
@tracend
tracend / underscore.toArray.js
Created January 15, 2014 04:45
_.toArray() #underscore #mixin #cc
_.mixin({
// - Takes an array-like object and turns it into a real Array
// to make all the Array.prototype goodness available.
toArray : function ( a ) {
return [].slice.call( a );
// alternatively:
//Array.prototype.slice.call( a );
}
});
@tracend
tracend / underscore.toNumber.js
Created January 15, 2014 04:39
_.toNumber() #underscore #mixin #cc
_.mixin({
// `toNumber` takes a value given as `numeric` parameter and tries to turn it into a number.
// If it is not possible it returns 0 (or other value given as `fallback`).
toNumber : function (numeric, fallback) {
return isNaN(numeric) ? (fallback || 0) : Number(numeric);
}
});
@tracend
tracend / underscore.getParams.js
Created January 15, 2014 04:36
_.getParams() #underscore #mixin #cc
_.mixin({
// parses a query string and returns the parameters in a javascript object
getParams : function(query){
var query = {};
data.replace(
new RegExp("([^?=&]+)(=([^&]*))?", "g"),
function($0, $1, $2, $3) { query[$1] = decodeURIComponent($3); }
);
return query;
}
@tracend
tracend / uniqueCode.js
Created December 31, 2013 22:56
Unique Code: Generate short IDs based on UTC Based on the C# version: http://schroedman.wordpress.com/2012/01/19/short-unique-id-in-c-without-using-guid/
function uniqueCode(){
var characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var ticks = (new Date()).getTime().toString();
var code = "";
for (var i = 0; i < characters.length; i += 2) {
if ((i + 2) <= ticks.length) {
var number = parseInt(ticks.substr(i, 2));
if (number > characters.length - 1) {
var one = number.toString().substr(0, 1);
var two = number.toString().substr(1, 1);