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 / 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 / paste-to-upload.jsx
Created March 21, 2021 12:15
react-uploady paste to upload example
import React from "react";
import styled from "styled-components";
import Uploady from "@rpldy/uploady";
import UploadDropZone from "@rpldy/upload-drop-zone";
import withPasteUpload from "@rpldy/upload-paste";
const StyledDropZone = styled(UploadDropZone)`
width: 400px;
height: 400px;
border: 1px solid #000;
@yoavniran
yoavniran / PreviewLayout.js
Created July 25, 2019 08:55
PreviewLayout for Gatsby & Netlify CMS to enable styled-components
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 / 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) ;
@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 / useIsMounted.js
Created June 16, 2021 07:53
useIsMounted React hook
import { useEffect, useRef, useCallback } from "react";
const useIsMounted = () => {
const mountedRef = useRef(true);
useEffect(() => {
return () => {
mountedRef.current = false;
};
}, []);
@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 / usePasteUpload.jsx
Created March 21, 2021 12:49
react-uploady usePasteUpload custom hook example
import React from "react";
import Uploady from "@rpldy/uploady";
import { usePasteUpload } from "@rpldy/upload-paste";
const ElementPaste = (props) => {
const containerRef = useRef(null);
const onPasteUpload = useCallback(({ count }) => {
console.log("ELEMENT PASTE-TO-UPLOAD files: ", count);
}, []);
@yoavniran
yoavniran / App.jsx
Last active September 14, 2020 12:05
react-native uploady demo - app
import React, { useState, useCallback, useContext } from "react";
import { SafeAreaView, StyleSheet, ScrollView, View, Text, StatusBar, Button, ImageBackground, Image } from "react-native";
import DocumentPicker from "react-native-document-picker/index";
import NativeUploady, {
UploadyContext,
useItemFinishListener,
useItemStartListener,
useItemErrorListener,
@yoavniran
yoavniran / App.styles.jxs
Created September 14, 2020 11:51
react-native uploady demo - styles
const styles = StyleSheet.create({
uploadedImage: {
width: 400,
height: 400,
resizeMode: 'cover',
},
body: {
backgroundColor: "#ffffff",
},
sectionContainer: {