Skip to content

Instantly share code, notes, and snippets.

View djfdyuruiry's full-sized avatar

matthew snoddy djfdyuruiry

View GitHub Profile
@djfdyuruiry
djfdyuruiry / exec_wsl_cmd.bat
Last active January 6, 2018 17:04
Loads Bash on Ubuntu on Windows, sets bash pwd to the Windows dir where the bat script currently is, and executes a command specified by first parameter.
C:\Windows\System32\bash.exe -c "echo '%~dp0' | sed -e 's|\\\\|/|g' -e 's|^\([A-Za-z]\)\:/\(.*\)|/mnt/\L\1\E/\2|' | cd && %1"
@djfdyuruiry
djfdyuruiry / pipeline_build_on_merge_to_master.groovy
Last active February 18, 2018 01:41
Jenkins pipeline that builds on merge to master; useful for Multi-Branch Pipelines where you only want master code to be auto built (feature branches are then manually triggered during development).
if (env.BRANCH_NAME == "master") {
properties([
pipelineTriggers([
pollSCM("H/5 * * * *")
])
])
}
pipeline {
agent none

A custom step for Jenkins pipelines that allows scaling a task n times in parallel, specifying parameters for each thread

@djfdyuruiry
djfdyuruiry / watchSqs.sh
Last active May 24, 2018 13:26
Pop off and log SQS messages from a given queue, both to std out and a log file (with an err log file)
#!/bin/bash
queueName="sns-queue"
endpointUrl="http://localhost:4576"
queueUrl="${endpointUrl}/queue/${queueName}"
queueLogFile="sqs_${queueName}.log"
queueErrorLogFile="sqs_${queueName}_err.log"
jsonLoadFromStdIn="json.load(sys.stdin)"
doJsonOperation() {
@djfdyuruiry
djfdyuruiry / vagrant-utils.sh
Created June 17, 2018 16:25
Bash function 'library' which contains handy vagrant utils, including provisioning, suspending and resuming multiple machines in parallel.
#!/usr/bin/env bash
if [ ! `command -v "vagrant"` ]; then
>&2 echo "ERROR: Script $0 requires vagrant, it was not found in the path"
exit 1
fi
vagrantProvider=${VAGRANT_PROVIDER:-virtualbox}
providerAwkString="[${vagrantProvider:0:1}]${vagrantProvider:1}"
vagrant-status() {
@djfdyuruiry
djfdyuruiry / json-path-query.sh
Last active June 21, 2018 22:43
JSON path bash util function using python, supports array queries, array indices, list object fields and array length query.
#!/usr/bin/env bash
jsonLoadFromStdIn="json.load(sys.stdin)"
loopOverItems=false
loopJsonOperation=""
__doJsonOperation() {
json="$1"
operation="$2"
operationWithJsonLoad=${operation/__JSON__/$jsonLoadFromStdIn}
@djfdyuruiry
djfdyuruiry / jenkinsApiClient.sh
Last active July 13, 2018 21:15
Jenkins API Client written in Bash
#!/usr/bin/env bash
########################################################################################################################
# #
# Jenkins API client written in Bash using the `wget` and `curl` commands #
# ----------------------------------------------------------------------- #
# See: https://gist.github.com/djfdyuruiry/71714479b3a5f7eb1e714df5d3499665 #
# #
# Using global configuration: #
# #
# export JENKINS_URL="https://my-
@djfdyuruiry
djfdyuruiry / queryMavenCentral.sh
Last active July 21, 2018 16:57
Maven Central Search Script
#/usr/bin/env bash
if [ "$#" -lt 1 ] || [ -z "$1" ]; then
>&2 echo "Usage: $0 searchTerm [searchResultLimit] # default searchResultLimit is 5"
exit 1
fi
if [ -z "$(command -v python)" ]; then
>&2 echo "$0 requires python to be installed and in the current PATH"
exit 1
@djfdyuruiry
djfdyuruiry / Grafana-snapshot.py
Last active August 19, 2018 21:10
Automated Grafana Snapshots using Python
from datetime import datetime, timedelta
from requests import get, post
GRAFANA_DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
GRAFANA_CREDS = ('user', 'password')
dashboardResponse = get('https://grafana.host/api/dashboards/a/dashboard', auth = GRAFANA_CREDS)
dashboard = dashboardResponse.json()['dashboard']
@djfdyuruiry
djfdyuruiry / generatePseudoUniqueId.lua
Last active August 23, 2018 23:21
Pseudo unique ID generator using a combination of memory addresses, time and random number generators. IDs are unique at worst unique 55% of the time, and at best up to 95% of the time.
MAX_ID_LENGTH = 10
local generatePseudoUniqueId = function()
local threadAddress = tostring({}):sub(10)
local threadAddressLetters = threadAddress:gsub("%d", "")
local threadAddressNumbers = threadAddress:gsub("[a-z]", "")
local threadAddressNumber = tonumber(threadAddressNumbers)
local maxNumberWidth = MAX_ID_LENGTH - threadAddressLetters:len()