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
  • 01:38 (UTC +07:00)
View GitHub Profile
/**
* Get XML sitemap URLs and metadata.
*
* @param {"https://example.com/sitemap.xml"} url - Input the XML sitemap URL.
* @param {"keyword"} filter [Optional] - keyword to filter URLs.
* @customfunction
*/
function sitemap(url, filter) {
// Validate if the URL is provided.
if (!url) return 'You need to enter the URL';
@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 'reflect-metadata';
import { container } from 'tsyringe';
import serverlessExpress from '@vendia/serverless-express';
import { Logger } from '@aws-lambda-powertools/logger';
import { Tracer } from '@aws-lambda-powertools/tracer';
import { capturePromise } from 'aws-xray-sdk-core';
import env from '@/configs';
import { DbBootstrapper } from '@/database/db-bootstrapper';
import { container } from 'tsyringe';
import { CacheService } from '@/services/cache.service';
const cacheSvc = container.resolve(CacheService);
export function CacheResponse(expiration: number = 3600, serializeKey?: unknown): MethodDecorator {
return function (target, propertyKey: string, descriptor: PropertyDescriptor) {
const classTarget = target.constructor.name;
const oriFunc = descriptor.value;
async function getBreadcrumb(
id: number,
results: Partial<Breadcrumb>[] = [],
maxLevel: number = 4,
): Promise<Partial<Breadcrumb>[]> {
if (!id) return results;
const row = await this.getRecord(id);
if (!row) return results;
import Redis from 'ioredis';
import { inject, injectable } from 'tsyringe';
import { Logger } from '@aws-lambda-powertools/logger';
import env from '@/configs/be-config';
@injectable()
export class CacheService {
private redis: Redis | undefined;
import { Command } from 'commander';
import { readdir, rmdir } from 'fs/promises';
import fs from 'node:fs';
import concurrently from 'concurrently';
import path from 'path';
const getDirectories = async (source) =>
(await readdir(source, { withFileTypes: true }))
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);
import 'dotenv/config';
import { NestFactory } from '@nestjs/core';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { PromiseHandler, awsLambdaFastify } from '@fastify/aws-lambda';
import { Logger } from '@nestjs/common';
import compression from '@fastify/compress';