Skip to content

Instantly share code, notes, and snippets.

View fzn0x's full-sized avatar
🌎
Makes international software.

fzn0x fzn0x

🌎
Makes international software.
View GitHub Profile
<html>
<head>
<title>Web3 Metamask Login</title>
<link
href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css"
rel="stylesheet"
/>
</head>
<body class="flex w-screen h-screen justify-center items-center">
@fzn0x
fzn0x / getSignatureMethods.js
Last active November 5, 2022 01:50
Get text signature from bytes signature, thanks https://www.4byte.directory/signatures for the free service!
import fetch from "node-fetch";
export default async function getSignatureMethods(hash) {
if (!hash) {
throw new Error("signature hash is required");
}
if (!Buffer.isBuffer(hash)) {
hash = hash.replace(/^0x/, "");
hash = Buffer.from(hash, "hex");
@fzn0x
fzn0x / objectDiff.js
Created October 10, 2022 17:44
JS Object Diff
const diff = Object.keys(expectedObject).filter((expectedKey) => {
return !Object.keys(currentObject).includes(expectedKey);
});
console.log(diff.length); // Different in length
console.log(diff); // Missing keys in currentObject
@fzn0x
fzn0x / signature.html
Last active June 29, 2022 13:25
Receive metamask signature by sign in to wallet and sign message.
<html>
<head>
<title>Web3 Metamask Login</title>
<link
href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css"
rel="stylesheet"
/>
</head>
<body class="flex w-screen h-screen justify-center items-center">
@fzn0x
fzn0x / copyable.js
Last active June 17, 2022 07:54
Merge your schemas like a boss in GraphQL - How to merge schema in GraphQL with Nodejs
// schema.js
const path = require("path");
const fs = require("fs");
const { makeExecutableSchema } = require("@graphql-tools/schema");
const { stitchSchemas } = require("@graphql-tools/stitch");
const subschemas = [];
const schemaDir = path.resolve(__dirname, "./schema");
@fzn0x
fzn0x / getTimestamp.js
Created June 15, 2022 17:48
Format dates with pattern matching in Javascript
const monthNames = [
"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December"
];
const timeZone = n => ({
true: "Asia/Jakarta",
[ n === "WIB" ]: "Asia/Jakarta",
@fzn0x
fzn0x / example.js
Created June 13, 2022 06:36
Axie composition and valuation sample script
const { AbortController } = require("node-abort-controller");
const HttpsProxyAgent = require("https-proxy-agent");
const { ua, randomElement } = require("../config/userAgent.js");
async function runRequestAxieBriefList(options, type = "") {
const timeout = 60000;
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout);
@fzn0x
fzn0x / mongodb_group.js
Created May 20, 2022 09:09
Group data by dates in mongodb without extract all the values.
import mongoose from "mongoose";
import dotenv from "dotenv";
dotenv.config();
mongoose
.connect(process.env.MONGO_SOURCE)
.then(async () => {
console.log("connected");
@fzn0x
fzn0x / dummy.json
Created May 3, 2022 05:06
dummy json
{
"dummy": true
}

Do not use forEach with async-await

TLDR: Use for...of instead of forEach in asynchronous code.

The problem

Array.prototype.forEach is not designed for asynchronous code. (It was not suitable for promises, and it is not suitable for async-await.)

For example, the following forEach loop might not do what it appears to do: