Skip to content

Instantly share code, notes, and snippets.

View gokart23's full-sized avatar

Karthik Duddu gokart23

View GitHub Profile
@gokart23
gokart23 / delete-slaves.groovy
Created December 11, 2017 07:54
Delete slaves with a certain label directly from Jenkins master script console
import hudson.slaves.*
import hudson.model.*
for (aSlave in hudson.model.Hudson.instance.slaves) {
if (aSlave.name.indexOf("medium-rt-framework") == 0 && !aSlave.getComputer().isOnline()) {
aSlave.getComputer().setTemporarilyOffline(true, null)
aSlave.getComputer().doDoDelete()
}
}
@gokart23
gokart23 / human_readable_time_to_ms.py
Created December 20, 2017 07:27
Convert human-readable time ('1 min 3 sec', '0.58 hr', etc) to milliseconds
interval_dict = OrderedDict([
('hr', 3600*1000),
('min', 60*1000),
('sec', 1000),
('ms' , 1),
])
def convert_to_ms(string):
interval_regex = re.compile( "^[<]?(?P<value>(\d\.)?[0-9]+) (?P<unit>({0}))".format("|".join(interval_dict.keys())) )
@gokart23
gokart23 / convert_kubectl_events_to_local_tz.sh
Created January 1, 2018 13:38
Convert Kubernetes events to local timezone (for comparison with other logs)
kubectl get events -o json | jq '.items[] | .lastTimestamp + "," + .message' | tr -d '"' | awk -F',' '{cmd="date +\"%d/%b/%Y:%T\" --date=" $1; cmd | getline conv_date; print "[" conv_date "] (kubectl events) " $2}'
@gokart23
gokart23 / KubeConnect.java
Created January 3, 2018 14:16
Remove nodes from a Kubernetes deployment programatically, in order to potentially use the deployment as a pool of ready nodes
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
@gokart23
gokart23 / trigger_jenkins_pipeline_programmatically.java
Created January 18, 2018 16:55
Programmatically trigger a pipeline run (with custom data) in Jenkins
import jenkins.model.*;
import hudson.model.Job;
import hudson.model.Run;
import hudson.model.queue.QueueTaskFuture;
import org.jenkinsci.plugins.workflow.cps.replay.ReplayAction;
String text = "node('some-node') { echo 'hi'; }"
@gokart23
gokart23 / kubernetes-rest-apply.sh
Created February 9, 2018 11:16
Kubernetes REST API for `kubectl apply -f <file>`
# Kubernetes Server: 1.3
# If this is the first time that apply is being called
curl -X POST -H "Content-Type: application/json" "${KUBERNETES_API_SERVER}"/apis/extensions/v1beta1/namespaces/my-namespace/deployments/ --data @my-deployment-spec.json
# If this is the first time that apply is being called
curl -X PATCH -H "Content-Type: application/json-patch+json" "${KUBERNETES_API_SERVER}"/apis/extensions/v1beta1/namespaces/my-namespace/deployments/my-deployment --data @my-deployment-spec.json
@gokart23
gokart23 / download.py
Last active December 19, 2019 00:28 — forked from rjchee/download.py
Download videos from Panopto based on RSS feed file
#!/bin/env python3
import argparse, sys
import os, subprocess
import xml.etree.ElementTree as ET
parser = argparse.ArgumentParser()
parser.add_argument("--rssfile", help="Location of RSS feed file downloaded from Panopto",
required=True, type=argparse.FileType('r'))
args = parser.parse_args()
@gokart23
gokart23 / run-arm-chroot-on-x86.md
Last active September 2, 2024 06:36
Run ARM chroot on x86 machine (both ArchLinux)

Steps

  1. Install qemu-user-static (yay -S qemu-user-static).
    • This might need you to install pcre-static and update PGP keys (follow the tips in the comments here).
  2. If not already present, install systemd-binfmt, the revamped version of binfmt-support tools
    • Your system has to support transparent Qemu user emulation, but fortunately, that is mostly enabled once the steps here have been followed.
  3. Check the status of the systemd-binfmt unit (systemctl status systemd-binfmt) and (re)start if needed (sudo systemctl restart systemd-binfmt)
    • This unit has ARM support by default, but check the current documentation to make install it if needed
  4. Mount the root partition of the ARM system into a folder (for e.g., sudo mount /dev/sdb2 arm_mountpoint)
  5. Copy the QEMU ARM static binary (/usr/bin/qemu-arm-static on my distro) to the mounted root directory's usr/bin
  1. Setting up docker to use a different image directory: https://stackoverflow.com/a/34731550
  2. Jellyfin docker image: docker run --name "jellyfin-server" --restart=unless-stopped -d -v $(pwd)/config/:/config -v $(pwd)/cache/:/cache -v /home/nemty/media:/media --net=host jellyfin/jellyfin
@gokart23
gokart23 / useful_bash_tricks.md
Last active October 19, 2020 23:02
Useful bash tricks
  1. Filter CSV based on number of words in a field using awk:

awk -F ',' 'split($2,a," ") == 2 {print $2}' fname

  1. Convert Kubernetes events to local timezone (for comparison with other logs):

kubectl get events -o json | jq '.items[] | .lastTimestamp + "," + .message' | tr -d '"' | awk -F',' '{cmd="date +\"%d/%b/%Y:%T\" --date=" $1; cmd | getline conv_date; print "[" conv_date "] (kubectl events) " $2}'

  1. Remove EOS/BOS from a text data file using sed