Skip to content

Instantly share code, notes, and snippets.

View perry-mitchell's full-sized avatar

Perry Mitchell perry-mitchell

View GitHub Profile
@perry-mitchell
perry-mitchell / nightmare_preload.js
Last active August 28, 2017 06:43
Nightmare Preload
window.__nightmare = {};
__nightmare.ipc = require('electron').ipcRenderer;
__nightmare.sliced = require('sliced');
// Listen for error events
window.addEventListener('error', function(e) {
__nightmare.ipc.send('page', 'error', e.message, e.error.stack);
});
(function(){
@perry-mitchell
perry-mitchell / gatekeeper.js
Last active July 31, 2017 11:05
Javascript malicious redirect prevention script
(function () {
const CLICK_ALLOWANCE = 5000; // ms
const KEYCODE_F5 = 116;
const KEYCODE_LETTER_R = 82;
const watchedElements = [];
let allowanceTimer = null;
function arr(nodelist) {
@perry-mitchell
perry-mitchell / find-common-parent.js
Created January 10, 2017 13:40
Find common parent element of n nodes
/**
* Find common parent node
*/
export function findCommonParent(...nodes) {
let nodeParents = nodes.map(node => findParents(node)),
firstNodeParents = nodeParents[0],
topParent = firstNodeParents[0];
if (nodeParents.some(parents => parents.indexOf(topParent) !== 0)) {
// no common parent
@perry-mitchell
perry-mitchell / .editorconfig
Last active January 29, 2017 15:50
Lint/Editor config MASTER
root = true
[*]
indent_style = space
end_of_line = lf
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
@perry-mitchell
perry-mitchell / .babelrc
Created December 6, 2016 19:01
Webpack2 + inject-loader2.0.1 (blog post)
{
"env": {
"testing": {
"presets": [
"es2015"
]
}
},
"presets": [
["es2015", { "modules": false }]
@perry-mitchell
perry-mitchell / .babelrc
Last active December 4, 2016 13:09
Webpack 2 + inject-loader 3
{
"presets": "es2015"
}
@perry-mitchell
perry-mitchell / .babelrc
Last active April 28, 2017 19:26
Webpack 2 + inject-loader 2
{
"presets": "es2015"
}
@perry-mitchell
perry-mitchell / split-semver.js
Created December 1, 2016 06:30
Semver splitting
"use strict";
const VALID_SEMVER = /^(\d+\.\d+\.\d+)(-[a-z1-9][a-z0-9]*(?:\.[a-z0-9]+)*)*(\+[a-z0-9]+(?:\.[a-z0-9]+)*)*$/i
let lib = module.exports = {
splitVersion: function(ver) {
let [,
version,
prerelease,
@perry-mitchell
perry-mitchell / .hyper.js
Created November 21, 2016 08:04
Hyperterm config 2016-11-21
module.exports = {
config: {
// default font size in pixels for all tabs
fontSize: 12,
// font family with optional fallbacks
fontFamily: 'Menlo, "DejaVu Sans Mono", "Lucida Console", monospace',
// terminal cursor background color and opacity (hex, rgb, hsl, hsv, hwb or cmyk)
cursorColor: 'rgba(248,28,229,0.8)',
@perry-mitchell
perry-mitchell / ecdh_iocane.js
Created November 12, 2016 16:19
ECDH key exchange with AES encryption using iocane
// To use this, you will need to `npm install iocane`!
const crypto = require("crypto");
let aliceECDH = crypto.createECDH("secp256k1");
aliceECDH.generateKeys();
let alicePublicKey = aliceECDH.getPublicKey(null, "compressed"),
alicePrivateKey = aliceECDH.getPrivateKey(null, "compressed");