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
// max operations that can be performed in a batch | |
export const MAX_BATCH_SIZE = 500 | |
export async function addDoc(collectionRef: string, data: Record<any, any>) { | |
const database = getFirestoreDatabase() | |
return await addDocFirebase(collection(database, collectionRef), data) | |
} | |
export async function setDoc(docRef: string, data: Record<any, any>) { |
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
// Heres how to start micro server without running "npx micro" command:- | |
// just run node <filename> to execute the file: | |
const { ApolloServer } = require('apollo-server-micro'); | |
const typeDefs = require('./type-defs'); | |
const resolvers = require('./resolvers'); | |
const micro = require('micro'); | |
const apolloServer = new ApolloServer({ typeDefs, resolvers }); | |
const startingServer = apolloServer.start(); |
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
import { useSession } from "next-auth/react" | |
import { useRouter } from "next/router" | |
// It only renders the children if user is authenticated, otherwise it will redirect to | |
// redirect Url. | |
function Auth({ children, waitContent = null, redirectUrl }) { | |
const { data: session, status } = useSession() | |
const loading = status === "loading" | |
const router = useRouter() |
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
export function useDocumentClickListener(eventListener) { | |
useEffect(() => { | |
document.addEventListener("click", eventListener) | |
return () => document.removeEventListener("click", eventListener) | |
}, [eventListener]) | |
return null | |
} |
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
{ | |
"products": [ | |
{ | |
"id": 1, | |
"title": "Product 1", | |
"price": "1000", | |
"desc": "This is product 1. Very good product. It is very easy to use." | |
}, | |
{ | |
"id": 2, |
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
export const MONTHS: Record<number, string> = { | |
0: 'January', | |
1: 'February', | |
2: 'March', | |
3: 'April', | |
4: 'May', | |
5: 'June', | |
6: 'July', | |
7: 'August', | |
8: 'September', |