Skip to content

Instantly share code, notes, and snippets.

loader = {
// arreglo con ruta de las imágenes
images: [],
// Se ejecuta al cargar las imágenes
onComplete: function(){},
init: function(){
var self = this, count = 0;
@schmidtsonian
schmidtsonian / 0_reuse_code.js
Last active August 29, 2015 14:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@schmidtsonian
schmidtsonian / events.js
Created April 12, 2019 14:22
A super-basic Javascript (publish subscribe) pattern
/**
* A super-basic Javascript (publish subscribe) pattern
* https://www.youtube.com/watch?v=nQRXi1SVOow
* https://gist.github.com/learncodeacademy/777349747d8382bfb722
*
* @export
* @class Events
*/
export default class Events {
@schmidtsonian
schmidtsonian / watcher.js
Created April 12, 2019 14:34
JavaScript Singleton watcher utility
// Events class is here: https://gist.github.com/schmidtsonian/8a023034a2f5600b455afd2e2aed7019
import Events from './events';
/**
* Watcher
*
* @class Watcher
*/
export default class Watcher {
@schmidtsonian
schmidtsonian / load-image.js
Created April 12, 2019 20:47
Creates and loads a single image
/**
* Creates and loads a single image
* @param {Object} attrs - Image element attributes
* @returns {Promise} {elm: img}
* @example
* loadImage({ src: 'foo.jpg', alt: 'foo' })
* .then(obj => console.log(obj.elem));
*/
export function loadImage(attrs) {
@schmidtsonian
schmidtsonian / load-video.js
Created April 12, 2019 20:48
Creates video and load it
/**
* Creates video and load it
* @param {Object} videoAttrs - Video element attributes
* @param {Object} sourceAttrs - Source element attributes
* @returns {Promise} {elm: video}
* @example
* loadVideo({autoPlay: false, controls: true}, {src: 'foo.webm', type: 'video/mp4'})
* .then(obj => console.log(obj.elem));
*/
export function loadVideo(videoAttrs, sourceAttrs) {
//https://stackoverflow.com/a/52357595/2690846
// usage: let frames = await extractFramesFromVideo("https://example.com/video.webm");
async extractFramesFromVideo(videoUrl: string, fps=3) {
return new Promise(async (resolve) => {
// fully download it first (no buffering):
let videoBlob = await fetch(videoUrl).then(r => r.blob());
let videoObjectUrl = URL.createObjectURL(videoBlob);
let video = document.createElement('video');