Skip to content

Instantly share code, notes, and snippets.

View tridungle's full-sized avatar

Trí Dũng Lê tridungle

  • Independent
  • Ho Chi Minh
View GitHub Profile
@tridungle
tridungle / jwt.js
Created October 3, 2023 11:18 — forked from robingustafsson/jwt.js
Simple JWT example for k6 load testing tool
import crypto from "k6/crypto";
import encoding from "k6/encoding";
const algToHash = {
HS256: "sha256",
HS384: "sha384",
HS512: "sha512"
};
function sign(data, hashAlg, secret) {
@tridungle
tridungle / jwt-module.js
Created April 21, 2023 10:55 — forked from SiddharthaChowdhury/jwt-module.js
Implementation of JWT using private and public keys
const fs = require('fs');
const jwt = require('jsonwebtoken');
// http://travistidwell.com/blog/2013/09/06/an-online-rsa-public-and-private-key-generator/
// use 'utf8' to get string instead of byte array (1024 bit key)
var privateKEY = fs.readFileSync('./private.key', 'utf8'); // to sign JWT
var publicKEY = fs.readFileSync('./public.key', 'utf8'); // to verify JWT
module.exports = {
sign: (payload, $Options) => {
/*
@tridungle
tridungle / gist:df4c1496d2bd8806555bbd16614034d4
Created April 21, 2023 10:49 — forked from aneudysamparo/gist:30d0c4d7f82cd089753dcda56de040b0
NestJs authentication using JWT and private and public key
Since it's been days, I am guessing this was solved. I am just adding my two cents here for future readers.
The problem lies with the JwtModule and the JwtStrategy instantiation. They aren't configured properly.
You need to pass in the algorithms you'd use for signing and verifying the tokens, along with the keys.
To verify whether the tokens are actually getting generated with the RS256 algo, check the header in the token at https://jwt.io/.
It would probably show HS256, and since your code didn't use the correct algorithm to sign the token.
And it fails while token gets verified using the public key.
To generate signed tokens properly with the RSA key pair:
@tridungle
tridungle / index.js
Created December 15, 2022 10:17 — forked from dyaa/index.js
Parse Separate Live Query Server Setup
// This is the index.js file for my Parse Live Query Server, running on a separate EC2 instance
var express = require('express');
var cors = require('cors')
var ParseServer = require('parse-server').ParseServer;
var app = express();
app.use(cors());
// We include the lines below so that we can hit `/` and it passes the Elastic Beanstalk Health Check
@tridungle
tridungle / importing.module.ts
Created November 26, 2022 19:31 — forked from evolkmann/importing.module.ts
Create Nest.js modules with custom config
import { Module } from '@nestjs/common';
import { MyLibModule } from './my-lib.module';
@Module({
imports: [
MyLibModule.register({ name: 'Enzo' }),
]
})
export class ImportingModule {}
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
// @ts-nocheck //TODO: enable remove once there are typings in place
// TODO: uncomment all three eslint() occurrences once eslint warnings and errors are fixed
// for info on emitCSS etc. https://github.com/rollup/rollup-plugin-svelte#extracting-css and https://svelte.dev/docs#svelte_preprocess
// import { eslint } from 'rollup-plugin-eslint'
import { terser } from 'rollup-plugin-terser'
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
import config from 'sapper/config/rollup.js'
import environmentVariables from './config/env'
@tridungle
tridungle / docker-run-redis.md
Created May 27, 2022 08:31 — forked from sskoopa/docker-run-redis.md
Start redis in Docker with a open port at localhost:6379

docker run --name recorder-redis -p 6379:6379 -d redis:alpine

@tridungle
tridungle / iterm2-solarized.md
Created May 21, 2022 17:31 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

@tridungle
tridungle / README.md
Created November 18, 2021 04:39 — forked from philnash/README.md
Send an SMS with Twilio in Node.js

Send an SMS with Twilio in Node.js

This is an example of how to send an SMS. To run this script you should:

  1. Download the index.js and package.json files
  2. Install the dependencies with npm install
  3. Get your Twilio Account SID and Auth Token from your Twilio console (sign up for a free account if you don't already have one)
  4. Get a Twilio number that can send SMS
  5. Set the credentials and other variables in the environment and run the script: