Skip to content

Instantly share code, notes, and snippets.

{
"public_identifier": "lednhatkhanh",
"profile_pic_url": "https://s3.us-west-000.backblazeb2.com/proxycurl/person/lednhatkhanh/profile?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=0004d7f56a0400b0000000001%2F20240506%2Fus-west-000%2Fs3%2Faws4_request&X-Amz-Date=20240506T020208Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=e5d730e286c7451bbdf9c7921d60c28926509eb34a0ad6149efffe94937fc75e",
"background_cover_image_url": null,
"first_name": "Khanh",
"last_name": "Le Dinh Nhat",
"full_name": "Khanh Le Dinh Nhat",
"follower_count": null,
"occupation": "Senior Fullstack Developer at ONE Tech Stop",
"headline": "Senior Fullstack Developer at ONE Tech Stop",
@lednhatkhanh
lednhatkhanh / frontend-ws-connection.ts
Created April 23, 2021 04:32 — forked from jsdevtom/frontend-ws-connection.ts
kubernetes-ingress websockets with nodejs
export const ws = webSocket<WebsocketMessage>(`wss://${location.hostname}:${location.protocol === 'https:' ? 443 : 80}/ws/`);
export const wsObserver = ws
.pipe(
retryWhen(errors =>
errors.pipe(
delay(1000)
)
)
);
@lednhatkhanh
lednhatkhanh / event-loop.md
Created December 23, 2020 08:41 — forked from khanh-bes/event-loop.md
What is the JS Event Loop and Call Stack?

Regular Event Loop

This shows the execution order given JavaScript's Call Stack, Event Loop, and any asynchronous APIs provided in the JS execution environment (in this example; Web APIs in a Browser environment)


Given the code

@lednhatkhanh
lednhatkhanh / uniq-by.ts
Last active April 23, 2026 19:07
Lodash uniqBy in Typescript
export const uniqBy = <T>(arr: T[], key: keyof T): T[] => {
return Object.values(
arr.reduce(
(map, item) => ({
...map,
[`${item[key]}`]: item,
}),
{},
),
);
@lednhatkhanh
lednhatkhanh / typescript-react-utils.md
Created October 14, 2019 01:53
Some Typescript utilities for React

Typescript utils for React

Extract component's props

import React from "react";

type MyInputProps = {
  value: string;
 onChange: React.ChangeEventHandler;
@lednhatkhanh
lednhatkhanh / asyncLimit.ts
Created September 11, 2019 10:03
Async Limit function of @ycmjason implemented in typescript
export function asyncLimit<T extends (...args: any) => Promise<any>>(fn: T, n: number): T {
let pendingPromises = [] as Promise<ReturnType<T>>[];
return async function limitedFunction(this: ThisType<T>, ...args: Parameters<T>) {
while (pendingPromises.length >= n) {
await Promise.race(pendingPromises);
}
const p = fn.apply<ThisType<T>, Parameters<T>, Promise<ReturnType<T>>>(this, args);
function listToTree(list) {
const copiedList = [...list];
const mapObj = {};
const result = [];
for (let i = 0; i < copiedList.length; i += 1) {
mapObj[copiedList[i].uuid] = i;
copiedList[i].children = [];
}
@lednhatkhanh
lednhatkhanh / git-reset-author.sh
Created February 13, 2018 02:29 — forked from bgromov/git-reset-author.sh
Git: reset author for ALL commits
#!/bin/sh
# Credits: http://stackoverflow.com/a/750191
git filter-branch -f --env-filter "
GIT_AUTHOR_NAME='Newname'
GIT_AUTHOR_EMAIL='new@email'
GIT_COMMITTER_NAME='Newname'
GIT_COMMITTER_EMAIL='new@email'
" HEAD
@lednhatkhanh
lednhatkhanh / create_trigger.php
Created March 8, 2017 15:24
Create trigger with laravel migration
<?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddFeedbacksTableDeleteTrigger extends Migration
{
/**
* Run the migrations.
*
@lednhatkhanh
lednhatkhanh / site.properties
Created February 9, 2017 02:41
JPF (Java Pathfinder)
# JPF site configuration
jpf-core = ${user.home}/projects/jpf/jpf-core
extensions=${jpf-core}