Skip to content

Instantly share code, notes, and snippets.

View johnbuhay's full-sized avatar
📺
Working from New York

John Buhay johnbuhay

📺
Working from New York
View GitHub Profile
@johnbuhay
johnbuhay / dogsitter.py
Created February 5, 2016 15:23
Restart Datadog agent automatically inside docker when python script detects integration changes
#!/opt/datadog-agent/embedded/bin/python
import os
import sys
import time
import re
import subprocess
import logging
# To keep this lightweight we assume the following
@johnbuhay
johnbuhay / setup-users.groovy
Created January 21, 2016 01:15
jenkins init.groovy.d script for configuring users
import jenkins.*
import hudson.*
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.domains.*
import com.cloudbees.jenkins.plugins.sshcredentials.impl.*
import hudson.plugins.sshslaves.*;
import hudson.model.*
import jenkins.model.*
import hudson.security.*
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
log_not_found off;
proxy_cache_valid any 1m;
proxy_pass http://local_backend$uri$is_args$args;
add_header X-Proxy-Cache $upstream_cache_status;
}
git_move() { # where $1 is your origin name and $2 is the new origin url
git fetch --all
git pull --all
for b in `git branch -r | grep -v -- '->'`; do git branch --track ${b##origin/} $b; done
git remote remove $1
git remote add $1 $2
for b in `git branch | grep -v -- '*'`; do git push -u origin $b; done
git push --tags
}
@johnbuhay
johnbuhay / one-liners
Last active August 29, 2015 14:23
Particularly fond of these useful one liners:
# Get a version from a json:
REMOTE_VERSION=$(curl -s URL_THAT_RETURNS_JSON|python -c 'import json,sys;obj=json.load(sys.stdin);print obj["version"]')
# Get latest version from Artifactory:
REMOTE_VERSION=$(curl -s http://{{artifactory_integration_host}}:8081/artifactory/api/npm/libs-npm-virtual/ww-node-configs/latest|python -c 'import json,sys;obj=json.load(sys.stdin);version = "0.0.0" if obj.get("version") is None else obj["version"];print version')
# To stop a job in jenkins if this build is not for a newer version:
python -c 'import sys; exit(0) if sys.argv[1] > sys.argv[2] else exit(1)' $LOCAL_VERSION $REMOTE_VERSION