Skip to content

Instantly share code, notes, and snippets.

View toast38coza's full-sized avatar

Christo Crampton toast38coza

View GitHub Profile
@toast38coza
toast38coza / proxy-shell.sh
Last active August 29, 2015 14:08
yum, easy_install, pip and github through a proxy
## yum:
## edit /etc/yum.conf
## command-line stuff:
export http_proxy=http://user:pass@proxy.mycompany.com:80
export https_proxy=https://user:pass@proxy.mycompany.com:80
## Github
git config --global http.proxy user:pass@proxy.mycompany.com:80
git config --global https.proxy user:pass@proxy.mycompany.com:80
@toast38coza
toast38coza / jenkins-api.py
Created October 28, 2014 12:48
Calling Jenkins' API with python
import requests
from requests.auth import HTTPBasicAuth
url = 'http://jenkins.mycompany.com/api/json'
username = '..'
token = '..'
response = requests.get(url, auth=HTTPBasicAuth(username, token))
@toast38coza
toast38coza / mock_consecutive_calls.py
Created October 29, 2014 11:50
A strategy for mocking consecutive calls. For example, if you need to test retrying something if you get an Exception on your first pass
@patch.object(TaskHelper, "get_parent")
def test_mocking(self, mock_get_parent):
responses = [Exception('boom'), 'response']
mock_get_parent.side_effect = lambda *args, **kw: responses.pop(0)
result = TaskHelper.get_parent()
if isinstance(result, Exception):
raise result
result = TaskHelper.get_parent()
@toast38coza
toast38coza / prepare-commit-msg
Created January 7, 2015 19:00
Require that git commit messages contain a Pivotal ID
#!/usr/bin/python
import re, sys
message_file = sys.argv[1]
f = open(message_file)
message = f.read()
p = re.compile('^\[\#\d+\]')
if p.match(message) is None:
print "This commit needs a pivotal story ID. e.g.: git commit -am'[#82695812] - message goes here .. ' where 82695812 is your pivotal story ID"
@toast38coza
toast38coza / .bash_profile
Created January 15, 2015 15:11
Cloning a repo from github through a corporate proxy with username and password
export http_proxy=http://username:password@mycompany.proxy.com:80
export https_proxy=http://username:password@mycompany.proxy.com:80
@toast38coza
toast38coza / get_unique_port
Last active August 29, 2015 14:21
Given a variable `http_port` stored in redis, incr the value and return the new port
redis-cli incr http_port | cut -c1-8
@toast38coza
toast38coza / ansiible-cheatsheet
Created June 4, 2015 12:08
Some useful ansible commands
# Get the ansible facts
ansible -i {inventory_file} -u {username} -m setup {hostname}
@toast38coza
toast38coza / jenkins-webhook.json
Created June 24, 2015 07:48
Creating github service webhooks with Ansible uri_module
{
"name": "jenkins",
"active": true,
"events": [
"push"
],
"config": {
"jenkins_hook_url": "http://ci.jenkins-ci.org/github-webhook/"
}
}
@toast38coza
toast38coza / maxmind_location.js
Created February 24, 2011 15:22
Get your location from MaxMinds JavaScript library (requires JQuery)
$.getScript("http://j.maxmind.com/app/geoip.js",function(){
console.log(geoip_country_code());
console.log(geoip_country_name());
console.log(geoip_city());
console.log(geoip_region());
console.log(geoip_region_name());
console.log(geoip_latitude());
console.log(geoip_longitude());
console.log(geoip_postal_code());
});
@toast38coza
toast38coza / gist:865750
Created March 11, 2011 11:11
Add a user to mailchimp with django_mailchimp
"""
requirements:
pip install django_mailchimp
"""
import mailchimp
def add_to_list(self,request, list_id, email):
mailinglist = mailchimp.utils.get_connection().get_list_by_id(list_id)
return mailinglist.subscribe(email,{'EMAIL':email}) # True / False