Skip to content

Instantly share code, notes, and snippets.

View toast38coza's full-sized avatar

Christo Crampton toast38coza

View GitHub Profile
@toast38coza
toast38coza / hipchat_speak.py
Created April 9, 2015 14:51
Send a message to a room in hipchat
def speak(message, room):
from requests.packages import urllib3
urllib3.disable_warnings()
token = '...'
url = "https://api.hipchat.com/v2/room/{1}/notification?auth_token={0}" . format (token, room)
requests.post(url, {"message":message})
@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 / 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 / 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 / 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 / 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 / play-audio.swift
Created October 26, 2014 06:28
Play Audio with swift
// requires linked AVFoundation.framework
// don't forget to import AVFoundation at the top of your controller
var player:AVAudioPlayer = AVAudioPlayer()
var error: NSError? = nil
var p1sounds = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("filenamegoeshere", ofType: "mp3")!)
player = AVAudioPlayer(contentsOfURL: p1sounds, error: &error)
player.play()
@toast38coza
toast38coza / call_soap_with_requests.py
Created October 22, 2014 11:17
Call a SOAP Service with plain old requests
import requests
url="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"
#headers = {'content-type': 'application/soap+xml'}
headers = {'content-type': 'text/xml'}
body = """<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://ws.cdyne.com/WeatherWS/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body><ns0:GetWeatherInformation/></ns1:Body>
</SOAP-ENV:Envelope>"""
@toast38coza
toast38coza / parse-data.swift
Created October 20, 2014 06:41
Save a class to parse with swift
## you need to create a bridging header: ParseExample-Bridging-Header.h
## #import <Parse/Parse.h>
Parse.setApplicationId("...", clientKey: "...")
var person = PFObject(className:"Person")
person.setObject("Joe", forKey: "firstname")
person.saveInBackgroundWithBlock{
@toast38coza
toast38coza / tableview.swift
Created October 19, 2014 21:24
Show a list of items in a tableview
// Drag
// Add UITableViewDelegate delegage
// class ViewController: UIViewController, UITableViewDelegate {
let people = ["Jim", "Joe", "Bob", "Jane"]
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return people.count
}