Skip to content

Instantly share code, notes, and snippets.

@miguelmota
miguelmota / download_queries.js
Last active Nov 19, 2022
Node.js fetch Metabase download all dashboard queries
View download_queries.js
require('dotenv').config()
const fetch = require('node-fetch')
const path = require('path')
const fs = require('fs')
const token = process.env.METABASE_TOKEN
const outputDir = process.env.OUTPUT_DIR || './'
async function auth() {
const res = await fetch('https://metabase.example.com/api/session', {
@miguelmota
miguelmota / authenticate.sh
Created Nov 19, 2022
Metabase api queries examples
View authenticate.sh
curl -X POST \
-H "Content-Type: application/json" \
-d '{"username": "alice@example.com", "password": "mysecretpassword"}' \
https://metabase.example.com/api/session
# {"id":"123..."}
@miguelmota
miguelmota / server.js
Created Nov 15, 2022
Node.js express cors whitelist example
View server.js
const whitelist = ['http://localhost:3000']
const corsOptions = {
origin: function (origin, callback) {
if (whitelist.includes(origin)) {
callback(null, true)
} else {
console.log('origin:', origin, 'not allowed')
callback(new Error('Not allowed by CORS'))
}
}
@miguelmota
miguelmota / instructions.sh
Last active Nov 15, 2022
docker postgres psql connect dump restore example
View instructions.sh
#pg.env
#PGPASSWORD=pass
# connect
docker run -it --net host --env-file pg.env postgres psql -h localhost -U postgres
# dump
docker run --net host --env-file pg.env postgres pg_dump -h localhost -U postgres postgres > /tmp/dbdump.sql
# restore
@miguelmota
miguelmota / fallbackProvider.js
Last active Nov 8, 2022
JavaScript ethers fallback provider example
View fallbackProvider.js
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
}
@miguelmota
miguelmota / siege.sh
Created Oct 29, 2022
siege JSON post data example
View siege.sh
siege --content-type "application/json" 'https://example.com POST {"hello": "world"}'
@miguelmota
miguelmota / instructions.sh
Last active Oct 25, 2022
linux mitmproxy proxy example
View instructions.sh
# terminal 1
mitmweb
# terminal 2
google-chrome-stable --proxy-server="http://localhost:8080"
# import Authority certificate into chrome settings ~/.mitmproxy/mitmproxy-ca-cert.pem
# for firefox: setup proxy in Firefox Settings and import CA cert
@miguelmota
miguelmota / cert.sh
Last active Oct 21, 2022
mitmproxy cert location
View cert.sh
~/.mitmproxy/mitmproxy-ca-cert.pem
@miguelmota
miguelmota / instructions.sh
Last active Oct 21, 2022
linux wireshark SSLKEYLOGFILE ssl decrypt curl
View instructions.sh
sudo wireshark
# go to:
# Edit -> Preferences -> Protocols -> TLS (you can type) -> under "(Pre)-Master-Secret log filename
" enter in input "/tmp/ssl-key.log"
# then start capture
# curl
SSLKEYLOGFILE=/tmp/ssl-key.log curl https://example.com
# firefox (don't forget to disable http2 in about:config and restart)
@miguelmota
miguelmota / curl.sh
Created Oct 21, 2022
mitmproxy certs curl example
View curl.sh
curl --proxy 127.0.0.1:8080 --cacert ~/.mitmproxy/mitmproxy-ca-cert.pem https://example.com/