Skip to content

Instantly share code, notes, and snippets.

View pgarciacamou's full-sized avatar
:octocat:

Pablo Garcia pgarciacamou

:octocat:
View GitHub Profile
@pgarciacamou
pgarciacamou / MyPromise-es6.js
Last active March 18, 2016 23:46
MyPromise.js is a very, very light (778 Bytes) version of a Promise. It aims for performance rather than complexity or functionality.
export default class MyPromise {
constructor (fn) {
this._callbacks = [];
this._done = false;
if(fn) fn(this.fulfill.bind(this));
}
static all(promises) {
return new MyPromise(function (fulfill){
var counter = promises.length;
@pgarciacamou
pgarciacamou / clone.js
Created December 21, 2015 22:46
Recursive Object Cloning (shallow).
function clone(o){
if(!(o instanceof Object)) return o;
var obj = {};
for(var prop in o) {
if(o.hasOwnProperty(prop)) obj[prop] = clone(o[prop]);
}
return obj;
}
@pgarciacamou
pgarciacamou / overloader.js
Last active October 27, 2015 19:52
Overloading methods in JavaScript like a charm.
// Function that overloads a method
// @param {Object} obj. Object container of the method (can be first-class-object/function)
// @param {String} methodName. Name of the method to overload
// @param {Function} fn. Method that will overload.
// @param {Array} [paramsArr]. Array with the parameters types. OPTIONAL (recommended to always use)
//
// Examples:
// var obj = { method: function(){return "default method";} };
// overloadMethod(obj, "method", function(a){return a;}, ["number"]);
// obj.method(); ==> "default method"
@pgarciacamou
pgarciacamou / index.html
Created August 10, 2015 21:07
Navigation Slider
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<title> ... </title>
<link href="css/nav.css" rel="stylesheet" type="text/css">
</head>
<body class="">
<section id="nav-container" class="right">
@pgarciacamou
pgarciacamou / Console.js
Created July 24, 2015 23:06
Mini node server REST API with express that prints to the console through web. Created to replace jsconsole.com and to debug phones that are not iphones or compatible.
/**
* This console connects to a server and sends data to be printed.
*
* @note Server must allow CORS requests.
*
* @param options {Object} Set of options to make the ajax requests.
*
* @example
* var c = new Console({
* localhost: "10.0.1.8",
// ---------------------------------------------
// FONT
// ---------------------------------------------
@font-face {
font-family: "Raleway";//-ExtraBold";
src: url("../font/Raleway-ExtraBold.ttf") format("truetype"), url("../font/Raleway-ExtraBold.woff") format("woff");
font-weight: 700;
font-style: normal;
}
@pgarciacamou
pgarciacamou / FileHandler.js
Created June 15, 2015 23:31
FileHandler :: Small file Handler that parses each file to an Array of Objects, each object corresponds to a row in the file. Each row must be in JSON format.
// ----
// CONSTRUCTOR
//
// name: FileHandler
// Handles input files and reads the data.
// Once the file is loaded it will execute the callback with that file.
function FileHandler(options){
if(!(window.File && window.FileReader && window.FileList && window.Blob)) throw new Error("File APIs not supported in current browser");
this.elem = options.element;
}
@pgarciacamou
pgarciacamou / gulpfile.js
Last active July 21, 2016 17:09
Gulpfile with less, browserify, babelify, ejs, uglify, and some folder structure.
/* global require */
"use strict";
var path = require('path')
var fs = require('fs');
var browserify = require('browserify');
var through2 = require('through2');
var babelify = require('babelify');
var gulp = require('gulp');
var uglify = require('gulp-uglify');
@pgarciacamou
pgarciacamou / toRem.js
Created June 10, 2015 21:21
Convert pixels to rems with JavaScript
var toRem = (function(){
var fontSize = parseFloat(window.getComputedStyle(document.querySelector("html"), null).getPropertyValue('font-size'));
return function toRem(px){
return px/fontSize;
};
})();
@pgarciacamou
pgarciacamou / transform.js
Last active August 29, 2015 14:20
Transform feature detection
"use strict";
window.transformProp = (function getSupportedTransform() {
var prefixes = "transform WebkitTransform MozTransform OTransform msTransform".split(" ");
for(var i = 0; i < prefixes.length; i++) {
if(document.createElement("div").style[prefixes[i]] !== undefined) {
return prefixes[i];
}
}
return false;