Skip to content

Instantly share code, notes, and snippets.

View toast38coza's full-sized avatar

Christo Crampton toast38coza

View GitHub Profile
@toast38coza
toast38coza / ansible_stdout.yml
Created February 25, 2014 08:46
Get the stdout response from an ansible task. From: https://gist.github.com/toast38coza/6bdd151eae2ee9d751a7
- name: print to stdout
command: echo "hello"
register: hello
- debug: msg="{{ hello.stdout }}"
- debug: msg="{{ hello.stderr }}"
@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 / 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 / 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()