Skip to content

Instantly share code, notes, and snippets.

@nandilugio
Created January 6, 2023 09:45
Show Gist options
  • Save nandilugio/2b964f9e6be9b3eb7a1dbed6545c99d3 to your computer and use it in GitHub Desktop.
Save nandilugio/2b964f9e6be9b3eb7a1dbed6545c99d3 to your computer and use it in GitHub Desktop.
Random notes from BU

SQL

Histogram queries

select
  (age/10)*10 as from_age, -- Bucket unique
  ((age/10)*10)+10 as to_age,
  count(*),
  repeat('=', (count(*) * 30 / max(count(*)) over ())::int) as bar
from users
group by 1
order by 1;

########################################################################################################################

Psql

Psql local copying

psql ... -Xf ~/q.sql --csv > /tmp/TODO.csv
\copy (
) to '/tmp/TODO.csv' csv header

########################################################################################################################

MitmProxy

Debug a remote website

From Getting Started

  • Configure the web browser to use localhost:8080 as proxy.
  • Start mitmproxy.
  • If not done before, go to http://mitm.it/ and install the CA cert.
  • To intersect requests press and use ~u <regex> & ~q (see the docs)

Reverse proxy local service

Eg. for localhost:3000

mitmproxy -p 4000 --set console_focus_follow --mode reverse:http://localhost:3000/ --set modify_headers="/~q/Origin/http://localhost:3000"

########################################################################################################################

Git

git rebase --onto

Example: Merging on staging is difficult because of diverging histories. You could cherry-pick each commit, or:

# Ensure staging is up-to-date
git checkout staging
git pull

# Ensure my-branch is up-to-date with master (optional but good)
git checkout my-branch
git rebase origin/master

# Make a temp branch from my-branch
git checkout -b temp

# Rebase it from it's chosen parent (here origin/master but can use other to cut
# in a different place, or when not having rebase before) on top of staging.
# Now temp is `origin/staging --> your-commits` which is what you want staging
# to look like
git rebase --onto origin/staging origin/master

# Go staging and reset the pointer to temp. Done
git checkout staging
git reset --hard temp

# Let the world know...
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment