Skip to content

Instantly share code, notes, and snippets.

View maxdemarzi's full-sized avatar
🏠
Working from home

Max De Marzi maxdemarzi

🏠
Working from home
View GitHub Profile
@maxdemarzi
maxdemarzi / MyService.java
Created March 23, 2014 05:49
NeoLove Service in Java
package org.neo4j.example.unmanagedextension;
import org.codehaus.jackson.map.ObjectMapper;
import org.neo4j.cypher.javacompat.ExecutionEngine;
import org.neo4j.cypher.javacompat.ExecutionResult;
import org.neo4j.graphdb.*;
import org.neo4j.helpers.collection.IteratorUtil;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@maxdemarzi
maxdemarzi / MyService.java
Created March 23, 2014 16:19
Neo Loves Caching
package org.neo4j.example.unmanagedextension;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import org.codehaus.jackson.map.ObjectMapper;
import org.neo4j.graphdb.*;
import org.neo4j.helpers.collection.IteratorUtil;
import javax.ws.rs.GET;
@maxdemarzi
maxdemarzi / pipeline_test.rb
Created April 11, 2014 15:06
Can't get more than 6000 r/s
require 'net/http/pipeline'
def runit
Net::HTTP.start 'localhost', 7474 do |http|
http.pipelining = true
reqs = []
6000.times do
@maxdemarzi
maxdemarzi / MutableInt.java
Created April 16, 2014 03:54
Mutable Int
/**
* Private inner class for sorting.
*
* @author dany
*/
public final class MutableInt implements Comparable<MutableInt> {
public int value = 0;
public MutableInt(int value) {
this.value = value;
import org.neo4j.graphdb.Node;
import java.util.Comparator;
import java.util.Map;
/**
* @author mh
* @since 16.03.14
*/
public class MutableIntEntryComparator implements Comparator<Map.Entry<Node, MutableInt>> {
@maxdemarzi
maxdemarzi / Rakefile
Last active August 29, 2015 14:15
Neo4j In Production Rake script
require 'net/http'
require 'uri'
# Set Java Home
unless ENV["JAVA_HOME"]
puts "You need to set your JAVA_HOME environment variable by running:"
javahome = `/usr/libexec/java_home`
command = "export JAVA_HOME=\"" + javahome.strip + "\""
puts command
end
@maxdemarzi
maxdemarzi / CreateNode.scala
Created March 9, 2015 17:27
Peak Transactions is 64 on my MBP
import io.gatling.core.Predef._
import io.gatling.core.scenario.Simulation
import io.gatling.http.Predef._
import scala.concurrent.duration._
class CreateNode extends Simulation {
val httpConf = http
.baseURL("http://localhost:7474")
int i = 0;
Transaction tx = db.beginTx();
try {
for ( Relationship relationship : GlobalGraphOperations.at(db).getAllRelationships()) {
// Do some work on relationship property
i++;
// Commit every x transactions
if (i % 10000 == 0) {
tx.success();
tx.close();
@maxdemarzi
maxdemarzi / dothis.java
Created September 4, 2015 15:57
string to millis
private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
int i = 0;
Transaction tx = db.beginTx();
try {
for ( Node node : GlobalGraphOperations.at(db).getAllNodes()) {
Date theDate = DATE_FORMAT.parse((String)node.getProperty("my_date_as_string_property", "2099-12-31 12:00:00"));
node.setProperty("new_date_as_millis", theDate.getTime());
i++;
// Commit every x transactions
if (i % 10000 == 0) {
@maxdemarzi
maxdemarzi / LockDownSecurityRule.java
Created September 3, 2014 18:03
Example Neo4j Security Rule
package org.neo4j.server.rest.security;
import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.DatatypeConverter;
import java.util.StringTokenizer;
import java.io.UnsupportedEncodingException;
public class LockDownSecurityRule implements SecurityRule {
public static final String REALM = "WallyWorld"; // as per RFC2617 :-);