Skip to content

Instantly share code, notes, and snippets.

@Jaysok
Jaysok / Lamport-Signature.md
Last active May 18, 2023 22:41
Lamport-Signature

Lamport Signature javascript implementation

I have implemented a basic Lamport Signature, following the instructions provided in this video.

vscode add all missing imports shortcut

There is no shortcut for "add all missing imports" by default. So we need add it manually.

See this link from vscode official.

You can simulate the action using right clicking the source code and trigger the action. As you can see, it is an action from what they call "Source Action".

As introduced in the link, we can add the action as a shortcut. The article is using the key binding as ctrl+shift+i but I used shift+cmd+i instead since I'm using Mac in which the add missing import shortcut for a single expression is cmd+i.

@Jaysok
Jaysok / zod-transform.md
Last active October 24, 2022 04:57
zod transform

zod transform

If we want to input timezone as a number but want to parse as a string, in this case, we can use .transform.

const timezone = z.number().min(-11).max(14).transform((val) => {
  return val < 0 ? `${val}` : `+${val}`;
});
const parsed = timezone.parse(10);
console.log(`parsed: ${parsed}, typeof: ${typeof parsed}`); // parsed: +10, typeof: string

.gitignore

Toptal .gitignore API

With the help of gitignore.io, we can do this:

# node.js
curl -sL https://www.toptal.com/developers/gitignore/api/node >> .gitignore

Node.js sign-up and sign-in(log-in) simplified

I wrote some simplified code for sign-up and sign-in. You can see whole source code at the bottom of this gist.

Sign-up

Assuming an id-password based login, the general flow of sign-up would look like this:

  1. Check that the user information is in the database with the user ID. Return if already exists.
  2. Create salt with randomBytes function.

GKE PV migration to another project

This gits is just for sharing my experience so it might not be the best fit for you. But I hope this might help someone facing similar problems in the future.

Background

Our team had to shutdown one of the clusters in GKE but there were some development dependencies to our nexus repository which is exposed as URI. So the team decided to migrate entire nexus repository from one GCP project to another and simply change the ip address of the DNS.

While it was easy to migrate the nexus because it was simply deployed as a pod, but it seemed quite difficult the persistent volume it depends upon.

@Jaysok
Jaysok / zod-example.ts
Last active June 23, 2022 02:45
zod example
// Used Deno
//
// If you're using Node.js, you should import it from node_modules
// And note that you must enable strict mode in your tsconfig.json
// see https://github.com/colinhacks/zod#requirements
import { z } from "https://deno.land/x/zod@v3.17.3/mod.ts";
const userSchema = z.object({
id: z.string(),
name: z.string(),