Skip to content

Instantly share code, notes, and snippets.

View juandopazo's full-sized avatar

Juan Dopazo juandopazo

View GitHub Profile
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
class QueueItem {
constructor(value) {
this.value = value;
this.next = void 0;
}
}
class Queue {
constructor() {
this.first = void 0;
@juandopazo
juandopazo / gist:dfc6c067f1442fa8fa23
Last active August 29, 2015 14:01
Loader hooks API surface
interface LoadRequest {
name: string;
address?: string;
source?: string;
metadata: Object;
}
interface Eventual<T> = T | Promise<T>;
interface ModuleInstantiator {
CancellablePromise.all = function (values) {
var CancellablePromise = this;
var child;
var children = [];
return new CancellablePromise(function (resolve, reject) {
if (!A.Lang.isArray(values)) {
reject(new TypeError('CancellablePromise.all expects an array of values or promises'));
return;
}
CancellablePromise.all = function (values) {
var CancellablePromise = this;
var child;
var children = [];
return new CancellablePromise(function (resolve, reject) {
if (!A.Lang.isArray(values)) {
reject(new TypeError('CancellablePromise.all expects an array of values or promises'));
return;
}
(function (global) {
"use strict";
function Queue(capacity) {
this.capacity = this.snap(capacity);
this.length = 0;
this.front = 0;
this.initialize();
}
PromisePolyfill.async = (function () {
"use strict";
function Queue(capacity) {
this.capacity = this.snap(capacity);
this.length = 0;
this.front = 0;
this.initialize();
}
@juandopazo
juandopazo / gist:8849263
Created February 6, 2014 17:55
You can expect this to be Node code in <2 years
import { readFile } from 'fs';
import { createServer } from 'http';
createServer(async function (req, res) {
try {
var content = await readFile('foo.html');
res.end(content);
} catch (e) {
res.end('ouch!');
}
@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) {