Skip to content

Instantly share code, notes, and snippets.

View james-prickett's full-sized avatar

James Prickett james-prickett

View GitHub Profile
@james-prickett
james-prickett / gist:1b37ab98afc564eec39e
Created February 24, 2015 16:03
Ruby scripts to create a load balanced cluster on AWS.
#!/usr/bin/env ruby
require 'aws-sdk'
@elb = Aws::ElasticLoadBalancing::Client.new(region: 'us-east-1')
@ec2 = Aws::EC2::Client.new(region: 'us-east-1')
def create_load_balancer
response = @elb.create_load_balancer(
load_balancer_name: "jboss-cluster-lb",
public static void main(String[] args) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance("com.prickettfamily.java.jaxb");
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Person person = (Person)unmarshaller.unmarshal(new File("/home/james/person.xml"));
assert person.getName().equals("John Doe");
assert person.getPhone().equals("555-5555");
assert person.getAddress().getStreet().equals("5 Somewhere Lane");
} catch (JAXBException e) {
e.printStackTrace();
@james-prickett
james-prickett / XmlSlurperExample.groovy
Created June 3, 2014 22:13
Groovy XmlSlurper Example
def person = new XmlSlurper().parse("/home/james/person.xml")
assert person.name == "John Doe"
assert person.phone == "555-5555"
assert person.address[0].street == "5 Somewhere Lane"
assert person.address.find { [email protected]().contains("home") }.street == "5 Somewhere Lane"
<person>
<name>John Doe</name>
<phone>555-5555</phone>
<address type="home">
<street>5 Somewhere Lane</street>
<city>Somewhere</city>
<state>MD</state>
<postalcode>12345</postalCode>
</address><address type="business">
<street>12345 Business Street</street>
@james-prickett
james-prickett / SecuritySpec2.groovy
Created April 1, 2011 17:16
Another security spec
def "Verify View users do not have edit or admin menu options"() {
given: "A view user logs in"
login "viewuser", "password", DashboardPage
when: "The user should be landed on the dashboard"
waitFor { at DashboardPage }
then: "They should not have any edit or admin menu options"
assert $("li", id: "menu-users").size() == 0
assert $("li", id: "menu-admin").size() == 0
@james-prickett
james-prickett / SecuritySpec.groovy
Created April 1, 2011 17:12
Security Specification w/ Spock and Geb
def "Restrict users with the view permission"() {
when: "The user attempts to access an edit page"
login "viewuser", "password", MyReportsPage
then: "The user is shown an error message"
$().text().contains(AUTHORIZATION_ERROR_MSG)
when: "The user attempts to access an admin page"
to AdminPage
@james-prickett
james-prickett / security_utils_test.py
Created March 12, 2011 19:06
simple unit test for the security utils api
import unittest
from utils.security_utils import SecurityUtils
class TestUtils(unittest.TestCase):
def test_security_encode_user_id(self):
id = 154
key = SecurityUtils.encode_user_id(id)
self.assertNotEquals(None, key)
@james-prickett
james-prickett / security_utils.py
Created March 12, 2011 19:01
a simple utility to enccrypt / decrypt user id's
from Crypto.Cipher import AES
import base64
import urllib
class SecurityUtils(object):
key = '^&#$SuP3rCR@zy$t%piDSEcu1+yK3Y$%&#'
mode = AES.MODE_CBC
pad_character = 'X'
@james-prickett
james-prickett / spoc_test.groovy
Created March 6, 2011 18:53
a simple spoc test
import java.io.File;
class HomePageTests extends BaseSpec {
def "Load the home page correctly"() {
when:
go "/"
then:
@james-prickett
james-prickett / imdb_scrapper_test.py
Created March 6, 2011 18:22
A simple unit test for the imdb scrapper
class ImdbServiceTests(unittest.TestCase):
def testGetIdsByPage(self):
service = ImdbService()
movie_ids = service.get_ids_from_page("http://www.imdb.com/chart/top")
self.assertNotEquals(None, movie_ids)
self.assertEquals(250, len(movie_ids))
for id in movie_ids:
self.assertNotEquals(None, id)