Skip to content

Instantly share code, notes, and snippets.

Avatar
📖
Writing. Code & Prose

Yoav Niran yoavniran

📖
Writing. Code & Prose
View GitHub Profile
@yoavniran
yoavniran / ultimate-ut-cheat-sheet.md
Last active May 6, 2021
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai, Sinon, and Jest
View ultimate-ut-cheat-sheet.md
@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 / simple-nodejs-iv-encrypt-decrypt.js
Last active May 1, 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 / usePasteUpload.jsx
Created Mar 21, 2021
react-uploady usePasteUpload custom hook example
View usePasteUpload.jsx
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 / paste-to-upload.jsx
Created Mar 21, 2021
react-uploady paste to upload example
View paste-to-upload.jsx
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 / 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 / App.jsx
Last active Sep 14, 2020
react-native uploady demo - app
View App.jsx
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 Sep 14, 2020
react-native uploady demo - styles
View App.styles.jxs
const styles = StyleSheet.create({
uploadedImage: {
width: 400,
height: 400,
resizeMode: 'cover',
},
body: {
backgroundColor: "#ffffff",
},
sectionContainer: {
@yoavniran
yoavniran / app.upload.jsx
Created Sep 14, 2020
react-native uploady demo - upload
View app.upload.jsx
const Upload = () => {
const [uploadUrl, setUploadUrl] = useState(false);
const uploadyContext = useContext(UploadyContext);
useItemFinishListener((item) => {
const response = JSON.parse(item.uploadResponse.data);
console.log(`item ${item.id} finished uploading, response was: `, response);
setUploadUrl(response.url);
});
@yoavniran
yoavniran / ItemPreviewWithCrop.jsx
Last active Jul 8, 2020
ItemPreviewWithCrop.jsx - react-uploady demo
View ItemPreviewWithCrop.jsx
import ReactCrop from "react-image-crop";
import { withRequestPreSendUpdate, useItemFinalizeListener } from "@rpldy/uploady";
import { PREVIEW_TYPES } from "@rpldy/upload-preview";
import cropImage from "./image-crop-helper";
const ItemPreviewWithCrop = withRequestPreSendUpdate(props => {
const { id, url, isFallback, type, updateRequest, requestData, previewMethods } = props;
const [finished, setFinished] = useState(false);
const [crop, setCrop] = useState(null);