Skip to content

Instantly share code, notes, and snippets.

@vasuadari
Last active September 27, 2022 09:40
Show Gist options
  • Save vasuadari/9c841b5c7c3c2efadf6ad5063fa61963 to your computer and use it in GitHub Desktop.
Save vasuadari/9c841b5c7c3c2efadf6ad5063fa61963 to your computer and use it in GitHub Desktop.
My Cheat Sheet

MySQL

Dump a query result to a csv file

mysql -h [HOST] -P [PORT] -u [USER] DB_NAME -e '[QUERY]' -p > [FILE_NAME].csv

Networking

Debug any outgoing connection to an ip

sudo tcpdump -i any -n host [IP_ADDRESS]

Debug TCP packets received from an IP

sudo tcpdump -i any -nn -s0 -v src [IP_ADDRESS]

Debug HTTP GET Requests

sudo tcpdump -s 0 -A 'tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420'

Running traceroute using mtr on icmp port

sudo mtr -n --report -c 1 [IP_ADDRESS]

Set a nameserver for a command on OSX

networksetup -setdnsservers Wi-Fi 1.1.1.1 | curl -I google.com

Elixir

How to use elixir remote console in your local

Start a phx.server with node name and cookie

elixir --name myapp@127.0.0.1 --cookie foobar -S  mix phx.server

Use –remsh to start remote console

iex --name myapp1@127.0.0.1 --cookie foobar --remsh myapp@127.0.0.1

Postgres

PG Dump

pg_dump --host localhost --port 5432 --username postgres --verbose --file "<abstract_file_path>" --table public.tablename dbname

PG Restore

pg_restore --verbose --clean --no-acl --no-owner -h localhost -U [user] -d [db] [filename].dump

or

psql --verbose --clean --no-acl --no-owner -h localhost -U [user] [filename].sql [db]

When used plain format option with pg_dump

Port fowarding using socat

socat TCP-LISTEN:8080,fork,reuseaddr TCP:google.com:443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment