Skip to content

Instantly share code, notes, and snippets.

@tstone2077
tstone2077 / startTunnel
Created October 16, 2019 15:07
Start an ssh dynamic tunnel for socks5 proxy
#!/bin/bash
#resp=$(aws ec2 describe-instances | jq '.Reservations[].Instances[] | select(.Tags[].Value=="$EC2_Name") | .InstanceId + " " + .State.Name'
EC2_Name=$1
resp=$(aws ec2 describe-instances | jq '.Reservations[].Instances[] | select(contains({Tags: [{Key: "Name"}, {Value: "$EC2_Name"}]}) ) | .InstanceId + " " + .State.Name' | sed 's/"//g')
respArray=($resp)
if test "${respArray[1]}" == "stopped"
then
echo "Starting EC3..."
aws ec2 start-instances --instance-ids ${respArray[0]}
@tstone2077
tstone2077 / entrypoint-update-uid.sh
Last active September 30, 2019 01:16
Docker entrypoint shell script that updates the docker user's uid to that of a specific directory, allowing that directory to be writable.
#!/bin/bash
# Docker entrypoint file to set the user's uid to an id that can write to
# a specific directory. Note: entrypoint must be run as root
#
# Usage:
# Set MAIN_USERNAME to the username that you want the container to run as
# Set MAIN_DIRECTORY to the directory that you want the user to be able to write
MAIN_USERNAME=username
MAIN_DIRECTORY=/home/username/project
@tstone2077
tstone2077 / git-ignore
Last active May 13, 2016 14:54
File to ignore files/extensions/etc in git.
#!/bin/sh
#
# Copyright (c) 2016, Thurston Stone
DEBUG=0
SUBDIRECTORY_OK=Yes
OPTIONS_KEEPDASHDASH=
OPTIONS_STUCKLONG=t
# Would be nice to have examples, but rev-parse sees '*' as a symbol to hide everything afterwards
@tstone2077
tstone2077 / applyPatches.sh
Last active August 29, 2015 14:25
Apply patches from a text file of urls onto a xen server
#!/bin/bash
function failOnError {
RETVAL=$1
ErrorText=$2
if [[ $RETVAL -ne 0 ]]; then
echo $2
exit $RETVAL
fi
}
@tstone2077
tstone2077 / VBAExternalDataSyncRows
Last active August 29, 2015 14:19
VBA Script for Excel that updates external data AND any extra data that needs to align with that external data.
Sub UpdateQueryData(DataSyncSheetName, _
QueryTableName, _
PrimaryKeyHeaderText, _
PrimaryKeyColumn, _
FirstExtraDataColumn, _
LastExtraDataColumn, _
MainSheetName)
' Assumptions:
' * External Data has a header row
' * External Data starts on A1
@tstone2077
tstone2077 / git-settimes
Created February 12, 2015 16:52
Script to set the times of a working copy to the last commit time.
#!/bin/bash
# Usage: git settimes [-v]
SAVE_IFS=$IFS
VERBOSE="False"
if [[ $1 == "-v" ]]; then
VERBOSE="True"
fi
IFS=$(echo -en "\n\b")
for FILE in $(git ls-files)
do
@tstone2077
tstone2077 / git-cloneall
Last active October 28, 2022 08:53
Clones as usual but creates local tracking branches for all remote branches.
#!/bin/bash
# Clones as usual but creates local tracking branches for all remote branches.
# To use, copy this file into the same directory your git binaries are (git, git-flow, git-subtree, etc)
clone_output=$((git clone "$@" ) 2>&1)
retval=$?
echo $clone_output
if [[ $retval != 0 ]] ; then
exit 1
@tstone2077
tstone2077 / StartJenkinsJobs.py
Last active October 27, 2016 10:14
Kick off a Jenkins Job programmatically.
#!/usr/bin/env python
#from https://gist.github.com/tstone2077/6106950
#__doc__ =
"""
OriginalAuthor: Thurston Stone
Description: Kick off a Jenkins Job programmatically.
Usage: run 'python StartJenkinsJob.py --help' for details.
Known Issues:
-c|--cause does not seem to work yet
@tstone2077
tstone2077 / commandLineTemplate.py
Last active June 1, 2019 15:58
Template for a python tool. This template supports:* running on the command line or importing* alternate return codes* argument parsing and validating* logging
# vim: set fileencoding=utf-8
import argparse
import logging
import os
import sys
import json
# -------------------
__doc__ = """
@tstone2077
tstone2077 / pysed.py
Created December 6, 2012 00:21
Basic sed functionality available in python
"""
OriginalAuthor: [email protected]
Description: Basic sed functionality in python
Usage: pysed -h for help
"""
cmd_desc="""
Basic sed functionality in python
"""
cmd_usage="""