bartekpacia / garden

https://garden.pacia.tech
2 stars 1 forks source link

Share useful snippets #9

Open bartekpacia opened 7 months ago

bartekpacia commented 7 months ago

gh and jq

List all workflows with name containing test:

gh workflow list --json name --jq '.[] .name' | grep test

List all workflows runs that are in progress:

gh run list --status in_progress

List all queued or in_progress GitHub Actions runs:

gh run list --json status,databaseId --jq 'map(select(.status == "queued" or .status == "in_progress")) | .[] .databaseId' | xargs -I {} echo "id: {}"
gh run list --json databaseId | jq '.[] .databaseId' | xargs -P 10 -I {} gh run cancel {}

List all releases in a private repository:

curl -L \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: token $(op read "op://Developer/GitHub PATs/supertoken")" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/bartekpacia/discover_rudy/releases | jq -r '.[] .tag_name'

Delete workflow runs with specific name:

workflow_name="debug"
gh run list --workflow "$workflow_name" --json createdAt,status,databaseId | jq -r '.[] .databaseId' | xargs -I {} gh run delete {}

Delete workflow runs with specific name (this works when workflow with the name no longer exists) (jq args syntax):

workflow_name="deploy tst"
gh run list --json name,createdAt,status,databaseId | jq --arg workflow "$workflow_name" '.[] | select(.name == $workflow).databaseId' | xargs -I {} gh run delete {}

fzf

This line enlightened me on how fzf really works and what it is for:

fzf --multi "$@" < <(echo "C C++ Go Dart Kotlin Java Python JavaScript Swift" | tr ' ' '\n')

Same as above but "shell completion" style:

_fzf_complete '--multi' "$@" < <(echo "C C++ Go Dart Kotlin Java Python JavaScript Swift" | tr ' ' '\n')

Search syntax is described in the README!

Non-interactive use:

fzf --filter "'lockfile" | grep -v -e project-app.lockfile -e buildscript-gradle.lockfile
bartekpacia commented 7 months ago

zsh

Get options: setopt

Read about options: man zshoptions or man zshall.

Editing multiline commands is possible!

Editing word splitting is possible!

bartekpacia commented 3 months ago

docker

Remove images whose tag contains $TAG:

TAG=flutter
docker image ls -a --format '{{ .Tag }} {{ .ID }}' | grep $TAG | cut -d ' ' -f 2 | xargs docker image rm

List images and show their architecture:

docker image inspect $(docker images -q) | jq -r '.[] | .RepoTags[0], .Architecture'

or:

docker image inspect $(docker images -q) | jq -c '.[] | { tag: .RepoTags[0], arch: .Architecture }'

Update all local images:

docker image ls -a --format '{{ .Repository }}:{{ .Tag }}' | xargs -I {} docker pull {}

... and remove dangling images:

docker system prune
bartekpacia commented 2 months ago

DNS thingies

Get DNS, same as defined in Network Settings (this is Cloudflare DNS):

$ networksetup -getdnsservers Wi-Fi
1.1.1.1
1.0.0.1
2606:4700:4700::1111
2606:4700:4700::1002

Set DNS servers:

networksetup -setdnsservers Wi-Fi 1.1.1.1 1.0.0.1 2606:4700:4700::1111 2606:4700:4700::1001
bartekpacia commented 2 months ago

More network things

See what process connect to internet on my mac:

netstat -anvp tcp | awk '/LISTEN/ {print $9}' | xargs ps -p
netstat -anvp tcp | awk 'NR > 2' | awk '{print $1, $4, $6, $9}' | column -t
bartekpacia commented 2 months ago

Android emulator

emulator -help-all
emulator -accel-check
bartekpacia commented 4 weeks ago

flutter


flutter build ipa

flutter build ipa --obfuscate --split-debug-info

Issue where flutter build ipa was implemented: https://github.com/flutter/flutter/issues/13065