• Mar 11, 2021 •C S
0 likes • 1 view
const mongoose = require('mongoose') const UserSchema = new mongoose.Schema({ username: { type: String, required: true }, email: { type: String, unique: true, required: true }, password: { type: String, required: true }, date: { type: Date, default: Date.now } }) module.exports = User = mongoose.model('user', UserSchema)
• Jan 25, 2023 •C S
0 likes • 24 views
const ResponsiveCardImg = styled(Card.Img)` // For screens wider than 768px @media(min-width: 768px) { // Your responsive styles here. } // For screens smaller than 768px @media(max-width: 768px) { // Your responsive styles here. } ` export default function App() { return ( <MainContainer> <Container> <Card text='white' bg='dark' style={styles.mainCard}> <ResponsiveCardImg style={styles.cardImage} onClick={handleClick} src={apeImage} alt='Degenerate Ape Academy' /> <Card.Body> <Card.Title className='text-center' as='h2'> {apeId} </Card.Title> </Card.Body> </Card> </Container> </MainContainer> ); }
• Nov 19, 2022 •CodeCatch
0 likes • 0 views
const shuffle = ([...arr]) => { let m = arr.length; while (m) { const i = Math.floor(Math.random() * m--); [arr[m], arr[i]] = [arr[i], arr[m]]; } return arr; }; const foo = [1, 2, 3]; shuffle(foo); // [2, 3, 1], foo = [1, 2, 3]
const insertionSort = arr => arr.reduce((acc, x) => { if (!acc.length) return [x]; acc.some((y, j) => { if (x <= y) { acc.splice(j, 0, x); return true; } if (x > y && j === acc.length - 1) { acc.splice(j + 1, 0, x); return true; } return false; }); return acc; }, []); insertionSort([6, 3, 4, 1]); // [1, 3, 4, 6]
• Nov 18, 2022 •AustinLeath
const dragAndDropDiv = editor.container; dragAndDropDiv.addEventListener('dragover', function(e) { e.stopPropagation(); e.preventDefault(); e.dataTransfer.dropEffect = 'copy'; }); dragAndDropDiv.addEventListener("drop",function(e){ // Prevent default behavior (Prevent file from being opened) e.stopPropagation(); e.preventDefault(); const files = e.dataTransfer.items; // Array of all files console.assert(files.length >= 1); if (files[0].kind === 'file') { var file = e.dataTransfer.items[0].getAsFile(); const fileSize = file.size; const fileName = file.name; const fileMimeType = file.type; reader = new FileReader(); reader.onloadend = function(){ editor.setValue(reader.result); } reader.readAsText(file); }else{ //Maybe handle if text is dropped console.log(files[0].kind); } });
const gcd = (...arr) => { const _gcd = (x, y) => (!y ? x : gcd(y, x % y)); return [...arr].reduce((a, b) => _gcd(a, b)); }; gcd(8, 36); // 4 gcd(...[12, 8, 32]); // 4