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
  • 20:22 (UTC +07:00)
View GitHub Profile
@sonthanhdan
sonthanhdan / free-database-hosting.md
Created November 15, 2024 05:28 — forked from bmaupin/free-database-hosting.md
Free database hosting
@sonthanhdan
sonthanhdan / canvasDownload.js
Created September 19, 2024 10:34 — forked from Kaundur/canvasDownload.js
JS to automatically download canvas as a png
// This code will automatically save the current canvas as a .png file.
// Its useful as it can be placed in a loop to grab multiple canvas frames, I use it to create thumbnail gifs for my blog
// Only seems to work with Chrome
// Get the canvas
var canvas = document.getElementById("canvas");
// Convert the canvas to data
var image = canvas.toDataURL();
// Create a link
var aDownloadLink = document.createElement('a');
@sonthanhdan
sonthanhdan / GoogleSheetJson.md
Created August 21, 2024 06:04 — forked from ronaldsmartin/GoogleSheetJson.md
Google Spreadsheet JSON Queries

SheetAsJSON + Filtering

This is an extension of DJ Adams' excellent SheetAsJSON Google Apps Script, which provides a way to GET a published Google Spreadsheet as a JSON feed. This version allows generic filtering for terms, more specific control over which rows to parse, and correct MIME type for JSONP output.

Minimal Usage

The following parameters are required for the script to work.

https://script.google.com/macros/s/AKfycbzGvKKUIaqsMuCj7-A2YRhR-f7GZjl4kSxSN1YyLkS01_CfiyE/exec?
+ id=<spreadsheet key>
+ sheet=<sheet name on spreadsheet>
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
@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,

SYNTAX
print ("Hello World")
# This is a comment
VARIABLE
carname = "Volvo"
x=5
y = 10
print(x+y)
@sonthanhdan
sonthanhdan / index.js
Created September 21, 2023 06:22 — forked from caesaneer/index.js
Part 2 - Worker Threads - Index.js
// ════════════════════════════════════════════════════════════════════════════════════════════════║
const http = require('http')
const { StaticPool } = require('node-worker-threads-pool')
const numCPUs = require('os').cpus().length
// ════════════════════════════════════════════════════════════════════════════════════════════════║
const host = '192.168.0.14'
const port = 8080
@sonthanhdan
sonthanhdan / nx-structure-angular-nestjs.md
Created September 21, 2023 06:21 — forked from trungvose/nx-structure-angular-nestjs.md
Nx workspace structure for NestJS and Angular

Nx

https://nx.dev/

Nx is a suite of powerful, extensible dev tools to help you architect, test, and build at any scale β€” integrating seamlessly with modern technologies and libraries while providing a robust CLI, caching, dependency management, and more.

It has first-class support for many frontend and backend technologies, so its documentation comes in multiple flavours.

Principles