Skip to content

Instantly share code, notes, and snippets.

View mhgrove's full-sized avatar

Michael Grove mhgrove

View GitHub Profile
@mhgrove
mhgrove / ParseTest.java
Created November 12, 2012 19:00
Sesame SPARQL parser perf regression
package test;
import org.apache.commons.math.stat.descriptive.SummaryStatistics;
import org.openrdf.query.parser.sparql.SPARQLParser;
public class ParseTest {
public static void main(String[] args) throws Exception {
final String q = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
@mhgrove
mhgrove / gist:5013411
Last active December 14, 2015 02:28
A series of snippets of streaming protobuf serialization code, works with protobuf 2.4.1 but not 2.5.0rc1.
// some initialization which takes place in the constructor of the streamed
// protobug message writer
mBytes = new ByteArrayOutputStream((int)(64 * (1 << 10)));
coded = CodedOutputStream.newInstance(mBytes);
// then as protobuf messages come in, i append to the stream
// if the message puts us over the threshold of 64k, we write out what's in
// the buffer and start fresh
private void write(final MessageLite aObj) throws IOException {
@mhgrove
mhgrove / Server2.java
Created August 20, 2013 11:52
Netty HTTP Streaming Bug
// Copyright (c) 2010 - 2013, Clark & Parsia, LLC. <http://www.clarkparsia.com>
// For more information about licensing and copyright of this software, please contact
// inquiries@clarkparsia.com or visit http://stardog.com
package netty;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@mhgrove
mhgrove / LocalEcho.java
Last active December 21, 2015 10:58
Modified LocalEcho class which demonstrates the name collision in LocalAddress
package netty;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
@mhgrove
mhgrove / HttpStaticFileServerHandler.java
Created September 6, 2013 14:11
ByteBufHttpOutputStream
public static final class ByteBufHttpOutputStream extends OutputStream {
/**
* The channel to which the {@link ByteBuf} objects are written
*/
private final ChannelHandlerContext mChannelHandlerContext;
/**
* The {@link ByteBuf} to which data is currently being written
*/
@Override
public void channelRead0(
ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
if (!request.getDecoderResult().isSuccess()) {
sendError(ctx, BAD_REQUEST);
return;
}
if (request.getMethod() != GET) {
sendError(ctx, METHOD_NOT_ALLOWED);
// this is where we'll store our constraints
Sail aConstraints = new MemoryStore();
aConstraints.initialize();
// more specifically, we'll store them in a particular named graph
URI aConstraintGraph = Values.iri("urn:icv");
// and here is our database. note this can be *any* type of Repository
Repository aRepo = new SailRepository(new MemoryStore());
@mhgrove
mhgrove / Function.java
Last active October 8, 2020 06:14
Function
/**
* <p>This is the extension point for 17.6 (Extensible Value Testing) of the SPARQL spec.</p>
*
* <p>For implementations of Function to be visible to the query parser and engine, they must be registered
* via the JDK {@link java.util.ServiceLoader}. Create a file called
* {@code com.complexible.stardog.plan.filter.functions.Function} in the {@code META-INF/services} directory.
* The contents of this file should be all of the *fully-qualified* class names for the custom Functions. Then
* if a jar containing the {@code META-INF/services} directory and the implementations for the Functions is
* included on the classpath, Stardog will pick up the implementations on startup.</p>
*
@mhgrove
mhgrove / gist:9639292
Created March 19, 2014 10:44
CLI output
mhgrove:dist mhgrove$ cat input.nt
<urn:foo> <urn:bar> "literal".
mhgrove:dist mhgrove$ ./bin/stardog-admin db create -n foo -s input.nt
Bulk loading data to new database.
Parsing triples: 100% complete in 00:00:00 (1 triples - 0.2K triples/sec)
Parsing triples finished in 00:00:00.005
Creating index: 100% complete in 00:00:00 (0.2K triples/sec)
Creating index finished in 00:00:00.005
Computing statistics: 100% complete in 00:00:00 (0.2K triples/sec)
Computing statistics finished in 00:00:00.006
@mhgrove
mhgrove / output
Created May 27, 2014 14:30
Describe Console Output
mhgrove:stardog-2.1.3 mhgrove$ ./bin/stardog-admin server start
mhgrove:stardog-2.1.3 mhgrove$ ./bin/stardog-admin db create -n describe
Creating index: 100% complete in 00:00:00 (0.0K triples/sec)
Creating index finished in 00:00:00.010
Loading complete.
Inserted 0 triples in 00:00:00.082 at 0.0 triples/sec
Successfully created database 'describe'.
mhgrove:stardog-2.1.3 mhgrove$ ./bin/stardog data add --named-graph urn:context describe ~/Downloads/census-2011_qs103sc.ttl
Adding data from file: /Users/mhgrove/Downloads/census-2011_qs103sc.ttl