Skip to content

Instantly share code, notes, and snippets.

View carloscabo's full-sized avatar
🏠
Working 100% remotely since 2018

Carlos Cabo carloscabo

🏠
Working 100% remotely since 2018
View GitHub Profile
@carloscabo
carloscabo / cantor_pairing.js
Created January 28, 2013 14:38
#js #math #utils Cantor pairing. Combines two integer values in a single one that can be reversed to the original ones
//CANTOR PAIRING
/* Combines two integer values in a single one that can be reversed to the original ones */
cantorPair = function(x, y) {
var z = ((x + y) * (x + y + 1)) / 2 + y;
return z;
};
reverseCantorPair = function(z) {
var pair = [];
@carloscabo
carloscabo / gist:4671669
Created January 30, 2013 08:34
#js #random #shuffle #array #fisher #yates Shuffles array's elements
var fisherYates = function( myArray ) {
var i = myArray.length, j, tempi, tempj;
if ( i == 0 ) return false;
while ( --i ) {
j = Math.floor( Math.random() * ( i + 1 ) );
tempi = myArray[i];
tempj = myArray[j];
myArray[i] = tempj;
myArray[j] = tempi;
}
@carloscabo
carloscabo / gist:4698468
Last active December 12, 2015 02:28
#js #math #utils Generate random token
/* Function to generate random numeric token. Usefull to append it at the end of URLs we don't want to be cached by the browser. <img src="/path/image.png?XXXXXXX"> */
var rand = function() {
return Math.random().toString(36).substr(2); // remove '0.'
};
var token = function(char_num) {
var token = rand() + rand(); // make it longer
token = token.substr(0, char_num);
return token;
@carloscabo
carloscabo / gist:5231666
Created March 24, 2013 12:15
#CSS #retina Targetting retina displays with media-query
@media
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and ( min--moz-device-pixel-ratio: 2),
only screen and ( -o-min-device-pixel-ratio: 2/1),
only screen and ( min-device-pixel-ratio: 2),
only screen and ( min-resolution: 192dpi),
only screen and ( min-resolution: 2dppx) {
.image{
background: url (myIMG@2x.png);
// Paste into Firebug or Chrome Dev Tools console
// when viewing a page with multiple checkboxes.
(function(d) {
var input = d.getElementsByTagName('input');
var i = input.length;
while (i--) {
if (input[i].type === 'checkbox') {
input[i].setAttribute('checked', 'checked');
/*
Responsive Pseudo-grid
We define here the cols width that will be asigned to the containers.
Include this mixins in the corresponding semantic container this way.
.container {
@include col-50(%3, %3);
}
<!DOCTYPE html>
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /><![endif]-->
<!--[if lt IE 7 ]> <html lang="<%= ::I18n.locale %>" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="<%= ::I18n.locale %>" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="<%= ::I18n.locale %>" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="<%= ::I18n.locale %>" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="<%= ::I18n.locale %>" class="no-js"> <!--<![endif]-->
@carloscabo
carloscabo / _tipography.scss
Created June 6, 2013 11:25
Dynamic font SASS mixin
@mixin font-face($font-family, $file-path, $weight: normal, $style: normal) {
@font-face {
font-family: $font-family;
font-weight: $weight;
font-style: $style;
src: font-url('#{$file-path}.eot');
src: font-url('#{$file-path}.eot?#iefix') format('embedded-opentype'),
font-url('#{$file-path}.woff') format('woff'),
font-url('#{$file-path}.ttf') format('truetype'),
font-url('#{$file-path}.svg##{$font-family}') format('svg');
@carloscabo
carloscabo / jquery.fn.js
Created June 11, 2013 14:59 — forked from afgomez/jquery.fn.js
Generic JQuery plugin template
(function($) {
$.fn.plugin = function() {
return this.each(function() {
var $this = $( this );
if ( !$this.data('plugin') ) {
$this.data( 'plugin', new Plugin(this) );
}
});
}
/* Send a form with a link with data-form="#form_id"
/ You can define params="name,value name,value"
/ All params will be append to the form as hidden inputs before send it
*/
$('body').on('click', '[data-form]', function(e) {
e.preventDefault();
var el = $(this),
form = $(el.data('form')),
params;