Skip to content

Instantly share code, notes, and snippets.

View paddyboyle's full-sized avatar

Patrick Boyle paddyboyle

  • CommScope
  • Virginia
View GitHub Profile
@iradul
iradul / docker_image_cleanup.sh
Last active October 16, 2019 06:10
Remove all Docker images filtered by `pattern` except latest `n`
#some grep pattern
pattern=192.168
# save latest n images
n=1
# check first (?):
# docker inspect -f '{{ .Created }} {{ .Id }} {{ .RepoTags }}' $(docker images | tail -n+2 | sed 's/^\([^ ]*\) *\([^ ]*\) *\([^ ]*\).*/ \1:\2 \3 /' | grep $pattern | cut -d' ' -f3) | sort -r | tail -n+$((n+1))
docker rmi $(docker inspect -f '{{ .Created }} {{ .Id }}' $(docker images | tail -n+2 | sed 's/^\([^ ]*\) *\([^ ]*\) *\([^ ]*\).*/ \1:\2 \3 /' | grep $pattern | cut -d' ' -f3) | sort -r | tail -n+$((n+1)) | cut -d' ' -f2 | cut -c8-)
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active July 7, 2024 13:22
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@katylava
katylava / git-selective-merge.md
Last active February 27, 2024 10:18
git selective merge

Update 2022: git checkout -p <other-branch> is basically a shortcut for all this.

FYI This was written in 2010, though I guess people still find it useful at least as of 2021. I haven't had to do it ever again, so if it goes out of date I probably won't know.

Example: You have a branch refactor that is quite different from master. You can't merge all of the commits, or even every hunk in any single commit or master will break, but you have made a lot of improvements there that you would like to bring over to master.

Note: This will not preserve the original change authors. Only use if necessary, or if you don't mind losing that information, or if you are only merging your own work.