Skip to content

Instantly share code, notes, and snippets.

View yoavniran's full-sized avatar
📖
Writing. Code & Prose

Yoav Niran yoavniran

📖
Writing. Code & Prose
View GitHub Profile
@yoavniran
yoavniran / promiseActions.js
Last active May 11, 2018 09:00
promise actions - run methods in sequence or parallel using the power of JS Promises
/**
* accepts n methods in sequence as arguments and returns a promise that is resolved
* once all methods finish.
* any argument may be an array of methods instead of a method itself. in this case, the array methods
* will be run in parallel
* any of the passed in methods may return a promise or any other type
*
* the results of the previous methods is handed over to the next method
*
* the last parameter may be an object containing one or both: {context, data}
@yoavniran
yoavniran / domReady.js
Created July 22, 2015 09:36
cross-browser dom ready helper
(function (doc, w) {
"use strict";
var readyCallbacks = [],
docLoadEv = "DOMContentLoaded",
ready = (document.readyState === "complete");
function registerForReadyEvent(fn) {
if (ready) { //already ready, execute immediately
@yoavniran
yoavniran / gitbashAdmin.bat
Created July 14, 2015 06:32
ConEmu - Run GitBash as Admin
"%ConEmuDrive%\Program Files (x86)\Git\bin\sh.exe" --login -i -new_console:a
@yoavniran
yoavniran / extender.js
Last active August 29, 2015 14:24
JS Type Extender (inspired by backbone.js)
//IE9+
(function () {
"use strict";
function merge(){ //shallow copy
var root = arguments[0], fromObj;
for (var i = 1; i < arguments.length; i++) {
fromObj = arguments[i];
@yoavniran
yoavniran / ultimate-ut-cheat-sheet.md
Last active April 13, 2024 16:19
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai, Sinon, and Jest
@yoavniran
yoavniran / mocha-hooks-order.js
Created April 11, 2015 13:35
shows how mocha hooks are ordered and run within contexts
describe("root context", function(){
before(function(){
console.log("before: root");
});
beforeEach(function(){
console.log("beforeEach: root");
});
@yoavniran
yoavniran / Venter.js
Last active August 29, 2015 14:07
a simple pub/sub class for node with support for scopes
/**
*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*
* SEE MY venter NPM PACKAGE - https://www.npmjs.org/package/venter
* OR REPOSITORY ON GITHUB - https://github.com/yoavniran/node-venter
*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@yoavniran
yoavniran / selector.js
Last active August 29, 2015 14:07
function to select element even using a numeric class name on IE8
var _selectorRgx = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/ ; //stole from jquery, to be used to quicken selector if simple class/id/tag selector used
/**
* stole the regex logic from jquery, added the support for classname selector starting with a number on IE8
* for example selector = ".1111" will work with this code even on IE8
**/
function select(selector) {
var match = _selectorRgx.exec(selector),
doc = window.document,
@yoavniran
yoavniran / chart.css
Created October 12, 2014 06:44
d3 bar chart with rising bars transition
.myChart text {
fill: white;
font: 10px sans-serif;
text-anchor: end;
}
.axis text {
fill: black;
}
@yoavniran
yoavniran / simple-nodejs-iv-encrypt-decrypt.js
Last active January 20, 2022 08:16
nodejs crypto - simple encrypt & decrypt using IV (Initialization Vector)
"use strict";
var crypto = require("crypto");
var EncryptionHelper = (function () {
function getKeyAndIV(key, callback) {
crypto.pseudoRandomBytes(16, function (err, ivBuffer) {
var keyBuffer = (key instanceof Buffer) ? key : new Buffer(key) ;