Skip to content

Instantly share code, notes, and snippets.

View mcindea's full-sized avatar

Mihai Cindea mcindea

  • 127.0.0.1
View GitHub Profile
@mcindea
mcindea / stop_azure_devops_jobs.ps1
Created August 4, 2022 11:36
Stops batch azure devops jobs/builds related to a specific repo
# This script can help to stop multiple jobs if there are too many to stop by point and click
# Just modify targetRepository, AzureDevOpsPAT and OrganizationName and it will stop all builds related to the target repository
$targetRepository = "some_repo_name"
$AzureDevOpsPAT = "XXXXX"
$OrganizationName = "org/project"
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }
$builds = Invoke-RestMethod -Uri "https://dev.azure.com/$OrganizationName/_apis/build/builds?api-version=6.0&repositoryId=" -Method get -Headers $AzureDevOpsAuthenicationHeader
$runningBuilds = $builds.value | Where-Object { $_.repository.name -like $targetRepository } | Where-Object { $_.status -eq 'inProgress' }
foreach($build in $runningBuilds){
@mcindea
mcindea / start_nano.sh
Created March 2, 2021 23:01
Stops mining software nanominer if Plex Transcoder is running, and starts it again whenever Plex stops transcoding.
#!/bin/bash
# Limit the GPU power draw to 115W
nvidia-smi -pl 115
function check_if_active {
nvidia-smi --query-compute-apps=name --format=csv,noheader | grep -q "$1"
}
while : ;do
@mcindea
mcindea / s3_buckets_size.sh
Created October 16, 2020 13:32
extracts size of S3 AWS Bucket from a list using cloudwatch
#!/bin/bash
# Execute as :
# ./s3_buckets_size.sh list.txt
# where list.txt is a list of all bucket
for bucket in `cat $1`;do
SIZE=$(aws cloudwatch get-metric-statistics --namespace AWS/S3 --start-time $(date +%Y-%m-%dT%H:%M:%S -d "00:00 last week") --end-time $(date +%Y-%m-%dT%H:%M:%S) --period 86400 --statistics Average --region eu-west-1 --metric-name BucketSizeBytes --dimensions Name=BucketName,Value=$bucket Name=StorageType,Value=StandardStorage | jq .Datapoints[].Average | tail -1)
echo $bucketname $(numfmt --to iec --format "%8.1f" ${SIZE:-"0"})
done
@mcindea
mcindea / vmware_tools_fixer.sh
Last active April 7, 2022 06:00
Vmware tools fixer when
#!/bin/bash
# Vmware tools fixer
# When vmware tools refuse to start
vmware-guestproxycerttool -g -f&&
/usr/bin/vmware-config-tools.pl -d&&
/etc/vmware-tools/services.sh restart
# Fix automated tools install
mkdir /p /media/cdrom &&
@mcindea
mcindea / find-aws-ecr-image.sh
Created July 13, 2020 08:21
Checks if a docker image tag exists in AWS ECR, and returns an exit code different than 0 if it doesn't.
#!/usr/bin/env bash
# Checks if a docker image tag exists in AWS ECR, and returns an exit code different than 0 if it doesn't.
REGISTRY_ID="${1%%.*}"
IMAGE_TAG=${1##*:}
REPOSITORY="$(echo ${1%%:*} | cut -d / -f 2,3)"
if [[ -z "$REGISTRY_ID" ]] || [[ -z "$IMAGE_TAG" ]] || [[ -z "$REPOSITORY" ]] ; then
echo "Usage: $( basename $0 ) url:tag"
echo "Example: $( basename $0 NNNNNNNNN.dkr.ecr.eu-west-1.amazonaws.com/repo-something:latest) "
#!/usr/bin/env bash
# ./find-ecr-image.sh 1234567890.dkr.ecr.eu-west-1.amazonaws.com/supersecret:tag
REGISTRY_ID="${1%%.*}"
IMAGE_TAG=${1##*:}
REPOSITORY="$(echo ${1%%:*} | cut -d / -f 2,3)"
if [[ -z "$REGISTRY_ID" ]] || [[ -z "$IMAGE_TAG" ]] || [[ -z "$REPOSITORY" ]] ; then
echo "Usage: $( basename $0 ) url:tag"
echo "Example: $( basename $0 NNNNNNNNN.dkr.ecr.eu-west-1.amazonaws.com/something:master) "
@mcindea
mcindea / .bashrc
Created March 11, 2020 07:25
my personal .bashrc for dailly life
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific environment
PATH="$HOME/.local/bin:$HOME/bin:$PATH"
export PATH
@mcindea
mcindea / airquality.py
Created January 10, 2020 20:39
Uses SDS011 to get the data and store it to InfluxDB - Tested it from a RaspberryPI
import serial, time, os, traceback
from influxdb import InfluxDBClient
# InfluxDB details
dbname = os.getenv('INFLUXDB_DATABASE', 'airquality')
username = os.getenv('INFLUXDB_USER')
password = os.getenv('INFLUXDB_PASSWORD')
host = os.getenv('INFLUXDB_HOST', '192.168.100.21')
port = os.getenv('INFLUXDB_PORT', 8086)
@mcindea
mcindea / codeship-extract-logs.sh
Last active December 10, 2019 10:43
Download or extract logs from CodeShip
# I made this script because CodeShip for some reason doesn't have an option to download the logs, so any logs bigger
# than your browser can handle will make it hang. You just need the jq installed for this script to work.
# How-to:
# If you open the Developer console and look at Network when you click a log, you will see something with the name:
# 'jet_log?start_index=' <- Just right click it, Copy => Copy as cURL.
# Then simply execute the command and pipe it to a file, or the following command:
# jq -c .service_log[].payload | tr -d \" | base64 -d
# Append this to your .bashrc, to use it at the end of the cURL command with a pipe, as so:
# <super long cURL command> | codeship-extract
@mcindea
mcindea / fix_nssdb_rhel6_rhel7-8.sh
Last active November 29, 2019 10:01
This script converts DB files created for NSS makedb command while you upgrade from RHEL6 to RHEL7 or 8.
#!/bin/bash
# This script converts DB files created for NSS while you upgrade from RHEL6 to RHEL7 or RHEL8.
# It only happens when you upgrade from RHEL6
# Fixes a problem where the groups are not properly added to the file like the following:
# :john john 2001,2500,4
# First copy the old file to a new file
cp group.tdb group_test.tdb
for line in `grep ^= group.tdb | grep :$ | awk '{print $2}'`; do