Skip to content

Instantly share code, notes, and snippets.

'use strict';
document.head.innerHTML = '';
document.body.innerHTML = '';
[0, 1].forEach((i) => {
const iframe = document.createElement('iframe');
iframe.src = location.href;
iframe.style.position = 'fixed';
iframe.style.left = (i === 0 ? '0' : '50vw');
(() => {
'use strict';
let mousePos = null;
window.addEventListener('mousemove', evt => {
mousePos = {
x: evt.pageX,
y: evt.pageY,
};
});
'use strict';
const loadSrcLocation = (locationStr, contextRadius = 5) => {
const parts = locationStr.split(':');
const col = Number(parts[parts.length - 1]);
const lineNo = Number(parts[parts.length - 2]);
const url = parts.slice(0, parts.length - 2).join(':');
return fetch(url)
.then(res => res.text())
'use strict';
const createElement = (tag, styles = {}) => {
const el = document.createElement(tag);
for (const [key, value] of Object.entries(styles)) {
el.style[key] = value;
}
return el;
'use strict';
window.addEventListener('load', () => {
const dot = document.createElement('div');
for (const [key, val] of Object.entries({
position: 'absolute',
left: '0px',
top: '0px',
borderRadius: '100%',
'use strict';
const imgUrls = Array.prototype.slice.apply(document.querySelectorAll('img')).map(img => img.src);
document.body.innerHTML = '';
const cover = document.createElement('div');
for (const [key, value] of Object.entries({
position: 'absolute',
left: '0px',
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
module.exports = function PositionalAudioPlayer(stream, leftRightBalance = 0.5) {
const player = {};
const audioCtx = new AudioContext();
const source = audioCtx.createMediaStreamSource(stream);
const splitter = audioCtx.createChannelSplitter(2);
@voltrevo
voltrevo / hslToRgb.ts
Last active January 1, 2017 10:30
Goldbach's Comet
// Ported to TypeScript from https://github.com/kayellpeee/hsl_rgb_converter/blob/master/converter.js
export default function hslToRgb(hue: number, saturation: number, lightness: number): [number, number, number] {
// based on algorithm from http://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB
if( hue == undefined ){
return [0, 0, 0];
}
var chroma = (1 - Math.abs((2 * lightness) - 1)) * saturation;
var huePrime = hue / 60;
var secondComponent = chroma * (1 - Math.abs((huePrime % 2) - 1));
'use strict';
window.addEventListener('load', () => {
const txt = document.createElement('span');
document.body.appendChild(txt);
const btn = document.createElement('button');
document.body.appendChild(btn);
let money = 100;
let target = 101;
@voltrevo
voltrevo / gift.js
Last active December 3, 2016 08:51
'use strict';
const range = (n) => (new Array(n)).fill(0).map((x, i) => i);
const stdNormalRand = () => {
const u = 1 - Math.random(); // Subtraction to flip [0, 1) to (0, 1].
const v = 1 - Math.random();
return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
};