Skip to content

Instantly share code, notes, and snippets.

autocomplete="chrome-off"
const MIN_PASSWORD_LENGTH = 6;
const [data, setData] = React.useState({
name: '',
email: '',
password: '',
confirmPassword:''
})
const errors = {
name: '',
email: '',
<Switch>
{!user && <Redirect exact from='/' to='/auth' />}
// you can only place the Redirect component inside the Switch Component if you are using the from to sytax
{user && <Redirect exact from='/' to='/dashboard'/>}
{user && <Redirect from='/auth' to='/dashboard'/>}
<Route path='/auth' component={AuthPage}/>
<Route path='/landing' component={LandingPage} />
<Route path='/' component={ProjectPage}/>
</Switch>
// sign up route
Router.post('/signUp',cors(), async (req, res) => {
const {email, password, name, imgUrl} = req.body
if(!email || !password || !name) return res.status(400).json({msg: 'all fields are required'})
try {
const user = await User.findOne({email})
if(user) return res.status(400).json({msg: 'email already exists'})
//One could (or should) use it as a protoype from Array:
//From ChristopheD:
Array.prototype.shuffle = function() {
var i = this.length, j, temp;
if ( i == 0 ) return this;
while ( --i ) {
j = Math.floor( Math.random() * ( i + 1 ) );
temp = this[i];
@moaoa
moaoa / socket-cheatsheet.js
Created October 13, 2020 11:15 — forked from alexpchin/socket-cheatsheet.js
A quick cheatsheet for socket.io
// sending to sender-client only
socket.emit('message', "this is a test");
// sending to all clients, include sender
io.emit('message', "this is a test");
// sending to all clients except sender
socket.broadcast.emit('message', "this is a test");
// sending to all clients in 'game' room(channel) except sender
git push origin --all
// will push all branches to github
rmdir /s/q node_modules
// With a JSON doc
Person.
find({
occupation: /host/,
'name.last': 'Ghost',
age: { $gt: 17, $lt: 66 },
likes: { $in: ['vaporizing', 'talking'] } // see if the value of likes included in ['vaporizing, 'talking'] array
// syntax {property: {$in: array...}}
}).
limit(10).
// gnerate token function
const jwt = require('jsonwebtoken');
const jwtSecret = process.env.JWT_SECRET;
module.exports = (obj) => {
return jwt.sign(obj, jwtSecret, {
expiresIn: '1day',
});
};
// ==================