Skip to content

Instantly share code, notes, and snippets.

View toast38coza's full-sized avatar

Christo Crampton toast38coza

View GitHub Profile
@toast38coza
toast38coza / unitTestSpringValidationClass
Last active August 29, 2015 13:59
Unit testing a Spring.io Validator class with ValidationContext
@Test
public void testValidateInitialDetailsCapture() {
MyModel myModel = new MyModel();
// setup:
MyModel.setSomeField("Some Value");
// this is the line that stumped me
ValidationContext validationContext = new DefaultValidationContext(requestContext, null, null);
@toast38coza
toast38coza / call_weather_service.py
Created August 29, 2014 08:25
Calling a SOAP WebService with Python Suds
from suds.client import Client
url="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"
client = Client(url)
print client ## shows the details of this service
result = client.service.GetWeatherInformation()
print result ## see: restult.txt below
@toast38coza
toast38coza / MyModelValidatorTest.java
Created September 4, 2014 09:48
Testing a Spring Web Flow validator
@Test
public void testValidateSomeEventId() {
// setup:
// mock request
MockRequestContext requestContext = new MockRequestContext();
// mock message context:
MessageContext messages = requestContext.getMessageContext();
messages.clearMessages();
@toast38coza
toast38coza / helloAngular.html
Created October 11, 2014 14:22
The smallest amount of code to demonstrate the power of AngularJS
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
</head>
<body ng-app="HelloWorldApp" >
<div ng-controller="HelloController" class="container" >
@toast38coza
toast38coza / fetch-image.swift
Created October 19, 2014 19:11
Fetch an image from the web
let url = NSURL(string: "http://www.haskell.org/happy/Happy.gif")
let urlRequest = NSURLRequest(URL: url)
NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue(),
completionHandler: {
response, data, error in
if error != nil {
println("There was an error")
} else {
@toast38coza
toast38coza / save-image.swift
Created October 19, 2014 19:28
Save an image downloaded from the web
let url = NSURL(string: "http://www.haskell.org/happy/Happy.gif")
let urlRequest = NSURLRequest(URL: url)
NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue(),
completionHandler: {
response, data, error in
if error != nil {
println("There was an error")
} else {
@toast38coza
toast38coza / call-json.swift
Created October 19, 2014 19:43
Call a JSON endpoint with swift
let url = NSURL(string: "http://www.telize.com/geoip")
let urlRequest = NSURLRequest(URL: url)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url,
completionHandler: {data, response, error -> Void in
if error != nil {
println("error")
} else {
@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
}
@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 / 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>"""