Skip to content

Instantly share code, notes, and snippets.

View juandopazo's full-sized avatar

Juan Dopazo juandopazo

View GitHub Profile
@juandopazo
juandopazo / gist:3174141
Created July 25, 2012 03:03
YUI AMD loader
var YUI_config = {};
(function (YUI, global) {
var modules = {};
var justLoaded = [];
var AMD_prefix = '~AMD~';
function nameFromPath(path) {
var parts = path.split(/\//g).pop().split(/\./g),
ext = parts.pop();
@juandopazo
juandopazo / gist:1305379
Created October 22, 2011 01:04
Loading AMD modules from YUI
(function (window) {
var lastModule;
// configFn for all patterns that match an AMD-like module
// For now, only modules starting with ./ or ../ are recognized as being AMD-like
// Support for regular expressions in the patterns configuration was requested in ticket #2531324
// In the future the goal is to filter everything that looks like a file
// Any other AMD module must be declared in the "modules" config like any other module
function defConfigFn(config) {
@juandopazo
juandopazo / gist:5620611
Last active September 8, 2020 00:22
Validator jQuery plugin
/*
* jQuery plugin to validate forms around segurosdigitales
* requires jquery validate plugin
* */
(function($){
function Validator(options, element) {
this.options = $.extend( {}, this.options, options );
this.elem = element;
this.$elem = $(element);
@juandopazo
juandopazo / lib.js
Created November 15, 2011 14:21
Function.prototype.extend for simple classes in ES5
Object.getOwnPropertyDescriptors = function getOwnPropertyDescriptors(obj) {
var descriptors = {};
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
descriptors[prop] = Object.getOwnPropertyDescriptor(obj, prop);
}
}
return descriptors;
};
@juandopazo
juandopazo / gist:2901426
Last active September 10, 2018 07:59
Privates and WeakMaps
// Based on a gist by @rwaldron
// https://gist.github.com/2897761
function privatize() {
var map = new WeakMap();
return function private(obj) {
var data = map.get(obj);
if (!data) {
map.set(obj, data = {});
}
@juandopazo
juandopazo / gist:3244053
Created August 3, 2012 03:24
Geometric linear algebra for 3d CSS3

@mapagella came to me with a question. A friend of his was trying to do ray tracing with CSS3. He wanted to rotate in 3D a <div> element shaped like a line so that it started and ended in specific points in space.

Ray tracing gone wrong

It turns out that CSS3 defines a rotate3d() transform function that allows you to rotate an HTML element a certain angle around a certain direction in 3D space. The function looks like rotate3d(x, y, z, angle) where x, y and z define the direction around which the element will be rotated. The question then is what direction and which angle to use.

Let's start by defining what our line will be. We'll use a div element with a line class: <div class="line"></div>. And we'll define line as:

.line {
 background: green;
export function getTimezoneOffset(date, timeZone) {
const parts = new Intl.DateTimeFormat('en-US', {
timeZone,
hour12: false,
year: 'numeric', month: 'numeric', day: 'numeric',
hour: 'numeric', minute: 'numeric', second: 'numeric'
}).format(date).split(/[\/\s:]/);
// The year string contains a comma, like "2016,", so we strip it using parseInt
const year = parseInt(parts[2], 10);
// The month is rendered in human readable terms, which are betweeen 1-12, but the API requires 0-11
@juandopazo
juandopazo / gist:1182244
Created August 30, 2011 22:14
JavaScript without logical operators or loops
function _if(truthy, then) {
[then, function () {}][+!truthy]();
}
function ifElse(truthy, then, _else) {
[then, _else][+!truthy]();
}
function and(a, b) {
return !!((!!a + !!b) >> 1);
@juandopazo
juandopazo / gist:8425869
Created January 14, 2014 21:15
AMD loading in YUI 3.15
YUI.add('require', function (Y) {
return function (name) {
return Y.Env._exported[name];
}
}, '@VERSION@', {
es: true
});
define(name, dependencies, factory) {
var defDeps = ['require', 'exports', 'module'],
@juandopazo
juandopazo / gist:8287117
Last active January 2, 2016 09:59
ES5-based Y.Model
function assign(dest, source) {
for (var prop in source) {
if (source.hasOwnProperty(prop)) {
dest[prop] = source[prop];
}
}
return dest;
}
function createStateClass(superclass, props) {