Skip to content

Instantly share code, notes, and snippets.

@miguelmota
miguelmota / README.md
Last active February 15, 2024 00:04
Fork Me on GitHub Button PNG
View README.md

forkmebutton

PNG

https://gist.github.com/assets/168240/25dd56cb-861f-4442-a6fb-b79e8c4afae4
@miguelmota
miguelmota / instructions.txt
Created December 5, 2023 23:11
git difftool meld
View instructions.txt
git config --global diff.tool meld
git config --global difftool.prompt false
git difftool --diff-filter=M master..devel
@miguelmota
miguelmota / nginx.conf
Created October 15, 2023 17:51
Nginx deny .git folder access
View nginx.conf
location ~ /\.git.* {
deny all;
}
@miguelmota
miguelmota / getEtherscanLogs.ts
Created September 10, 2023 07:03
JavaScript get etherscan logs by topic for contract address
View getEtherscanLogs.ts
async function getEtherscanLogs (chain: string, fromBlock: number, toBlock: number, address: string, topic0: string, topic1?: string) {
const baseUrl = 'https://api-goerli.etherscan.io'
let url = `${baseUrl}/api?module=logs&action=getLogs&address=${address}&fromBlock=${fromBlock}&toBlock=${toBlock}&topic0=${topic0}&page=1&offset=0&apikey=YourApiKeyToken`
if (topic1) {
url += `&topic0_1_opr=and&topic1=${topic1}`
}
const res = await fetch(url)
const json = await res.json()
const logs = json.result
return logs
@miguelmota
miguelmota / getEtherscanTxs.ts
Created September 10, 2023 07:02
JavaScript get etherscan api transactions for account address
View getEtherscanTxs.ts
async function getEtherscanTxs(chain: string, accountAddress: string) {
const baseUrl = 'https://api-goerli.etherscan.io'
const url = `${baseUrl}/api?module=account&action=txlist&address=${accountAddress}&startblock=0&endblock=99999999&sort=asc&apikey=YourApiKeyToken`
const res = await fetch(url)
const json = await res.json()
const txs = json.result
const txHashes = txs.map((tx: any) => tx.hash)
return txHashes
}
@miguelmota
miguelmota / batchFetch.ts
Created September 10, 2023 07:01
ethers filters events logs with batching
View batchFetch.ts
async function batchFetch (contract: Contract, filter: any, startBlockNumber: number, endBlockNumber: number, batchSize = 10000) {
const logs: any[] = []
let start = startBlockNumber
let end = Math.min(start + batchSize, endBlockNumber)
while (end <= endBlockNumber) {
const _logs = await contract.queryFilter(
filter,
start,
end
)
@miguelmota
miguelmota / instructions.sh
Created September 8, 2023 07:48
Arch linux command line csv viewer
View instructions.sh
pacman -S csview
@miguelmota
miguelmota / urls.txt
Created September 2, 2023 03:42
Optimism public RPC urls
View urls.txt
'https://rpc.ankr.com/optimism',
'https://optimism.blockpi.network/v1/rpc/public',
'https://opt-mainnet.g.alchemy.com/v2/demo',
'https://optimism-mainnet.public.blastapi.io',
'https://api.zan.top/node/v1/opt/mainnet/public',
'https://optimism.publicnode.com',
'https://optimism.meowrpc.com',
'https://mainnet.optimism.io',
'https://rpc.optimism.gateway.fm',
'https://gateway.tenderly.co/public/optimism',
@miguelmota
miguelmota / removeOutliersByZScore.ts
Created September 2, 2023 03:18
JavaScript remove outliers by z score
View removeOutliersByZScore.ts
function removeOutliersByZScore(data: number[], threshold = 2) {
const mean = data.reduce((acc, val) => acc + val, 0) / data.length
const stdDev = Math.sqrt(data.reduce((acc, val) => acc + Math.pow(val - mean, 2), 0) / data.length)
return data.filter((val) => Math.abs((val - mean) / stdDev) < threshold)
}
@miguelmota
miguelmota / is_symlink.sh
Created August 1, 2023 17:00
Linux bash check if file or directory is symlink
View is_symlink.sh