Skip to content

Instantly share code, notes, and snippets.

View byrnedo's full-sized avatar

Donal Byrne byrnedo

View GitHub Profile
@byrnedo
byrnedo / clone_stash_project.sh
Last active September 22, 2015 11:05
Clone every repo in an Atlassian Stash project. Must run with env variables STASH_USER and STASH_PASSWORD set. Must also change url and git url.
#!/bin/bash
if [ $# -lt 1 ]
then
echo >&2 Must give project code as argument
exit 1
fi
string_project=$1
#CHANGEME
@byrnedo
byrnedo / gnatsd_service_check.sh
Last active September 22, 2015 11:07
Check if one can get a response on a nats channel. I use it for health checking node services. Uses mailgun to email.
#!/bin/bash
set -ueo pipefail
natsUrl="nats://user:pass@192.168.1.84:4222"
checkTimeout=6
mailgunDomain=CHANGEME
mailgunAPIKey=CHANGEME
deliveryEmailAddress=CHANGEME
SEND_ERROR_MAIL=1
@byrnedo
byrnedo / staticDockerPortMapper.zsh
Last active October 29, 2015 15:10
Maps a dynamically allocated docker port to a chosen static port. Watches for updates.
func staticDockerPortMapper(){
[[ $# -lt 3 ]] && >&2 echo "usage: $0 <container-name/id> <exposed-container-port>/<tcp|udp> <static-port>" && return
local container=$1
local internalPort=$2
local staticPort=$3
local currentPid=$(lsof -ti :$staticPort 2>/dev/null)
if [[ -n $currentPid ]]
then
@byrnedo
byrnedo / bash_iniparse.sh
Created January 20, 2016 08:21 — forked from splaspood/bash_iniparse.sh
Parsing INI Files with Bash
cfg.parser () {
fixed_file=$(cat $1 | sed 's/ = /=/g') # fix ' = ' to be '='
IFS=$'\n' && ini=( $fixed_file ) # convert to line-array
ini=( ${ini[*]//;*/} ) # remove comments
ini=( ${ini[*]/#[/\}$'\n'cfg.section.} ) # set section prefix
ini=( ${ini[*]/%]/ \(} ) # convert text2function (1)
ini=( ${ini[*]/=/=\( } ) # convert item to array
ini=( ${ini[*]/%/ \)} ) # close array parenthesis
ini=( ${ini[*]/%\( \)/\(\) \{} ) # convert text2function (2)
ini=( ${ini[*]/%\} \)/\}} ) # remove extra parenthesis
@byrnedo
byrnedo / fr.sh
Created January 21, 2016 07:53
Find Repo: Git repo fuzzy find (uses Fzf)
# Add this to your bashrc/zshrc somewhere
# Set env FR_SEARCH_PATH to where you want fr to start looking from, otherwise it starts at current dir.
function fd() {
local startDir=${FR_SEARCH_PATH:=.}
local dir
dir=$(cd $startDir && find . -name *.git -type d -nowarn 2>/dev/null | sed 's/\(.*\)\/.git/\1/' | fzf) && cd "$startDir/$dir"
}
@byrnedo
byrnedo / split_php_myadmin_export.sh
Created March 2, 2016 14:53
Splits a phpmyadmin sql export into one file per database. Requires a 'footer.sql' and 'header.sql' file for custom content.
#!/bin/bash
set -euo pipefail
mkdir -p ./out
rm -rf ./out/prod_split_*
csplit -n2 -s -f "out/" -b "prod_split_%d" $1 "/-- Database: /-1" "{*}"
rm -f ./out/prod_split_0
cd ./out
@byrnedo
byrnedo / startSwarm.sh
Last active February 5, 2017 22:08
Start 3 Machine Local Docker Swarm
#!/bin/bash
set -euo pipefail
function useDockerEnv {
eval "$(docker-machine env $1)"
}
function getIfaceIP {
local machine="$1"
@byrnedo
byrnedo / AppServiceProvider.php
Last active May 20, 2017 15:55
Add Nullable If validator in laravel 5.4
<?php
...
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
@byrnedo
byrnedo / compose-merge.pl
Last active March 7, 2018 07:56
Stand in to merge docker compose file merging (docker stack deploy doesn't do the magic yet), does the 'extends' replacement and the env var replacement.
#!/usr/bin/perl
#
#====================================================
#
# Stand in for docker-compose 'extends' and env replacement
# ( currently not implemented for `docker stack deploy -f` )
#
#====================================================
use strict;
@byrnedo
byrnedo / http-health-slack.sh
Created May 15, 2018 08:56
Check urls for 200s or send slack message
#!/bin/bash
WORK_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
set -ueo pipefail
checkTimeout=6
SEND_ERROR_MAIL=1
cd "$WORK_DIR"
function send_to_slack {
local status=$1