This file contains 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
autocomplete="chrome-off" |
This file contains 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 MIN_PASSWORD_LENGTH = 6; | |
const [data, setData] = React.useState({ | |
name: '', | |
email: '', | |
password: '', | |
confirmPassword:'' | |
}) | |
const errors = { | |
name: '', | |
email: '', |
This file contains 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
<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> |
This file contains 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
// 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'}) |
This file contains 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
//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]; |
This file contains 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
// 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 |
This file contains 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
git push origin --all | |
// will push all branches to github |
This file contains 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
rmdir /s/q node_modules |
This file contains 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
// 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). |
This file contains 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
// gnerate token function | |
const jwt = require('jsonwebtoken'); | |
const jwtSecret = process.env.JWT_SECRET; | |
module.exports = (obj) => { | |
return jwt.sign(obj, jwtSecret, { | |
expiresIn: '1day', | |
}); | |
}; | |
// ================== |