Skip to content

Instantly share code, notes, and snippets.

View ngoctp's full-sized avatar

Ngoc P. Tran ngoctp

View GitHub Profile
@coderberry
coderberry / chrome-cheat-sheet.md
Last active March 10, 2023 13:56
Chrome Canary Console Cheat Sheet
@zcaceres
zcaceres / Include-in-Sequelize.md
Last active July 13, 2024 13:46
using Include in sequelize

'Include' in Sequelize: The One Confusing Query That You Should Memorize

When querying your database in Sequelize, you'll often want data associated with a particular model which isn't in the model's table directly. This data is usually typically associated through join tables (e.g. a 'hasMany' or 'belongsToMany' association), or a foreign key (e.g. a 'hasOne' or 'belongsTo' association).

When you query, you'll receive just the rows you've looked for. With eager loading, you'll also get any associated data. For some reason, I can never remember the proper way to do eager loading when writing my Sequelize queries. I've seen others struggle with the same thing.

Eager loading is confusing because the 'include' that is uses has unfamiliar fields is set in an array rather than just an object.

So let's go through the one query that's worth memorizing to handle your eager loading.

The Basic Query

@furkan3ayraktar
furkan3ayraktar / CloudFrontMetadataInject.js
Last active October 5, 2023 16:38
Complete Lambda@Edge function to inject metadata.
const path = require('path');
const https = require('https');
const zlib = require('zlib');
const downloadContent = (url, callback) => {
https.get(url, (res) => {
let response;
let body = '';
if (res.headers['content-encoding'] === 'gzip') {
@Firsh
Firsh / lwp-cloudflare-dyndns.sh
Last active July 2, 2024 02:55
Cloudflare as Dynamic DNS
#!/bin/bash
# Cloudflare as Dynamic DNS
# From: https://letswp.io/cloudflare-as-dynamic-dns-raspberry-pi/
# Based on: https://gist.github.com/benkulbertis/fff10759c2391b6618dd/
# Original non-RPi article: https://phillymesh.net/2016/02/23/setting-up-dynamic-dns-for-your-registered-domain-through-cloudflare/
# Update these with real values
auth_email="email@example.com"
auth_key="global_api_key_goes_here"
zone_name="example.com"
@jonilsonds9
jonilsonds9 / file-buffer-nestjs.ts
Last active October 17, 2023 23:11
Uploading binary file (buffer) using NestJS
// Had to upload a binary file but multer only works with `multipart/form-data`
// And NestJS parses the request. So I had to manually upload it.
// First in `main.ts` I had to edit the following line:
const app = await NestFactory.create(AppModule);
// For:
const app = await NestFactory.create(AppModule, { bodyParser: false });