This file contains hidden or 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
| // -adj-node -visited | |
| function bfs(node){ | |
| let queue = [node] | |
| while(queue.length > 0){ | |
| const v = queue.shift() | |
| console.log(v.data) | |
| if(v.children){ | |
| queue.push(...v.children) | |
| } | |
| } |
This file contains hidden or 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 pagination = {} | |
| pagination.process = (page, limit = 10, q = '') => { | |
| try { | |
| page = +page | |
| limit = +limit | |
| // pagination boolean | |
| const paginating = (page && (page === 0 || page > 0)) || false | |
| // get skips | |
| const skips = page <= 1 ? 0 : (page - 1) * limit |
This file contains hidden or 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 asyncVerify = nodeUtil.promisify(jwt.verify) | |
| const JWT_SECRET = 'jwt.secret' | |
| const f = {} | |
| f.signToken = (id) => { | |
| // 24 hours | |
| let tokenExpiry = 60 * 60 * 24 | |
| return jwt.sign( | |
| { |
This file contains hidden or 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 { NextApiHandler, NextApiRequest, NextApiResponse } from "next" | |
| // checkout NextJS 'NextApiResponse' generic, | |
| // TL;DR | |
| // calling response.send & response.json can be type, NextApiResponse<your_interface_or_type> | |
| interface API_Response { | |
| ok: boolean, | |
| status?: number, | |
| data?: any | |
| } |
This file contains hidden or 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 Tweetur = require('tweetur') // | |
| //initialize the Tweetur app... | |
| const app = new Tweetur({ | |
| consumer_key : "api_key", // required ** | |
| consumer_secret: "api_secret", // required ** | |
| access_token: "access_token", // required ** | |
| access_token_secret: "access_token_secret", // required ** | |
| api_version: "1.1" // if you want to use Twitter v2, change the value to '2' | |
| }) |