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 / 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 / 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 / domReady.js
Created Jul 22, 2015
cross-browser dom ready helper
View domReady.js
(function (doc, w) {
"use strict";
var readyCallbacks = [],
docLoadEv = "DOMContentLoaded",
ready = (document.readyState === "complete");
function registerForReadyEvent(fn) {
if (ready) { //already ready, execute immediately
@yoavniran
yoavniran / addFrameConsciousEvent.js
Created Nov 1, 2015
ES6 animation frame conscious event listener
View addFrameConsciousEvent.js
const addFrameConsciousEvent = (obj, event, handler) => { //adapted from: https://developer.mozilla.org/en-US/docs/Web/Events/resize#Example
let isRunning = false;
const handlerWrapper = (e)=> {
if (!isRunning){
isRunning = true;
requestAnimationFrame(()=>{ //throttling so only execute when the browser is ready to re-render
isRunning = false;
handler(e);
})
@yoavniran
yoavniran / promiseActions.js
Last active May 11, 2018
promise actions - run methods in sequence or parallel using the power of JS Promises
View promiseActions.js
/**
* 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 / 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 / Image.js
Last active Sep 9, 2019
utility to generate breakpoints with cloudinary
View Image.js
import {getResponsiveAttributes} from "../getResponsiveAttributes";
const Image = ({publidId}) => {
const transformation = [{
quality: "auto",
fetchFormat: "auto",
dpr: 2,
},];
@yoavniran
yoavniran / RTLMarkdownWidget.js
Created Jul 25, 2019
right-to-left markdown widget for netlify-cms
View RTLMarkdownWidget.js
import React from "react";
import NetlifyCmsWidgetMarkdown from "netlify-cms-widget-markdown";
const name = "rtlmarkdown";
const PreviewComponent = NetlifyCmsWidgetMarkdown.previewComponent;
const OrgControlComponent = NetlifyCmsWidgetMarkdown.controlComponent;
const ControlComponent = React.forwardRef((props, ref) => {
return <div dir="rtl">