Skip to content

Instantly share code, notes, and snippets.

@weisk
weisk / gist:6e9cf120f441f2ed917a74568638cfef
Created August 26, 2016 07:25 — forked from callmephilip/gist:3519403
[JavaScript] Dispatching keyboard event
// gecko and webkit
// details here https://developer.mozilla.org/en-US/docs/DOM/event.initKeyEvent
var keyboardEvent = document.createEvent("KeyboardEvent");
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? "initKeyboardEvent" : "initKeyEvent";
keyboardEvent[initMethod](
"keydown", // event type : keydown, keyup, keypress
true, // bubbles
@weisk
weisk / url.js
Created August 27, 2016 06:32
URL Helpers
define([
'lodash'
], function(_) {
// Regular expressions
var digitTest = /^\d+$/,
keyBreaker = /([^\[\]]+)|(\[\])/g,
plus = /\+/g,
paramTest = /([^?#]*)(#.*)?$/;
@weisk
weisk / 0_reuse_code.js
Created August 28, 2016 05:19
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
@weisk
weisk / arrayzing.md
Last active August 28, 2016 05:23 — forked from ourmaninamsterdam/LICENSE
Arrayzing - The JavaScript array cheatsheet
@weisk
weisk / prime_generator.js
Created September 29, 2016 08:45 — forked from ajace/prime_generator.js
nodejs script to generate prime numbers
#!/usr/bin/env node
var fs = require('fs');
var outfile = "primes.txt";
var count = 0;
var maxCount = 100;
var primes = [];
var i = 2;
@weisk
weisk / index.js
Created June 1, 2017 12:36
es2017 node starter boilerplate
import something from './somewhere';
export default function() {
console.log('hi');
}
@weisk
weisk / html5-video-streamer.js
Created June 9, 2017 00:18 — forked from lleo/html5-video-streamer.js
This is an enhancement to Gist#1993068 https://gist.github.com/paolorossi/1993068 . I found what was needed to demonstrate a functioning video stream was a HTML file with a <video> tag pointing to the streamer.
#!/usr/bin/env node
/*
* Inspired by: http://stackoverflow.com/questions/4360060/video-streaming-with-html-5-via-node-js
* Modified from https://gist.github.com/paolorossi/1993068
*/
var http = require('http')
, fs = require('fs')
, util = require('util')
@weisk
weisk / i18n.js
Created October 7, 2017 22:02
Util.promisify example - read files from directory, parse JSONs, copy
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const { promisify } = require('util');
const { ncp } = require('ncp');
const readDir = promisify(fs.readdir);
const readFile = promisify(fs.readFile);
const copyDir = promisify(ncp);
@weisk
weisk / index.js
Created September 30, 2018 21:32
Babel node starter 2018
(async () => {
console.log('hi!');
})()
@weisk
weisk / script.js
Created March 1, 2019 03:21
randomest in js
// window
let array = new Uint32Array(10);
crypto.getRandomValues(array);
// node
crypto.randomBytes(10).toString('utf8');