Skip to content

Instantly share code, notes, and snippets.

View mneedham's full-sized avatar

Mark Needham mneedham

View GitHub Profile
@mneedham
mneedham / gist:3803604
Created September 29, 2012 09:53
Script to get upstart out of a start/killed state (http://heh.fi/tmp/workaround-upstart-snafu)
#!/usr/bin/env ruby1.8
class Workaround
def initialize target_pid
@target_pid = target_pid
first_child
end
def first_child
@mneedham
mneedham / SampleSpatialGraph.java
Created March 10, 2013 21:36
neo4j spatial football stadiums
package org.neo4j.gis.spatial;
import org.neo4j.gis.spatial.indexprovider.SpatialIndexProvider;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.index.Index;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import java.io.BufferedReader;
import java.io.FileReader;
@mneedham
mneedham / StadiumsImport.java
Created March 17, 2013 18:30
Code for importing stadiums to the football graph
package main.java;
import org.neo4j.gis.spatial.indexprovider.SpatialIndexProvider;
import org.neo4j.graphdb.DynamicRelationshipType;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.index.Index;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import java.io.BufferedReader;
@mneedham
mneedham / late_goals
Created April 28, 2013 20:49
Trying to recreate OptaJoe stats with a football data set I've collected - https://twitter.com/OptaJoe/status/328549908967743488
START team = node:teams('name:"Manchester City"')
MATCH team-[:played_in]-game-[goal:scored_in]-player-[:played]-playerStats-[:for]-team, playerStats-[:in]-game
WHERE goal.minute > 75
RETURN player.name, game.name, goal.minute, game.home_goals + " - " + game.away_goals AS score, game.friendly_date
ORDER BY game.date, goal.minute
+--------------------------------------------------------------------------------------------------------------------+
| player.name | game.name | goal.minute | score | game.friendly_date |
+--------------------------------------------------------------------------------------------------------------------+
// Initial products
CREATE (dress1 { name: "Halter Dress", colour: "Blue"})-[:BRAND]-(frenchConnection { name: "French Connection" })
CREATE (dress2 { name: "Another Dress", colour: "Yellow"})-[:BRAND]-(frenchConnection)
CREATE (dress3 { name: "Different Dress", colour: "Blue"})-[:BRAND]-(frenchConnection)
RETURN dress1, dress2, dress3
// Query to find the blue French Connection products
START brand = node:node_auto_index(name="French Connection")
MATCH brand<-[:BRAND]-product
WHERE product.colour = "Blue"
@mneedham
mneedham / gist:5823205
Created June 20, 2013 14:28
neo4j spatial withinDistance
@Test
public void testEpic() {
Map<String, String> config = SpatialIndexProvider.SIMPLE_POINT_CONFIG;
IndexManager indexMan = db.index();
Index<Node> index = indexMan.forNodes("geom", config);
Transaction tx = db.beginTx();
Node n1 = db.createNode();
n1.setProperty("lat", 60.1);
n1.setProperty("lon", 15.2);
$ ifconfig -u
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=3<RXCSUM,TXCSUM>
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
...
status: active
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
@mneedham
mneedham / gist:6095019
Created July 27, 2013 14:27
Jersey Client Example
@Test
public void jerseyClientExample() {
Foo foo = new Foo(Client.create());
// some code here to fake the call to google to make it return 200
String result = foo.doSomething();
assertEquals("win", result);
}
@mneedham
mneedham / gist:6095082
Last active December 20, 2015 07:39
Attempt to stub out google call with WebStub
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static com.thoughtworks.webstub.StubServerFacade.newServer;
import static com.thoughtworks.webstub.dsl.builders.ResponseBuilder.response;
import static org.junit.Assert.assertEquals;
@mneedham
mneedham / jersey.java
Created July 27, 2013 15:29
Playing around with a simple stub of a jersey client
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.ClientRequest;
import com.sun.jersey.api.client.ClientResponse;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class RandomTest {
@Test