Skip to content

Instantly share code, notes, and snippets.

View davebshow's full-sized avatar

David Michael Brown davebshow

  • Vancouver Island
View GitHub Profile
import json
import time
from TwitterAPI import TwitterAPI
# This is the object that we will use to send the request to Twitter
# A request is a HTTP request, just like your browser does when it goes to a website!
api = TwitterAPI(consumer_key, consumer_secret, access_token_key,
access_token_secret)
"""Simple benchmark based on aiohttp benchmark client.
https://github.com/KeepSafe/aiohttp/blob/master/benchmark/async.py
"""
import argparse
import asyncio
import collections
import random
import aiogremlin
host: localhost
port: 8182
threadPoolWorker: 4
gremlinPool: 16
scriptEvaluationTimeout: 30000
serializedResponseTimeout: 30000
channelizer: com.tinkerpop.gremlin.server.channel.WebSocketChannelizer
graphs: {
g: conf/titan-berkeleydb.properties}
plugins:
@csrf_exempt
def pdf_gen_view(request, graph_slug, template_slug):
def render(request, graph_slug, template_slug):
graph = get_object_or_404(Graph, slug=graph_slug)
template = get_object_or_404(ReportTemplate, slug=template_slug)
queries = template.queries.all()
queries = [{'series': query.execute(headers=True), 'name': query.name,
'id': query.id, 'results': query.query_dict['results']}
for query in queries]
import asyncio
import json
from tornado import escape, gen
from tornado.web import RequestHandler, Application, url
from tornado.platform.asyncio import AsyncIOMainLoop
from gizmo import AsyncGremlinClient
class GremlinHandler(RequestHandler):
CREATE INDEX ON :Author(id);
CREATE INDEX ON :Paper(id);
USING PERIODIC COMMIT
LOAD CSV FROM "file:///home/davebshow/git/projx/data/opsahl-collaboration/out.opsahl-collaboration"
AS line FIELDTERMINATOR " "
MERGE (author:Author {id: line[0]})
MERGE (paper:Paper {id: line[1]})
MERGE (author)-[:WROTE]-(paper);
import json
import pickle
import random
def write_schema(graph, filename):
s = NX2SylvaSchemaConverter(graph)
s.build_schemas(filename)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# Recursive
%timeit parser.parseString('MATCH (c:City)-[l:lives_in]-(p:Person) TRANSFER ATTRS (c)-(p)')
1000 loops, best of 3: 1.7 ms per loop
%timeit parser.parseString('MATCH (p1:Person)-[l1:lives_in]-(c:City)-[l:lives_in]-(p:Person) TRANSFER ATTRS (c)-(p1) PROJECT (p1)-(c)-(p2)')
100 loops, best of 3: 3.22 ms per loop
# Recursive pattern.
%timeit parser.parseString('MATCH (c:City)-[l:lives_in]-(p:Person) TRANSFER ATTRS (c)-(p)')1000 loops, best of 3: 1.58 ms per loop