Skip to content

Instantly share code, notes, and snippets.

@ivawzh
ivawzh / [...ts-rest].tsx
Created March 17, 2024 04:13
TS-Rest + NextJS
// pages/api/[...ts-rest].tsx
import { createNextRoute as fulfilContract, createNextRouter } from '@ts-rest/next';
import { initContract } from '@ts-rest/core';
import { z } from 'zod';
export interface Post {
id: string;
title: string;
description: string | null;
content: string | null;
@ivawzh
ivawzh / README.md
Last active August 4, 2023 01:05
WSS uninstall

Uninstall WSS

Run:

./SymantecRemovalTool.command
@ivawzh
ivawzh / README.md
Last active July 20, 2023 05:41
vscode cheat sheet

Ivan Wang's VSCode cheat sheet

Basic

Extensions

  1. Atom Keymap for typical Electron app short cuts.

Settings

@ivawzh
ivawzh / readme.md
Created March 16, 2023 23:34
refeed from dead letter queue

You can use the following bash script to refeed AWS events from a dead letter queue (DLQ) to an SQS queue in batches of 5 events with a 1-minute wait between batches. Replace DLQ_URL and TARGET_SQS_URL with the appropriate URLs for your dead letter and target queues.

#!/bin/bash

DLQ_URL="https://sqs.region.amazonaws.com/your-account-id/dead-letter-queue-name"
TARGET_SQS_URL="https://sqs.region.amazonaws.com/your-account-id/target-queue-name"
BATCH_SIZE=5
WAIT_TIME=60
@ivawzh
ivawzh / strip-indents-tag.ts
Created September 13, 2020 14:35
TypeScript utils
//@ts-nocheck
// copied from https://github.com/zspecza/common-tags/blob/master/src/stripIndents/stripIndents.js
const tagTransformersSymbol = 'COMMON_TAGS_TAG_TRANSFORMERS_SYMBOL';
function isTag(fn) {
return typeof fn === 'function' && fn[tagTransformersSymbol];
}
@ivawzh
ivawzh / History\2d77d413\KEAY.json
Last active April 18, 2023 02:44
VsCode Settings Sync
{
"debug.toolBarLocation": "docked",
"markdown.extension.orderedList.marker": "one",
"terminal.integrated.enableBell": false,
"editor.multiCursorModifier": "ctrlCmd",
"workbench.iconTheme": "material-icon-theme",
"atomKeymap.promptV3Features": true,
"files.autoSave": "onFocusChange",
"editor.tabSize": 2,
"files.eol": "\n",
@ivawzh
ivawzh / json-parser.ts
Last active February 26, 2024 07:09
Typescript crazy mapped types
// This is only working in 4.1.0-insiders20200903
type ParserError<T extends string> = { error: true } & T
type EatWhitespace<State extends string> =
string extends State
? ParserError<"EatWhitespace got generic string type">
: State extends ` ${infer State}` | `\n${infer State}`
? EatWhitespace<State>
: State
type AddKeyValue<Memo extends Record<string, any>, Key extends string, Value extends any> =
@ivawzh
ivawzh / instance-method-stub.ts
Last active July 13, 2020 06:54
Typescript stub/mock with type check
// at b.ts
export class B {
public iAm() {
return 'B'
}
}
// at a.ts
import { B } from './b'
@ivawzh
ivawzh / Dockerfile
Last active July 11, 2020 02:39
docker-compose-wait-for-it
From whatever
# Install wait-for-it.sh docker-compose to wait on dependent containers e.g. database
RUN apk --no-cache --virtual .build-deps add curl && \
curl https://raw.githubusercontent.com/raphaelahrens/wait-for-it/master/wait-for-it.sh > /usr/local/bin/wait-for-it.sh && \
chmod +x /usr/local/bin/wait-for-it.sh && \
apk del .build-deps
ENTRYPOINT ["/usr/local/bin/shush", "exec", "--"]
type TransformObjValueType<OBJ extends {[k: string]: string}, NEW_TYPE> =
{[K in keyof OBJ]: NEW_TYPE}
// Usage:
type Secrets = {[k: string]: string}
type ContainerSecrets = TransformObjValueType<Secrets, EcsSecret>