Skip to content

Instantly share code, notes, and snippets.

View WEEFAA's full-sized avatar
🐵
Feeding machines

Ray Quijada WEEFAA

🐵
Feeding machines
View GitHub Profile
@WEEFAA
WEEFAA / bfs.js
Created November 16, 2022 14:31
a.bfs
// -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)
}
}
@WEEFAA
WEEFAA / pagination.js
Created March 11, 2022 08:51
[Util] Pagination
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
@WEEFAA
WEEFAA / jwt.js
Last active March 11, 2022 08:55
[JWT] decode/sign
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(
{
@WEEFAA
WEEFAA / next.controller.ts
Last active July 27, 2022 06:03
[NextJS] custom controller class
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
}
@WEEFAA
WEEFAA / tweetur_getting_started.js
Last active March 11, 2022 08:56
[Tweetur] Getting started with Tweetur: 2 Legged OAuth Flow or "Client Credentials Flow"
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'
})