Skip to content

Instantly share code, notes, and snippets.

@vikki
vikki / domRace.js
Created July 3, 2016 21:31
Element Poller + chooser - Streams based, returns all results (found + not found) - http://jsbin.com/mutuziqamu/1/edit?js,console,output
// requires Q
const NUMBER_OF_PLACEMENTS_REQUIRED = 1;
const MS_TO_WAIT = 7000;
const selectors = ['.wibble', '.bleuch', '.foo'];
function checkElement(selector, observer) {
var elementFound = document.querySelector(selector) !== null;
console.log(`el ${selector} = found : ${elementFound}`);
@vikki
vikki / domRace.js
Created July 3, 2016 21:24
Element Poller + chooser - Promise based, returns all results (found + not found) - http://jsbin.com/nitohuyilu/1/edit?js,console,output
// requires Q
const NUMBER_OF_PLACEMENTS_REQUIRED = 1;
const MS_TO_WAIT = 7000;
const selectors = ['.wibble', '.bleuch', '.foo'];
function checkElement(selector, observer) {
var elementFound = document.querySelector(selector) !== null;
console.log(`el ${selector} = found : ${elementFound}`);
@vikki
vikki / domRace.js
Last active July 3, 2016 21:24
Element Poller + chooser - Streams based, returns only matched elements (found + not found) - http://jsbin.com/calekubavi/edit?js,console,output
// requires RX.js
const NUMBER_OF_PLACEMENTS_REQUIRED = 1;
const MS_TO_WAIT = 7000;
const selectors = ['.wibble', '.bleuch'];
function checkElement(selector, observer) {
var elementFound = document.querySelector(selector) !== null;
console.log(`el ${selector} = found : ${elementFound}`);
@vikki
vikki / domRace.js
Last active July 3, 2016 21:25
Element Poller + chooser - Streams based, returns all results (found + not found) http://jsbin.com/calekubavi/edit?js,console,output
// requires RX.js
const NUMBER_OF_PLACEMENTS_REQUIRED = 1;
const MS_TO_WAIT = 7000;
const selectors = ['.wibble', '.bleuch'];
function checkElement(selector, observer) {
var elementFound = document.querySelector(selector) !== null;
console.log(`el ${selector} = found : ${elementFound}`);
@vikki
vikki / gist:7514320
Created November 17, 2013 14:54
SMR lodash goodness
var weWantToMeet = _.chain(smrDevs)
.filter(function isAwesome(smrDev) {
return smrDev.isAwesome;
})
.filter(function isEnthusiastic(smrDev) {
return smrDev.enthusiasmLevel === 'high';
})
.filter(function pingPongProficiency(smrDev) {
// not really :D
return smrDev.pingPongSkillz === 'badass';
<element extends="div" is="x-nyandiv">
<template>
<img src="http://www.nyan.cat/cats/skrillex.gif"
alt="wub">
</img>
<content select=".boring"></content>
</template>
</element>
<div is="x-nyandiv">
@vikki
vikki / webgl_video_texture.js
Created July 30, 2012 13:31
Using a video as a WebGL Texture
// using webgl-utils.js for *everything*
// and assuming you have a global called gl
// that's pointed to the webgl canvas context
// based on learningwebgl.com <3
function initTextureWith(videoUrl) {
var vidElement = document.createElement('video');
vidElement.onload = function () {
var texture = makeTextureFrom(this);
@vikki
vikki / webgl_img_texture.js
Created July 30, 2012 13:28
Using an image as a WebGL Texture
// using webgl-utils.js for *everything*
// and assuming you have a global called gl
// that's pointed to the webgl canvas context
// based on learningwebgl.com <3
function initTextureWith(imgUrl) {
var imgElement = new Image();
imgElement.onload = function () {
var texture = makeTextureFrom(this);
@vikki
vikki / webgl_npot_fix.js
Created July 30, 2012 13:25
Avoiding NPOT Problems with X-Domain Images in WebGL
// the NPOT fix is taken from :
// http://www.khronos.org/webgl/wiki/WebGL_and_OpenGL_Differences
function makeSuitableForTexture(srcElement) {
srcElement.crossOrigin = '';
// it probs should be image.width not image.videoWidth or clientWidth but doesn't work with <video>
// TODO fixme
if (srcElement.tagName === 'IMG') {
var width = srcElement.width;
@vikki
vikki / yt_video_proxy.py
Created July 30, 2012 13:21
YouTube HTML5 Video Proxy
ytVideoUrlMatcher = r'url_encoded_fmt_stream_map=url=([^&]*)&'
ytVideoInfoUrlBase = 'http://www.youtube.com/get_video_info?html5=1&video_id='
def getHTML5VideoFileFromYouTube(videoId):
videoInfoUrl = ytVideoInfoUrlBase + videoId
videoInfoFile = urllib2.urlopen(videoInfoUrl)
videoInfo = urllib2.unquote(videoInfoFile.read())
vidMatch = re.search(ytVideoUrlMatcher, videoInfo)
videoUrl = vidMatch.groups(0)[0]