Skip to content

Instantly share code, notes, and snippets.

📖
writing. mostly code

Yoav Niran yoavniran

📖
writing. mostly code
Block or report user

Report or block yoavniran

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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">
@yoavniran
yoavniran / PreviewLayout.js
Created Jul 25, 2019
PreviewLayout for Gatsby & Netlify CMS to enable styled-components
View PreviewLayout.js
import React, { useRef, useLayoutEffect } from "react";
import { StyleSheetManager } from "styled-components";
import PreviewContext from "./PreviewContext";
const WithPreviewContext = ({ children }) =>
<PreviewContext.Provider value={true}>
<main>
{children}
</main>
</PreviewContext.Provider>;
@yoavniran
yoavniran / gatsby-netlify-form.js
Last active Jul 18, 2019
a gatsby-netlify contact form example
View gatsby-netlify-form.js
import React, { useContext, useState, } from "react";
import { navigate } from "gatsby";
import styled from "styled-components";
import { Box, Button } from "grommet";
import ReCaptcha from "react-google-recaptcha";
import { NotificationContext } from "../Notifications/NotificationProvider";
const isDev = process.env.NODE_ENV === "development";
const onRegisterSuccess = (navUrl) => {
@yoavniran
yoavniran / convertFromGridToInfiniteProps.js
Last active Aug 19, 2019
convert data from react-window Grid's onItemsRendered to data that react-window-infinite-loader's onItemsRendered understands
View convertFromGridToInfiniteProps.js
onItemsRendered = (gridData: Object) => {
const {useOverscanForLoading} = this.props; //default is true
const {
visibleRowStartIndex,
visibleRowStopIndex,
visibleColumnStopIndex,
overscanRowStartIndex,
overscanRowStopIndex,
overscanColumnStopIndex
@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 / 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 / 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
@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];
You can’t perform that action at this time.