Skip to content

Instantly share code, notes, and snippets.

@espeed
espeed / device_test.py
Created October 20, 2011 19:33
Python ZeroMQ Streamer Client & Worker
import os
import time
import zmq
from zmq.devices.basedevice import ProcessDevice
from multiprocessing import Process
from device import Streamer, create_socket
in_port = 6000
out_port = 6001
number_of_workers = 1
@espeed
espeed / device_test.py
Created October 20, 2011 20:00
PyZMQ Streamer Tester
# Note, added LINGER -1 to all sockets.
# See UPDATE comment below...
import zmq
from zmq.devices.basedevice import ProcessDevice
from multiprocessing import Process
import time
in_port = 6000
out_port = 6001
python try.py
CONTENT TYPE application/json
HEADERS {'Content-Type': 'application/json', 'Accept': 'application/json'}
POST url: http://localhost:8182/graphs/tinkergraph/tp/gremlin
POST body: {"script": "g.setMaxBufferSize(0);g.startTransaction();g.V;tx.stopTransaction(TransactionalGraph.Conclusion.SUCCESS)"}
SystemError: ({'status': '500', 'transfer-encoding': 'chunked', 'server': 'grizzly/2.1.1', 'connection': 'close', 'date': 'Sat, 12 Nov 2011 19:06:33 GMT', 'access-control-allow-origin': '*', 'content-type': 'application/json'}, '{"message":"","error":"javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: groovy.lang.MissingMethodException.setMaxBufferSize() is applicable for argument types: () values: []","api":{"description":"evaluate an ad-hoc Gremlin script for a graph.","parameters":{"rexster.returnKeys":"an array of element property keys to return (default is to return all element properties)","rexster.showTypes":"displays the properties of the elements with
@espeed
espeed / json_example.groovy
Created November 12, 2011 21:30
Groovy JSON Example
#!/usr/bin/env groovy
import groovy.json.JsonSlurper
def slurper = new JsonSlurper()
def payload = '{"age": 34, "name": "james"}'
def data = slurper.parseText(payload)
println data
@espeed
espeed / config.py
Created November 14, 2011 09:29
Bulbs 0.3 Config File
# -*- coding: utf-8 -*-
#
# Copyright 2011 James Thornton (http://jamesthornton.com)
# BSD License (see LICENSE for details)
#
class Config(object):
def __init__(self,root_uri,username=None,password=None):
self.root_uri = root_uri
@espeed
espeed / whybase.py
Created November 14, 2011 09:35
Example Bulbs 0.3 Domain Object
from bulbs.graph import Graph
from bulbs.config import Config
from bulbs.element import Vertex, Edge
from bulbs.proxy import VertexProxy, EdgeProxy, IndexProxy
from bulbs.model import Node, NodeProxy
from bulbs.gremlin import Gremlin
# Bulbs 0.3 has pluggable resources -- there is a Neo4j Server Resource as well
from bulbs.resources import RexsterResource, RexsterIndex
@espeed
espeed / gremlin.yaml
Created November 14, 2011 15:20
Gremlin Library: YAML
save_graphml: |
g.saveGraphML('data/graphml')
new File('data/graphml').getText()
load_graphml: |
g.loadGraphML($uri)
get_all_vertices: |
g.V
@espeed
espeed / gremlin.py
Created November 20, 2011 21:18
Bulbs 0.3 gremlin.py
# -*- coding: utf-8 -*-
#
# Copyright 2011 James Thornton (http://jamesthornton.com)
# BSD License (see LICENSE for details)
#
"""
An interface for executing Gremlin scripts on the resource.
"""
import os
@espeed
espeed / gremlin.yaml
Created November 20, 2011 21:19
Bulbs 0.3 gremlin.yaml
#
# Copyright 2011 James Thornton (http://jamesthornton.com)
# BSD License (see LICENSE for details)
#
# Gremlin scripts in Gremlin-Groovy v1.3
#
# Each script is a string literal of a Python string template.
#
# See the Gremlin and Blueprints docs for the full Gremlin/Blueprints API.
#
@espeed
espeed / index.groovy
Created November 23, 2011 05:50
Gremlin Overloaded Index Put Method to Accept Map and JSON
import java.util.Map.Entry;
import groovy.json.JsonSlurper;
com.tinkerpop.blueprints.pgm.impls.tg.TinkerIndex.metaClass.put = {
final Map<String, Object> properties, final Element element ->
for (final Entry<String, Object> entry: properties.entrySet()) {
put(entry.getKey(), entry.getValue(), element);
}
}