Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / test1.rb
Created January 27, 2016 19:08
Ruby subthread stdout
require 'open3'
puts "test1.rb"
Open3.popen3("ruby test2.rb") do |stdin, stdout, stderr, wait_thr|
while line = stdout.gets do
puts line
end
end
@adampats
adampats / cloudtrail.sh
Created January 19, 2016 20:35
View CloudTrail logs from S3 quickly
bucket_name="my-cloudtrail-bucket"
acc_num="myacc"
region="us-west-1"
aws s3 cp --recursive s3://$bucket_name/AWSLogs/$acc_num/CloudTrail/$region/2016/01/
ls
gunzip -c cloudTrail-log-file-name.json.gz | jq .
@adampats
adampats / logs.sh
Last active January 14, 2016 20:45
docker log tail loop
set -e
log_files=( /home/app/log/development.log \
/home/app/log/production.log )
for i in ${log_files[@]}; do
if [[ -e $i ]]; then
exec tail -F $i
else
exec sleep 10
@adampats
adampats / create_repo.sh
Created November 18, 2015 01:18
Create GitHub repo from command line and push
# Personal Access Token required - go here: https://github.com/settings/tokens
repo="newrepo"
gh_user="adampats"
gh_token="mytoken"
curl -u "$gh_user:$gh_token" https://api.github.com/user/repos -d '{"name":"'$repo'"}'
@adampats
adampats / databag.sh
Created November 4, 2015 19:12
chef data bags encryption
# create json file in appropriate location, e.g.
./data_bags/docker/config.json
# add stuff in data_bag format to config.json
nano ./data_bags/docker/config.json
# generate a secret key if you don't have one
openssl rand -base64 512 | tr -d '\r\n' > chef_secret_key
# encrypt it - chef-zero style