Skip to content

Instantly share code, notes, and snippets.

@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 / google.md
Created August 27, 2016 08:12
Google search
@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 / 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 / gist:4baead030f7dd4e690d56a3b884803c6
Created August 26, 2016 07:18 — forked from callmephilip/gist:3517765
[JavaScript] Dispatching mouse move event
// look here for more details : https://developer.mozilla.org/en-US/docs/DOM/event.initMouseEvent
var mouseMoveEvent = document.createEvent("MouseEvents");
mouseMoveEvent.initMouseEvent(
"mousemove", //event type : click, mousedown, mouseup, mouseover, mousemove, mouseout.
true, //canBubble
false, //cancelable
window, //event's AbstractView : should be window
1, // detail : Event's mouse click count
@weisk
weisk / 13-async.js
Created August 12, 2016 17:57
learnyounode 13 async
var http = require('http');
var requests = process.argv.slice(2);
var results = [];
var count = 0;
for (var i = 0, len = requests.length; i < len; i++) {
getRequest(requests[i], i);
}
@weisk
weisk / promise_deferred.js
Created August 8, 2016 17:04
Promise ES6 deferred helper
function Deferred() {
var resolve, reject;
var promise = new Promise((resolver, rejector) => {
resolve = resolver;
reject = rejector;
});
return {
promise,
resolve,
reject
@weisk
weisk / lodash-data-transformation.md
Created August 6, 2016 09:02
Lodash snippets - data transformation

Sort object by values

let doo = {Derp: 17, Herp: 2, Asd: 5, Foo: 8, Qwe: 12};

let foo = _.chain(doo)
  .map((val, key) => {
    return { name: key, count: val }
  })
  .sortBy('count')
 .reverse()
@weisk
weisk / levenshtein.js
Created July 2, 2016 15:08 — forked from andrei-m/levenshtein.js
Levenshtein distance between two given strings implemented in JavaScript and usable as a Node.js module
/*
Copyright (c) 2011 Andrei Mackenzie
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
@weisk
weisk / introrx.md
Created December 25, 2015 21:15 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing