Skip to content

Instantly share code, notes, and snippets.

Alexandru Vlăduţu alessioalex

View GitHub Profile
@alessioalex
alessioalex / shortcut.js
Created Mar 7, 2016
Related to https://twitter.com/timferro/status/705189339890843648 - notify when the user types in a certain word / sequence of chars
View shortcut.js
function shortcut(shortcutKeys, callback) {
var code = shortcutKeys.toString();
var keys = [];
document.addEventListener('keydown', function(evt) {
keys.push(evt.keyCode);
if (keys.length > shortcutKeys.length) {
keys.shift();
}
@alessioalex
alessioalex / serially-iterating-array.js
Last active Feb 9, 2016
Serially Iterating An Array, Asynchronously
View serially-iterating-array.js
function run(steps, data, done) {
// our recursion exit strategy:
// no items left? we're done.
if (steps.length === 0) {
return done();
}
// get the first item in the array
var step = steps.shift();
@alessioalex
alessioalex / such-wow.js
Created Feb 3, 2016
ES6 Proxy magic for arrays
View such-wow.js
// https://curiosity-driven.org/array-slices#mimicking-array
function emulateArray(obj) {
var length = obj.length || 0;
return new Proxy(obj, {
get: function(target, property) {
if (property === 'length') {
return length;
}
if (property in target) {
View mutation-observer.js
var observer = new MutationObserver(function(mutations) {
//console.log('OBSERVED', mutations);
var observation = parseInt(Math.random() * 100);
console.group('Observation ' + observation);
mutations.forEach(function(mutation) {
console.log('%s: %s', mutation.target.nodeName, mutation.type, mutation);
});
console.groupEnd();
});
var config = {childList: true, attributes: true, characterData: true, subtree: true, attributeOldValue: true, characterDataOldValue: true};
@alessioalex
alessioalex / debug-events.js
Last active May 9, 2020
intercept *.addEventListener for debugging
View debug-events.js
// http://stackoverflow.com/questions/4787698/failure-to-override-elements-addeventlistener-in-firefox
(function() {
Error.stackTraceLimit = Infinity;
var _interfaces = Object.getOwnPropertyNames(window).filter(function(i) {
return /^HTML/.test(i);
}).map(function(i) {
return window[i];
});
View infinite-loop-trick.log
$ cat test.js
function foo () { while (true) { } }
function bar () { return foo(); }
bar();
$ node test.js &
$ gdb attach $(pidof node)
0x00000bf778c63d5f in ?? ()
(gdb) b v8::internal::Runtime_StackGuard
Breakpoint 1 at 0x84a1f0
(gdb) print 'v8::V8::TerminateExecution'(0)
@alessioalex
alessioalex / zombies.js
Created May 18, 2015
zombie processes nodejs
View zombies.js
// http://stackoverflow.com/questions/12871740/how-to-detach-spawned-child-process-in-a-node-js-script
// https://nodejs.org/api/child_process.html#child_process_options_detached
// var fs = require('fs');
// var out = fs.openSync('./out.log', 'a');
// var err = fs.openSync('./out.log', 'a');
var cp = require('child_process');
// var child = cp.spawn('node', ['zombie.js'], { detached: true, stdio: [ 'ignore', out, err ] });
var child = cp.spawn('node', ['zombie.js'], { detached: true, stdio: [ 'ignore' /* stdin */, 'ignore' /* stdout */, 'ignore' /* stderr */ ] });
@alessioalex
alessioalex / reddit.js
Created May 8, 2015
reddit cli node app
View reddit.js
"use strict";
var growl = require('growl');
var request = require('request');
var argv = require('minimist')(process.argv.slice(2));
var JSONStream = require('JSONStream');
var assert = require('assert');
var through = require('through');
var ms = require('ms');
var chalk = require('chalk');
@alessioalex
alessioalex / exotics.md
Last active Aug 29, 2015
Destiny exotic weapons checklist (pre-HoW)
You can’t perform that action at this time.