Skip to content

Instantly share code, notes, and snippets.

View mildronize's full-sized avatar

Thada Wangthammang mildronize

View GitHub Profile
@mildronize
mildronize / main.ts
Created March 16, 2024 03:54
Example of Express + Zod + Zod to OpenAPI + Swagger UI
import express from 'express';
import morgan from 'morgan';
import swaggerUi from 'swagger-ui-express';
import { extendZodWithOpenApi, OpenApiGeneratorV3, OpenAPIRegistry } from '@asteasolutions/zod-to-openapi';
import { z } from 'zod';
extendZodWithOpenApi(z);
const host = process.env.HOST ?? 'localhost';
const port = process.env.PORT ? Number(process.env.PORT) : 3000;
@mildronize
mildronize / Restart-AppServiceInstances.ps1
Created September 13, 2023 13:10
Restart-AppServiceInstances.ps1
Param(
[Parameter(Mandatory=$true)]
# ID for the Azure subscription containing the App Service
[string]$SubscriptionId,
[Parameter(Mandatory=$true)]
# Name of the App Service on which the restart should be performed
[string]$AppServiceName,
[Parameter(Mandatory=$false)]
# Seconds between each instance restart, defaults to 30
[int]$SecondsBetweenRestarts = 30
@mildronize
mildronize / my-own-react-hook-form.tsx
Last active June 27, 2023 01:03
My Own React Hook Form
// Inspired by react-hook-form
import { useRef } from 'react';
import { z } from 'zod';
interface UseFormOption<T> {
defaultValues: T;
schema: z.AnyZodObject;
}
@mildronize
mildronize / index.ts
Created March 23, 2023 00:41 — forked from cpojer/index.ts
When using `vite-node` with http servers, any HMR update will crash the process because the port is in use. This code can be inserted at the top-level of your script to gracefully stop the previous server instance before starting the new one.
#!/usr/bin/env node_modules/.bin/vite-node --watch
// `vite-node` HMR handler for servers.
type TeardownCallback = () => Promise<void>;
type Listener = () => TeardownCallback;
declare global {
// eslint-disable-next-line no-var
var __HMR__: {
listeners: ReadonlyArray<Listener>;
@mildronize
mildronize / Setup SSH keys.md
Last active November 20, 2021 08:43 — forked from my-wrm/README.md
Setup SSH keys for use with GitHub/GitLab/BitBucket etc

Create a new repository, or reuse an existing one.

Generate a new SSH key:

ssh-keygen -t rsa -C "your_email@example.com"

Copy the contents of the file ~/.ssh/id_rsa.pub to your SSH keys in your GitHub account settings (https://github.com/settings/keys).

Test SSH key:

@mildronize
mildronize / secure-client.js
Created October 26, 2021 08:37 — forked from ceejbot/secure-client.js
A node https server/client pair that uses client certs to authorize clients.
#!/usr/bin/env node
var fs = require('fs'),
https = require('https');
// We pass our client key & cert to the http agent,
// which we then use to make the request.
var agentOptions = {
key: fs.readFileSync('client.key'),
cert: fs.readFileSync('client.crt'),
/*
* Legit auto pop by Noxturnix
* Version 0.3
*
* How to use:
* 1. Go to https://popcat.click/
* 2. Press F12
* 3. Go to "Console" tab
* 4. Ignore the warning. There's no such malicious codes in this script. You can try to understand the code if you want
* 5. Copy and paste this script
@mildronize
mildronize / README.md
Last active June 13, 2021 08:28
My VS Code settings & Extensions

Common

  • [Vim]
    • Disable CTRL+C and CTRL+V
    "vim.handleKeys": {
          "<C-c>": false,
          "<C-v>": false
      }
    
@mildronize
mildronize / README.md
Last active November 18, 2020 01:48
Git cheat sheet

Deleting local branches

git branch -a
# *master
#  test
#  remote/origin/master
#  remote/origin/test

git branch -d test