Skip to content

Instantly share code, notes, and snippets.

Avatar
📖
Writing. Code & Prose

Yoav Niran yoavniran

📖
Writing. Code & Prose
View GitHub Profile
@yoavniran
yoavniran / SimpleAuthTransporter.js
Last active Aug 29, 2015
class used to allow making authorized requests to google API that also allows streaming the response even if a token refresh is required
View SimpleAuthTransporter.js
"use strict";
var util = require("util"),
_ = require("underscore"),
events = require("events"),
request = require("request"),
AppAuthClient = require("../google/AppAuthClient"); //thin wrapper around the google oauth2client - simply initializing it with app's client id and secret
var SimpleAuthTransporter= (function () {
@yoavniran
yoavniran / node-remove-dir.js
Last active May 13, 2020
Node async & recursive dir remove
View node-remove-dir.js
"use strict";
var path = require("path"),
fs = require("fs");
module.exports = (function(){
/**
* recursively remove the fs structure starting from (and including) the path given in dirToRemove
* @param dirToRemove
* the path to remove
@yoavniran
yoavniran / simple-nodejs-iv-encrypt-decrypt.js
Last active Feb 23, 2021
nodejs crypto - simple encrypt & decrypt using IV (Initialization Vector)
View simple-nodejs-iv-encrypt-decrypt.js
"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) ;
@yoavniran
yoavniran / chart.css
Created Oct 12, 2014
d3 bar chart with rising bars transition
View chart.css
.myChart text {
fill: white;
font: 10px sans-serif;
text-anchor: end;
}
.axis text {
fill: black;
}
@yoavniran
yoavniran / selector.js
Last active Aug 29, 2015
function to select element even using a numeric class name on IE8
View selector.js
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 / Venter.js
Last active Aug 29, 2015
a simple pub/sub class for node with support for scopes
View Venter.js
/**
*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*
* SEE MY venter NPM PACKAGE - https://www.npmjs.org/package/venter
* OR REPOSITORY ON GITHUB - https://github.com/yoavniran/node-venter
*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@yoavniran
yoavniran / mocha-hooks-order.js
Created Apr 11, 2015
shows how mocha hooks are ordered and run within contexts
View mocha-hooks-order.js
describe("root context", function(){
before(function(){
console.log("before: root");
});
beforeEach(function(){
console.log("beforeEach: root");
});
@yoavniran
yoavniran / ultimate-ut-cheat-sheet.md
Last active Apr 22, 2021
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai, Sinon, and Jest
View ultimate-ut-cheat-sheet.md
@yoavniran
yoavniran / extender.js
Last active Aug 29, 2015
JS Type Extender (inspired by backbone.js)
View extender.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 / gitbashAdmin.bat
Created Jul 14, 2015
ConEmu - Run GitBash as Admin
View gitbashAdmin.bat
"%ConEmuDrive%\Program Files (x86)\Git\bin\sh.exe" --login -i -new_console:a