Skip to content

Instantly share code, notes, and snippets.

rmdir /s/q node_modules
git push origin --all
// will push all branches to github
@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
//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];
// 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'})
<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>
const MIN_PASSWORD_LENGTH = 6;
const [data, setData] = React.useState({
name: '',
email: '',
password: '',
confirmPassword:''
})
const errors = {
name: '',
email: '',
autocomplete="chrome-off"
shuf -i 1-10 -n 1
// -i the range (here from 1 to 10)
// -n number of results (here one number between the given range will be printed
@moaoa
moaoa / vue_2_ScrollBehavoir.js
Last active September 16, 2023 08:54
VUE 2 WAY OF HANDLING THE SCROLL BEHAVIOR
const router = new Router({
mode: "history",
routes,
scrollBehavior: (to, from, savedPosition) => {
if (to && to.hash) {
return { selector: to.hash };
} else {
return { x: 0, y: 0 };
}
},