Skip to content

Instantly share code, notes, and snippets.

View sonthanhdan's full-sized avatar
🎯
Focusing

Son Thanh Dan sonthanhdan

🎯
Focusing
  • Ho Chi Minh City
  • 11:07 (UTC +07:00)
View GitHub Profile
import bootstrap from '@utils/bootstrap';
import { APIGatewayEvent, Context } from 'aws-lambda';
import { HttpException } from '@nestjs/common';
import { PromiseHandler } from '@fastify/aws-lambda';
let server: PromiseHandler;
const lambda = async (
module: any,
event: APIGatewayEvent,
/**
* Deletes keys from a Redis cluster, based on the provided keys array.
*
* @param {string[]} keys - Array of keys to be deleted from the Redis cluster
*/
private async deleteRedisClusterKeys(keys: string[]) {
const allKeys = await Promise.all(
keys.map(async (k) => {
const keys: RedisKey[] = await this.redis.keys(k);
return keys;
import { Cluster, ClusterNode, ClusterOptions } from 'ioredis';
export const redisClusterOptions = {
nodes: [
{
host: process.env.REDIS_HOST,
port: +process.env.REDIS_PORT,
},
] as ClusterNode[],
redisOptions: {
import { withAuth } from "next-auth/middleware";
export default withAuth(
function middleware(request) {
if (request.nextUrl.pathname !== "/") return;
return Response.redirect(new URL("/home", request.url));
},
// This is NextAuth.js
// Docs: https://next-auth.js.org/configuration/nextjs#pages
// Needs to be the same as your `authOptions.pages`
@sonthanhdan
sonthanhdan / apple-gen-secret.mjs
Created May 4, 2024 15:24 — forked from balazsorban44/apple-gen-secret.mjs
Script to generate Apple Client secret
#!/bin/node
import { SignJWT } from "jose"
import { createPrivateKey } from "crypto"
if (process.argv.includes("--help") || process.argv.includes("-h")) {
console.log(`
Creates a JWT from the components found at Apple.
By default, the JWT has a 6 months expiry date.
Read more: https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens#3262048
A webhook is an HTTP callback, that occurs when something happens, a resource changes its state, order gets created, product gets updated
Webhooks provide a way to build event driven apps because you can notify about changes
@sonthanhdan
sonthanhdan / api-throttling-429-error-handling.js
Created November 23, 2023 06:12 — forked from benogle/api-throttling-429-error-handling.js
An example script consuming an API with various throttling and 429 "too many requests" error handling strategies.
// An example script consuming an API with various throttling and 429 error
// handling strategies.
//
// Blog post with more context
// https://www.useanvil.com/blog/2021-03-29-throttling-and-consuming-apis-with-429-rate-limits
//
// License: MIT
import fetch from 'node-fetch'
import mapLimit from 'async/mapLimit'
@sonthanhdan
sonthanhdan / lifecycle-cheat-sheet.md
Created November 16, 2023 03:34 — forked from HyperBrain/lifecycle-cheat-sheet.md
Serverless Lifecycle Cheat Sheet

Serverless plugin author's cheat sheet

This cheat sheet provides a detailed overview of the exposed lifecycle events and available commands (and entrypoints) of the Serverless framework, that can be hooked by plugins (internal and external ones). The document is structured by the commands invoked by the user.

Lifecycle events are shown as the globally available outer events (all providers) and sub lifecycle events that are provider specific in the called order. Currently only the AWS provider is shown. If you have information about the other provider,

https://www.cs.usfca.edu/~galles/visualization/Algorithms.html
https://www.cs.usfca.edu/~galles/visualization/BTree.html
https://www.cs.usfca.edu/~galles/visualization/BPlusTree.html
SYNTAX
print ("Hello World")
# This is a comment
VARIABLE
carname = "Volvo"
x=5
y = 10
print(x+y)