Skip to content

Instantly share code, notes, and snippets.

@miguelmota
miguelmota / Cloudflare.ts
Created March 15, 2023 04:48
JavaScript Cloudflare API update IPFS dnslink subdomain
import fetch from 'isomorphic-fetch'
require('dotenv').config()
const CLOUDFLARE_ZONE_ID = process.env.CLOUDFLARE_ZONE_ID
const CLOUDFLARE_TOKEN = process.env.CLOUDFLARE_TOKEN
export class Cloudflare {
async getRecordId(dnslinkDomain: string) {
const url = `https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE_ID}/dns_records?name=${dnslinkDomain}`
const res = await fetch(url, {
@miguelmota
miguelmota / fallbackProvider.js
Last active February 2, 2023 10:59
JavaScript ethers fallback provider example
const { providers } = require('ethers')
async function main() {
const url1 = 'https://optimism-mainnet.infura.io/v3/84842078b09946638c03157f83405213'
const url2 = 'https://mainnet.optimism.io'
const stallTimeout = 2 * 1000
const options = {
timeout: 60 * 1000,
throttleLimit: 1
}
@cwhinfrey
cwhinfrey / bridge_hacks.md
Last active November 21, 2024 16:11
Bridge Hack List
@miguelmota
miguelmota / config
Created July 2, 2022 00:56
PostgreSQL SSH Tunnel Example
Host db_tunnel
HostName 1.2.3.4
User ubuntu
Port 22
RemoteCommand echo 'tunnel open' && cat
IdentityFile ~/.ssh/hop/id_rsa
IdentitiesOnly yes
Localforward 5432 localhost:5432
@miguelmota
miguelmota / instructions.sh
Last active June 17, 2022 03:51
github git push to gist pull from gist
# gist id = c55cc3f8aba345fc80262b3707a2e2b1
git clone git@gist.github.com:c55cc3f8aba345fc80262b3707a2e2b1.git
git add .
git commit -m "Initial commit"
git remote add origin git@gist.github.com:c55cc3f8aba345fc80262b3707a2e2b1.git
git push origin main # make sure it's "main" branch
@miguelmota
miguelmota / zksync_balances.js
Last active June 20, 2022 00:26
JavaScript zksync get eth and token balances
const zksync = require('zksync')
const { formatUnits } = require('ethers/lib/utils')
const addresses = [
'0x123....'
]
const decimals = {
USDC: 6,
USDT: 6
@miguelmota
miguelmota / KmsSigner.js
Last active January 11, 2023 15:26
JavaScript ethers Signer using AWS KMS
const { BigNumber, Signer } = require('ethers')
const { keccak256, recoverAddress, joinSignature, resolveProperties, serializeTransaction, hashMessage, arrayify, defineReadOnly } = require('ethers/lib/utils')
const { KMSClient, GetPublicKeyCommand, SignCommand } = require('@aws-sdk/client-kms')
const asn1 = require('asn1.js')
const EcdsaPubKey = asn1.define('EcdsaPubKey', function () {
this.seq().obj(
this.key('algo').seq().obj(
this.key('a').objid(),
this.key('b').objid()
@miguelmota
miguelmota / contenthash.js
Created January 11, 2022 21:18
JavaScript generate ENS contenthash (content) IPFS IPNS hash value
const bs58 = require('bs58')
const contentHash = require('content-hash')
const domain = 'app.uniswap.org'
const text = `ipns://${domain}`
const matched = text.match(/^(ipfs|ipns|bzz|onion|onion3):\/\/(.*)/) || text.match(/\/(ipfs)\/(.*)/) || text.match(/\/(ipns)\/(.*)/)
const contentType = matched[1]
const content = matched[2]
const bs58content = bs58.encode(
@miguelmota
miguelmota / proxy.ts
Created January 11, 2022 00:16
TypeScript Cloudflare worker proxy IPFS cloudflare-ipfs.com example
// SETINGS /////////////////////////////////////
const upstream = {
domain: 'cloudflare-ipfs.com',
protocol: 'https',
}
const dns = {
domain: 'cloudflare-dns.com',
protocol: 'https',
path: '/dns-query',
@miguelmota
miguelmota / replace_wm.sh
Last active December 10, 2021 04:30
XFCE replace window manager to bspwm
# change to bspwm
xfconf-query -c xfce4-session -p /sessions/Failsafe/Client0_Command -t string -sa bspwm
# revert to xfwm4
xfconf-query -c xfce4-session -p /sessions/Failsafe/Client0_Command -t string -sa xfwm4