Skip to content

Instantly share code, notes, and snippets.

View chewhx's full-sized avatar
👋

Chew Han Xiang chewhx

👋
View GitHub Profile
@chewhx
chewhx / cron-expressions.ts
Created June 28, 2023 07:20
Cron Expressions
export enum CronExpression {
EVERY_SECOND = '* * * * * *',
EVERY_5_SECONDS = '*/5 * * * * *',
EVERY_10_SECONDS = '*/10 * * * * *',
EVERY_30_SECONDS = '*/30 * * * * *',
EVERY_MINUTE = '*/1 * * * *',
EVERY_5_MINUTES = '0 */5 * * * *',
EVERY_10_MINUTES = '0 */10 * * * *',
EVERY_30_MINUTES = '0 */30 * * * *',
EVERY_HOUR = '0 0-23/1 * * *',
@chewhx
chewhx / downloadAudio.ts
Created April 5, 2023 00:14
Download stuff from urls
import axios from 'axios';
export async function downloadAudio(url: string): Promise<ArrayBuffer> {
const { data } = await axios.get(url, { responseType: 'arraybuffer' });
return data;
// To save, write Buffer.from(data).toString("binary") to disk with "binary" encoding
}
@chewhx
chewhx / QueryProvider.tsx
Last active April 4, 2023 11:52
react-tsx-providers
import React from 'react';
import { QueryClientProvider, QueryClient } from 'react-query';
import { ReactQueryDevtools } from 'react-query/devtools';
const client = new QueryClient();
const QueryProvider: React.FC<React.PropsWithChildren> = ({ children }) => {
return (
<QueryClientProvider client={client}>
{children}
@chewhx
chewhx / winston-dev-logger.js
Created March 12, 2023 09:45
Dev Logger Config for winston.js
export const levels = {
error: 0,
warn: 1,
info: 2,
http: 3,
debug: 4,
};
export const colors = {
error: 'red',
@chewhx
chewhx / tsconfig.json
Created December 31, 2022 08:29
Standard config for typescript projects
{
"compilerOptions": {
"target": "ES2016",
"module": "CommonJS",
"lib": ["dom", "ES2016"],
"rootDir": "src",
"outDir": "dist",
"strict": true,
"declarationMap": true,
"esModuleInterop": true,
@chewhx
chewhx / .prettierrc
Created December 31, 2022 08:28
Standard config for repos
{
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": true,
"singleQuote": true,
"semi": true,
"printWidth": 80,
"bracketSpacing": true,
"bracketSameLine": false
}
@chewhx
chewhx / usePostJsonPlaceholder.ts
Created October 29, 2022 00:53
Hook to mimic mutation request
export function usePostJsonPlaceholder(
opts?: Omit<
UseMutationOptions<
AxiosResponse<any, any>,
unknown,
{
data: string;
},
unknown
>,
@chewhx
chewhx / initConfig.ts
Last active April 3, 2023 13:22
Initialise configurestore
export async function initConfig(keys: string[]) {
for (const key of keys) {
const hasKey = configstore.has(key);
if (!hasKey) {
const answer = await prompt([
{
name: key,
message: `Enter value for "${key}" config: `,
type: 'input',
},
@chewhx
chewhx / cryptoZombies.md
Created July 29, 2022 08:21 — forked from oilsinwater/cryptoZombies.md
CryptoZombies Notes

CryptoZombies.io Notes

Contracts

Solidty's code is encapsulated in contracts. A contract is the fundamental building block of Ethereum applications -- i.e. all variables and functions belong to a contract, and are the starting point of your project. Below is an example of an empty contract called HelloWorld.

@chewhx
chewhx / _font-weights.scss
Last active June 14, 2022 14:41
Scss mapping for font-weight .fw- classes
$font-weights: (100, 200, 300, 400, 500, 600, 700, 800, 900);
@each $weight in $font-weights {
.fw-#{$weight} {
font-weight: $weight;
}
}