Skip to content

Instantly share code, notes, and snippets.

Juan Dopazo juandopazo

View GitHub Profile
View get_timezone_offset.js
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
View gist:689bc36a4cf5d8994d15
class QueueItem {
constructor(value) {
this.value = value;
this.next = void 0;
}
}
class Queue {
constructor() {
this.first = void 0;
@juandopazo
juandopazo / gist:dfc6c067f1442fa8fa23
Last active Aug 29, 2015
Loader hooks API surface
View gist:dfc6c067f1442fa8fa23
interface LoadRequest {
name: string;
address?: string;
source?: string;
metadata: Object;
}
interface Eventual<T> = T | Promise<T>;
interface ModuleInstantiator {
View CancellablePromise.all.js
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;
}
View CancellablePromise.all.js
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;
}
View gist:9772321
(function (global) {
"use strict";
function Queue(capacity) {
this.capacity = this.snap(capacity);
this.length = 0;
this.front = 0;
this.initialize();
}
View gist:9413718
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 Feb 6, 2014
You can expect this to be Node code in <2 years
View gist:8849263
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 Jan 14, 2014
AMD loading in YUI 3.15
View gist:8425869
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 Jan 2, 2016
ES5-based Y.Model
View gist:8287117
function assign(dest, source) {
for (var prop in source) {
if (source.hasOwnProperty(prop)) {
dest[prop] = source[prop];
}
}
return dest;
}
function createStateClass(superclass, props) {
You can’t perform that action at this time.