Skip to content

Instantly share code, notes, and snippets.

View blasten's full-sized avatar

Emmanuel Garcia blasten

  • c.ai
  • Palo Alto, CA
View GitHub Profile
const SENTINEL = -Infinity;
function groupEvents(events) {
if (!Array.isArray(events) || events.length === 0) {
return [];
}
events = events.slice();
events.sort((a, b) => a.start - b.start);
let group,
@blasten
blasten / CustomElement.js
Last active March 24, 2017 17:18
custom elements in Preact or React without CE polyfills.
const HAS_NATIVE_CE = window.customElements != null;
const HTMLElement = HAS_NATIVE_CE ? window.HTMLElement : class{ constructor(self) { return self; } };
export class CustomElement extends HTMLElement {
constructor(inst) {
this.__instance = super(inst);
return this.__instance;
}
get props() {
return Object.assign({}, this.__props);
// Input
function NumberPad({ onPadPressed } = props) {
let keys = [0, 1, 2, 3, 4, 5, 6, 7, 8];
return keys.map(digit => <button key={digit} onClick={(event) => { onPadPressed({ digit: digit }); }}>{key}</button>);
}
function Calculator({ result, set} = props) {
return <div style={{ backgroundColor: 'gray' }}>
<input type="text" readOnly="true" value={result} />
<NumberPad onPadPressed={(event) => {
_queue = [];
_isRunning = false;
async _runLoop(task) {
let job, queue = this._queue;
if (this._isRunning) {
// Preempt the current tasks
while (job = queue[0]) {
queue.shift();
@blasten
blasten / object-fit-edge.css
Last active August 28, 2020 20:12
Adds support to object-fit in Edge.
.fit {
position: absolute;
top: 0px;
left: 0px;
bottom: 0px;
right: 0px;
width: 100%;
height: 100%;
object-fit: cover;
}
! function(t, i) {
"object" == typeof exports && "undefined" != typeof module ? module.exports = i() : "function" == typeof define && define.amd ? define(i) : t.Layout = i()
}(this, function() {
"use strict";
function t(t) {
return new Promise(function(i, n) {
function s(h, o) {
try {
var r = t[o ? "throw" : "next"](h)
<template tag="video-playback-control">
<style>
:host {
display: block;
}
#playButton::slotted {
color: red;
}
</style>
<slot id="playButton" name="play-button"></slot>
@blasten
blasten / async-lib-pattern.js
Last active November 30, 2016 20:59
async-lib-pattern
var libPromise = new Promise(function(resolve) {
window.Lib = window.Lib || [];
window.Lib.push(resolve);
});
libPromise.then(function(lib) {
// ...
});
libPromise.then(function(lib) {
Polymer.Debouncer = function Debouncer() {
this._scheduler = Polymer.Async.microTask;
this._timer = null;
this._wait = 0;
this.flush = this.flush.bind(this);
};
Polymer.Utils.mixin(Polymer.Debouncer.prototype, {
after: function(scheduler, wait) {
this._scheduler = asyncModule;
<dom-module id="x-list">
<template>
<iron-list item-height="_getItemHeight"></iron-list>
</template>
<script>
Polymer({
is: 'x-list',
_getItemHeight: function(node) {
if (node.hasTimeGap) {
return 116;