Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Carter Cole neopunisher

🎯
Focusing
View GitHub Profile
View injectIpfs.js
(function(url, inj) {
inj(url).then(function() {
const node = new Ipfs()
node.on('error', errorObject => console.error(errorObject))
node.on('ready', () => {
console.log('nodeready')
node.stop(() => {
console.log('node gone')
})
@neopunisher
neopunisher / generateWorker.js
Created May 29, 2018
generates a web worker from a function
View generateWorker.js
(function(){
function aWorker(){
onmessage = function(e) {
console.log('Message received from main script');
var workerResult = 'Result: ' + (e.data[0] * e.data[1]);
console.log('Posting message back to main script');
postMessage(workerResult);
}
var i = 0;
View injectUltrasonics.js
(function(url, inj) {
inj(url).then(function() {
var ALPHABET = '0123456789';
var MESSAGE = '314159';
var button = document.createElement('button');
document.body.appendChild(button)
button.addEventListener('click', onButton);
function onButton() {
@neopunisher
neopunisher / speechCommands.js
Created May 26, 2018
control stuff with your voice in the browser
View speechCommands.js
(function(url, inj) {
inj(url).then(function() {
if (annyang) {
// Let's define a command.
var commands = {
'hello': function() { alert('Hello world!'); }
};
// Add our commands to annyang
@neopunisher
neopunisher / screenshotHtml.js
Created May 26, 2018
take a pic of the current html with svg magic
View screenshotHtml.js
(function(url, inj) {
inj(url).then(function() {
html2canvas(document.body).then(function(canvas) {
document.body.appendChild(canvas);
});
})
})('https://html2canvas.hertzen.com/dist/html2canvas.min.js', (src, head = true) => new Promise(function(c, d) {
@neopunisher
neopunisher / youtube-screencap.js
Created May 25, 2018
take high quality screen stills from youtube with a button
View youtube-screencap.js
(function(a){var b=a.createElement("button");b.innerText="Screencap";b.onclick=function(){var d=a.querySelector("video"),e=a.createElement("canvas"),b=e.getContext("2d"),c=a.createElement("a");e.width=d.videoWidth;e.height=d.videoHeight;b.drawImage(d,0,0);c.download=[ytcsi.data_.info.docid,d.currentTime,".png"].join("-");c.href=e.toDataURL();a.body.appendChild(c);c.click();a.body.removeChild(c)};a.querySelector("h1.title").appendChild(b)})(document);
@neopunisher
neopunisher / voicejammer.js
Created May 24, 2018
put on headphones and try and talk
View voicejammer.js
var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioContext = new AudioContext();
var synthDelay = audioContext.createDelay(0.2);
synthDelay.connect(audioContext.destination)
// request audio stream from the user's webcam
navigator.mediaDevices.getUserMedia({
audio: true
})
.then(function (stream) {
@neopunisher
neopunisher / injectSientinal.js
Created May 23, 2018
does stuff when things are added to the page... via https://github.com/muicss/sentineljs
View injectSientinal.js
(function(style, func){
document.addEventListener('sentinel-load', function(){
sentinel.on(style, func);
})
var a=document.createElement("script");a.src='//cdn.rawgit.com/muicss/sentineljs/0.0.4/dist/sentinel.min.js';a.type="text/javascript";
document.head.appendChild(a);
})('.my-div', function(el) {
el.innerHTML = 'The sentinel is always watching.';
})
View dsl_fiz_buz.js
let tokens = [];
let dsl = new Proxy({}, {
get(state, token) {
// Before anything, we're going to try and access a variable
if (tokens.length === 0 && state[token] !== undefined) {
return state[token];
}
tokens.push(token);
const rule = grammar[tokens[0]];
View injectPoseNet.js
(function(url1, url2, url3, inj) {
inj(url1).then(() => inj(url2)).then(() => inj(url3)).then(async function() {
var canvas = document.createElement('canvas')
var ctx = canvas.getContext('2d');
const net = await posenet.load();
var processfn = async function(video, dt) {
ctx.drawImage(video, 0, 0);