This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const loadImage = src => | |
new Promise((resolve, reject) => { | |
const img = new Image(); | |
img.onload = () => resolve(img); | |
img.onerror = reject; | |
img.src = src; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import Dropzone from 'react-dropzone' | |
import { act, fireEvent, render, waitFor } from '@testing-library/react' | |
test('invoke onDragEnter when dragenter event occurs', async () => { | |
const file = new File([ | |
JSON.stringify({ping: true}) | |
], 'ping.json', { type: 'application/json' }) | |
const data = mockData([file]) | |
const onDragEnter = jest.fn() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let size = prompt("size?"); | |
for(let i=1; i<=size; i++) console.log("#".repeat(i)); | |
let size = prompt("size?") | |
for(let i=1; i<= size; i++){ | |
let buffer = ' '.repeat(size-i) | |
let side = '#'.repeat(i-1) | |
console.log(`${buffer}${side} ${side}${buffer}`); | |
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function dragElement(elmnt, dragElement = elmnt) { | |
let pos1 = 0; | |
let pos2 = 0; | |
let pos3 = 0; | |
let pos4 = 0; | |
dragElement.onmousedown = dragMouseDown; | |
function dragMouseDown(e) { | |
e = e || window.event; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function arrayBufferToString (buffer, encoding = 'UTF-8', callback = console.log) { | |
const blob = new Blob([buffer], { type: 'text/plain' }) | |
const reader = new FileReader() | |
reader.onload = evt => callback(evt.target.result) | |
reader.readAsText(blob, encoding) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function streamToString (stream) { | |
const chunks = [] | |
return new Promise((resolve, reject) => { | |
stream.on('data', (chunk) => chunks.push(Buffer.from(chunk))) | |
stream.on('error', (err) => reject(err)) | |
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8'))) | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Longhand | |
switch (data) { | |
case 'a': | |
test1(); | |
break; | |
case 'b': | |
test2(); | |
break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findCustomerCity(name) { | |
const texasCustomers = ['John', 'Ludwig', 'Kate']; | |
const californiaCustomers = ['Wade', 'Lucie','Kylie']; | |
return texasCustomers.includes(name) ? 'Texas' : | |
californiaCustomers.includes(name) ? 'California' : 'Unknown'; | |
}; | |
// For every call, memory is unnecessarily re-allocated to the variables texasCustometrs and californiaCustomers . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function readFile(file: File | null) { | |
const reader = new FileReader(); | |
reader.addEventListener("load", (event) => { | |
const result = event.target.result; | |
console.log(result); | |
}); | |
reader.addEventListener("progress", (event) => { |
NewerOlder