Skip to content

Instantly share code, notes, and snippets.

@paulwongx
paulwongx / ECDSARecover.sol
Last active August 16, 2022 22:19
Ethers.js
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
contract ECDSARecover {
using ECDSA for bytes32;
using ECDSA for bytes;
@paulwongx
paulwongx / devops_prereq.md
Last active October 18, 2022 02:28
devops
import crypto from "crypto";
import fs from "fs";
// Creates a sha256 hash from a file
export const createHashFromFile = (filePath: string) => new Promise(resolve => {
const hash = crypto.createHash('sha256');
fs.createReadStream(filePath).on('data', data => hash.update(data)).on('end', () => resolve(hash.digest('hex')));
});

Javascript Cheatsheet

  1. This document focuses on more nuanced topics. It is not comprehensive.
  2. Examples are taken from MDN mostly

Strings

// [@@iterator]() - iterating a string
const str = 'A\uD835\uDC68';
const strIter = str[Symbol.iterator]();

VSCode Shortcuts

Windows Shortcut MacOS Function
Alt + Up/Down Arrow Opt + Up/Down Arrow Moves line of code up or down
Alt + Shift + Up/Down Arrow Opt + Shift + Up/Down Arrow Duplicates line of code
Ctrl + P Cmd + P Search and open a file quickly
Ctrl + Shift + P Cmd + Shift + P Open up the command prompt
Alt + Shift + F Shift + Opt + F Format document
Ctrl + Shift + F Shift + Cmd + F Search for file
Ctrl + Shift + E Shift + Cmd + E Open up file explorer
@paulwongx
paulwongx / prisma.ts
Last active September 24, 2022 21:07
Example prisma schema
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()
// const prisma = new PrismaClient({ log: ["query"]})
// npx prisma generate
// to generate the types, if not, close and re-open file. If not, ctrl+click create to reload typescript
// npx prisma migrate dev --name test2
async function main() {
@paulwongx
paulwongx / sorting_algos.md
Last active October 18, 2022 17:30
Data structures and algorithms

Sorting Algorithms

Reference \

Algorithm Time and Space Complexity

Straight Insertion

Description - From left to right, sort the numbers in groups starting from 1 to the length of the array
Time complexity - O(n^2)
Space complexity - O(1)

@paulwongx
paulwongx / download_youtube_mp3.ts
Last active January 6, 2023 22:39
Download Youtube mp3
import ytdl from "ytdl-core";
import fs from "fs";
import ffmpeg from "fluent-ffmpeg";
import readline from "readline";
// https://github.com/fent/node-ytdl-core/blob/master/example/convert_to_mp3.js
const id = 'nMfPqeZjc2c';
let stream = ytdl(id, {
@paulwongx
paulwongx / theme-provider.tsx
Created February 26, 2023 18:57
React Theme Provider
"use client"
import React, { useState, SetStateAction, Dispatch } from "react";
import { Color, colors } from "@/types"
import { useIsomorphicLayoutEffect } from "usehooks-ts";
interface ThemeContextProps {
theme: Color;
setTheme: Dispatch<SetStateAction<Color>> | null;
}
@paulwongx
paulwongx / Useful CLI Commands
Created February 28, 2023 01:55
CLI Commands
# Creating a next app from example template
# All examples: https://github.com/vercel/next.js/tree/canary/examples
yarn create next-app -e app-dir-mdx .