Skip to content

Instantly share code, notes, and snippets.

View noctarius's full-sized avatar

noctarius aka Christoph Engelbert noctarius

View GitHub Profile
import java.io.*;
import javax.script.*;
import org.python.core.PySystemState;
import org.python.core.PyString;
import org.python.util.PythonInterpreter;
/**
* This class executes the AsciiDoc python scripts (asciidoc.py and a2x.py) from
* Java using the Jython interpreter.
*
import java.io.*;
import javax.script.*;
import org.python.core.PySystemState;
import org.python.core.PyString;
import org.python.util.PythonInterpreter;
/**
* This class executes the AsciiDoc python scripts (asciidoc.py and a2x.py) from
* Java using the Jython interpreter.
*
@noctarius
noctarius / gist:fac5675bf7ea431bc44e
Last active August 29, 2015 14:06 — forked from forax/gist:0c25deac1867d1ef3247
Dynamic Class Mapping on Method Handles
import java.lang.invoke.CallSite;
import java.lang.invoke.ConstantCallSite;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
MacBook-Pro:cc-arm-none-eabi noctarius$ ls -la
total 32
drwxr-xr-x 5 noctarius staff 170 Nov 8 13:48 .
drwxr-xr-x 145 noctarius staff 4930 Nov 7 10:03 ..
drwxr-xr-x 14 noctarius staff 476 Nov 8 13:26 .git
-rw-r--r-- 1 noctarius staff 20 Nov 7 10:04 .gitignore
-rwxr-xr-x 1 noctarius staff 10732 Nov 8 13:48 toolchain-build.sh
MacBook-Pro:cc-arm-none-eabi noctarius$ ./toolchain-build.sh
Checking for necessary tools...
Checking for 'git'... success.
StreamWriter streamWriter = StreamWriter.newBuilder().build();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamGraphBuilder graphBuilder = streamWriter.newStreamGraphBuilder(Output.toOutputStream(baos));
graphBuilder.putNumber(100).putNumber(101).putNumber(102).putNumber(103).putNumber(104).finishStream();
Parser parser = Parser.newBuilder().build();
Input input = Input.fromByteArray(baos.toByteArray());
// Dictionary, inner dictionary, inner sequence
@Test
public void test_exception_flow_control() {
Calendar calendar = Calendar.getInstance();
calendar.set(2003, 11, 13, 18, 30, 02);
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
calendar.set(Calendar.MILLISECOND, 250);
Instant expected = calendar.toInstant();
ZoneId UTC = ZoneId.of("UTC");
DateTimeFormatter fractionFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.US);
@noctarius
noctarius / EvenOrOdd.js
Created December 29, 2016 16:33
I had the feeling I finally need to solve this issue! :)
// Found this awesome way in Java code once and had
// the strong feeling I need to port it to Javascript
// for the sake of all NodeJS developers!
var EvenOrOdd = function() {
function EvenOrOdd() {}
EvenOrOdd.prototype.isEven = function(value) {
var even = "02468";
var v = String(value);
var w = v.charAt(v.length - 1);
return even.indexOf(w) != -1;
java:
import io.vertx.core.*;
import io.vertx.core.http.*;
import io.vertx.core.shareddata.AsyncMap;
import io.vertx.core.spi.cluster.ClusterManager;
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager;
import java.util.Optional;
import java.util.function.Consumer;
Parser parser = Parser.newBuilder().build();
// extracts id into mid, internalDate into date, payload/headers into headers, returns the new object
// Query query = "(mid: #{'id'}, date: #{'internalDate'}, headers: #{'payload'}{'headers'})";
// alternative version to define it
Query query = parser.newQueryBuilder().asDictionary()
.putEntry("mid").stream(0).dictionary("id").endEntry()
.putEntry("date").stream(0).dictionary("internalDate").endEntry()
.putEntry("headers").stream(0).dictionary("payload").dictionary("headers").endEntry()
Dictionary [
ByteString{ historyId }=UInt{ 5060033 },
ByteString{ id }=ByteString{ 14dc2de0074cc817 },
ByteString{ internalDate }=UInt{ 1433493436000 },
ByteString{ labelIds }=Sequence [
ByteString{ INBOX },
ByteString{ IMPORTANT },
ByteString{ CATEGORY_FORUMS }
],
ByteString{ payload }=Dictionary [