Skip to content

Instantly share code, notes, and snippets.

@adampats
adampats / docker_reg_image_version
Created February 26, 2016 23:48
function to get docker registry versions
# Dump all docker registry image versions
docker_reg_image_versions () {
if [ -z $1 ]; then
echo "Pass registry hostname as argument."
else
reg="$1"
read -p "$reg username: " user
read -s -p "$reg password: " pass
echo ""
for i in $(curl -k -s -X GET "https://$reg/v2/_catalog" \
@adampats
adampats / response.json
Last active February 29, 2016 22:36
aws spot instance requests jq parsing
{
"CreateTime": "2016-02-29T18:18:48.000Z",
"ImageId": "ami-f7a2bf96",
"InstanceType": "m4.large",
"SpotInstanceRequestId": "sir-039b6k6b",
"SpotPrice": "0.030000",
"State": "cancelled",
"Status": {
"Code": "instance-terminated-by-user",
"Message": "Spot Instance terminated due to user-initiated termination.",
@adampats
adampats / jqf.sh
Last active March 9, 2016 22:16
bash jq filter newline
foo () {
jqf='.ImageId,'\
'.InstanceId'
aws_ec2_list | jq -S "$jqf"
}
@adampats
adampats / saws.sh
Created May 12, 2016 17:03
python el capitan issues
sudo pip install saws --ignore-installed six
Password:
The directory '/Users/adam/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/adam/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting saws
Downloading saws-0.4.0.tar.gz
Collecting awscli>=1.7.46 (from saws)
Downloading awscli-1.10.27-py2.py3-none-any.whl (937kB)
100% |████████████████████████████████| 942kB 1.3MB/s
@adampats
adampats / groovy.groovy
Created May 18, 2016 22:25
Jenkins groovy script to execute shell command
def cmd = 'hostname'
def sout = new StringBuffer(), serr = new StringBuffer()
def proc = cmd.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
println sout
@adampats
adampats / get_user_repos.py
Created May 26, 2016 23:13
PyGithub with GHE
from github import Github
g = Github("user", "pass", base_url="https://github.foo.net")
u = g.get_user('user')
print u.name
@adampats
adampats / creds.groovy
Created July 27, 2016 05:00
Jenkins Credentials Binding pipeline groovy
try {
err = null
currentBuild.result = "SUCCESS"
node {
stage 'One'
// using a single secret Jenkins credential
withCredentials([[$class: 'StringBinding', credentialsId: 'my-api-token', variable: 'API_TOKEN']]) {
sh '''
set +x
@adampats
adampats / newvar.groovy
Created March 15, 2017 04:44
Groovy / Jenkinsfile create variable name from arbitrary string
// requires Jenkins - Groovy Sandbox to be turned OFF
new_var = "varname"
new GroovyShell(this.binding).evaluate("${new_var} = 'skittles'")
println varname
@adampats
adampats / ledocker.sh
Created March 15, 2017 20:29
Install docker on Ubuntu
apt-get update
apt-get install -y linux-image-extra-$(uname -r) \
linux-image-extra-virtual \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
@adampats
adampats / env_vars.sh
Last active March 17, 2017 16:07
Set environment variables from key/value file
export $(cat config.env | grep -v ^# | xargs)