Skip to content

Instantly share code, notes, and snippets.

View chrisvest's full-sized avatar
🍉

Chris Vest chrisvest

🍉
View GitHub Profile

This is a very simple approach to doing role-based access control with Neo4j. It is optimistic, in the sense that all items are assumed to be world-accessible unless they have specific constraints. Item visibility can be constrained to either individual users or all users who belong to a role. Roles are also hierarchical, so can inherit privileges from other roles.

First, lets create our basic example data:

package org.openjdk.jol.samples;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
import org.openjdk.jol.util.VMSupport;
import static java.lang.System.out;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.concurrent.ThreadLocalRandom;
import org.openjdk.jmh.annotations.Benchmark;
public class MethodHandleBenchmark
{
private static final MethodHandle workHandle = createWorkHandle();
@chrisvest
chrisvest / Finalizer.java
Created July 30, 2014 11:34
The cost of finalizer methods
import org.openjdk.jmh.annotations.Benchmark;
public class Finalizer
{
private static class ObjectWithFinalizer
{
@Override
protected void finalize() throws Throwable
{
super.finalize();
@chrisvest
chrisvest / ThreadLocalWeakRefTest.java
Created July 20, 2014 00:46
ThreadLocals and weak references
import org.junit.Test;
import java.lang.ref.WeakReference;
import static org.junit.Assert.assertNull;
public class ThreadLocalWeakRefTest {
/**
* Many Java web servers and containers go out of their way to find and null
* out ThreadLocals that an application might have created. Question is, is
chris@Minty ~ $ perf stat -d echo 1
1
Performance counter stats for 'echo 1':
0.597512 task-clock # 0.249 CPUs utilized
3 context-switches # 0.005 M/sec
0 cpu-migrations # 0.000 K/sec
176 page-faults # 0.295 M/sec
<not supported> cycles
public static void main(String[] args) {
outer:for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; i++) {
// Optimise the program by checking most likely candidates for
// coercion conflicts first.
boolean foundConflict = false;
for (int x = 1; x < 100; x++) {
// scala> for (x <- 1 until 15)
// yield ((x / 2) ^ (-1 * (x % 2)));
// res21: Seq[Int] =
// Vector(-1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7)
var Functor = ['map'];
var Applicative = ['maps', 'wrap'].concat(Functor);
var Monad = ['mapcat'].concat(Applicative);
var compliment = function (f) {
return function (x) {
return !f(x);
}
}
@chrisvest
chrisvest / BenchmarkSynchronousQueue.java
Created April 14, 2014 18:35
Benchmarking a SynchronousQueue with JMH. Enjoy.
import java.util.concurrent.SynchronousQueue;
import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
import org.openjdk.jmh.annotations.Group;
import org.openjdk.jmh.annotations.GroupThreads;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.logic.Control;
@chrisvest
chrisvest / CodeGenMeta.java
Created March 30, 2014 14:53
Example showing how to generate, compile, load and run Java programs at run-time.
import javax.tools.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;