Skip to content

Instantly share code, notes, and snippets.

View patoarvizu's full-sized avatar

Pato Arvizu patoarvizu

  • ASAPP
  • Brooklyn, NY
View GitHub Profile
@patoarvizu
patoarvizu / gist:45b7790fe058bbf733ccf3cecf004bb9
Created April 2, 2020 22:19
Terminate all pods in Unknown state
for ns in $(kubectl get ns -o json | jq -r '.items[].metadata.name'); do for p in $(kubectl get pods -n $ns -o json | jq -r '.items[] | select(.status.reason == "NodeLost") | .metadata.name'); do kubectl -n $ns delete pod $p --force --grace-period=0; done; done
@patoarvizu
patoarvizu / gist:65f6d36af62c2d327e54ee1c4ee18798
Created April 2, 2020 20:22
Delete all empty ReplicaSets in all namespaces
for ns in $(kubectl get ns -o json | jq -r '.items[].metadata.name'); do for rs in $(kubectl get rs -n $ns -o json | jq -r '.items[] | select(.status.replicas == 0) | .metadata.name'); do kubectl -n $ns delete rs $rs; done; done
@patoarvizu
patoarvizu / gist:cfc26f88b5661e2e78f4a5bcea6f66a4
Created October 5, 2016 18:56
Create replacement string for using sed as a template processor
for token in TOKEN_A TOKEN_B TOKEN_C; do
REPLACEMENT_STRING=$REPLACEMENT_STRING"s|%$token%|"$(eval echo \$$token)"|g;"
done
Verifying that +patoarvizu is my blockchain ID. https://onename.com/patoarvizu
@patoarvizu
patoarvizu / update-user-data.sh
Created August 13, 2015 20:08
Encode and update CloudFormation User Data
NEW_USER_DATA=$(base64 bootstrap.sh | tr -d '\n')
sed -i '' "s/\"UserData\": \".*\"/\"UserData\": \"$NEW_USER_DATA\"/g" template.json

Keybase proof

I hereby claim:

  • I am patoarvizu on github.
  • I am patoarvizu (https://keybase.io/patoarvizu) on keybase.
  • I have a public key whose fingerprint is B1A5 C438 F040 D35C 6F8D D982 A566 D955 781F 1AA0

To claim this, I am signing this object:

@patoarvizu
patoarvizu / find-largest-directories
Last active December 26, 2015 19:39
Shell script to find 10 largest directories. Ssubstitute -type d with -type f to find largest files or tail -10 with any other number if you want to see more than 10.
find . -type d -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
@patoarvizu
patoarvizu / translate-tag-to-sha1-and-update.sh
Created September 5, 2013 21:55
Get sha1 for given tag in Mercurial and update using the sha1 rather than the tag. I don't have a specific use case, but I created it when trying to work around this problem (https://issues.jenkins-ci.org/browse/JENKINS-14862) although it doesn't actually work in that scenario.
hexRevision=$(less .hgtags | grep <tag-name> | cut -d ' ' -f1)
hg up $hexRevision
@patoarvizu
patoarvizu / translate-tag-to-revision-id
Created July 31, 2013 17:48
Gets the revision id for a specific Mercurial tag. Useful for a bug seen in Jenkins where the Mercurial plugin can't update to branches or tags with a hyphen '-' on their name. The piped commands do, in order, the following: - Get the list of tags. - Search for the line with the specific tag we're looking for. - Trim multiple spaces into one. Th…
hg tags | grep $tag | tr -s ' ' | cut -d' ' -f2
@patoarvizu
patoarvizu / JobForEachBranch
Last active December 19, 2015 03:08
Iterate over a file called branches (that should contain a list of branches to be built, one in each line) and triggers another Jenkins job via the REST API and authenticating with the API Token. It pulls the missing revisions from ALL branches as a final step.
for branch in $(cat branches)
do
echo "---------------"
echo "Branch: $branch"
json="{\"parameter\": [{\"name\": \"branch\", \"value\": \"$branch\"}]}"
curl -F json="$json" -u $1:$2 $JENKINS_URL/job/$2/build?token=$4
done
hg pull -u