Skip to content

Instantly share code, notes, and snippets.

View tqmvt's full-sized avatar

Taylor Lee tqmvt

View GitHub Profile
@tqmvt
tqmvt / fizzbuzz.go
Created September 18, 2023 09:54
FizzBuzz with Unit Test written using GoLang
package fizzbuzz
import "strconv"
func Fizzbuzz(n int) string {
var name string = ""
if n%3 == 0 {
name = "Fizz"
@tqmvt
tqmvt / generic.org
Created September 15, 2023 18:37
Some generic writeup about common gas optimizations, etc.

Upgrade to at least 0.8.4

Using newer compiler versions and the optimizer gives gas optimizations and additional safety checks for free!

The advantages of versions 0.8.* over <0.8.0 are:

  • Safemath by default from 0.8.0 (can be more gas efficient than some library based safemath).
  • Low level inliner from 0.8.2, leads to cheaper runtime gas. Especially relevant when the contract has small functions. For
@tqmvt
tqmvt / liquidityPoolERC20.sol
Created August 25, 2023 00:50
Building a Liquidity Pool Smart Contract for Token Swapping
// SPDX-License-Identifier:OPEN
pragma solidity ^0.8.18;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol";
library SafeMath {
function add(uint256 x, uint256 y) internal pure returns (uint256 z) {
@tqmvt
tqmvt / upstash-redis-with-vercel-edge.ts
Last active April 23, 2023 13:10
rate limit - upstash redis with vercel edge / nextjs
import { NextRequest, NextResponse } from "next/server";
import { Redis } from "@upstash/redis";
export const config = {
runtime: "edge",
};
if (
!process.env.UPSTASH_REDIS_REST_URL ||
!process.env.UPSTASH_REDIS_REST_TOKEN
) {
@tqmvt
tqmvt / mergesort.js
Created September 27, 2022 15:24
Merge Sort Algorithm
// merge the two arrays: left and right
function merge(left, right) {
let resultArray = [],
leftIndex = 0,
rightIndex = 0;
// concatenate values into the resultArray in order
while (leftIndex < left.length && rightIndex < right.length) {
if (left[leftIndex] < right[rightIndex]) {
resultArray.push(left[leftIndex]);
@tqmvt
tqmvt / multicall.md
Created November 16, 2021 03:10
How to speed up your DeFi Queries?