Skip to content

Instantly share code, notes, and snippets.

View electrum's full-sized avatar
🚀
Working on @trinodb and @starburstdata

David Phillips electrum

🚀
Working on @trinodb and @starburstdata
View GitHub Profile
@electrum
electrum / protocol.md
Last active November 14, 2017 15:59
Presto protocol enhancements

The current protocol uses HTTP headers for many things including session parameters, session properties, transaction info, prepared statements, etc. This is problematic for prepared statements due to length limitations on HTTP headers in various clients and servers. It is also makes the protocol harder to following by mixing things across headers and the request / response bodies.

As long as we're changing the protocol, it makes sense to move everything from headers into the JSON documents. We will add a new endpoint, /v2/statement, that accepts application/json with the new request body (instead of just the query text). The new endpoint will return the new response format.

@electrum
electrum / Collections.java
Created November 16, 2016 00:24
Java sorted()
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import static java.util.Comparator.naturalOrder;
public final class Collections
{
private Collections() {}
@electrum
electrum / args.py
Last active November 3, 2016 18:11
Bash variable expansion
#!/usr/bin/env python
import sys
print '%s: %s' % (len(sys.argv) - 1, sys.argv[1:])
@electrum
electrum / snake.asm
Created November 3, 2016 00:05
Snake game for the TI-86 graphing calculator
; Snake 86 by David Phillips <david@acz.org>
; for the TI-86 graphing calculator
; written on January 28, 2000
#include "ti86asm.inc"
VideoRam = $fc00
SnakeBody = $9000
.org _asm_exec_ram
@electrum
electrum / Test.java
Created September 7, 2016 15:47
Java String.getBytes() with Charset
import java.nio.charset.Charset;
import java.util.Arrays;
public final class StringBytes
{
public static void main(String[] args)
{
bytes(Charset.forName("ASCII"));
bytes(Charset.forName("UTF-8"));
bytes(Charset.forName("UTF-16"));
import com.google.common.cache.CacheLoader;
public final class CacheLoaderUtil
{
private CacheLoaderUtil() {}
public static <K, V> CacheLoader<K, V> cacheLoader(LoaderFunction<K, V> loader)
{
return new CacheLoader<K, V>()
{
@electrum
electrum / ObjectBinding.java
Created October 30, 2015 23:49
JDBI ObjectBinder
public interface ObjectBinder<T>
{
void bind(SQLStatement<?> query, T value);
}
@BindingAnnotation(BindObjectFactory.class)
@Retention(RUNTIME)
@Target(PARAMETER)
public @interface BindObject
{
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>example</artifactId>
<version>1.0</version>
<properties>
<dep.swift.version>0.15.1</dep.swift.version>
@electrum
electrum / interrupt.txt
Last active August 29, 2015 14:27
Thread.interrupt() hang in NIO FileChannel.force()
"20150819_160255_05306_partm.1.23-5-12509" #12509 prio=5 os_prio=0 tid=0x00007f7f10063000 nid=0x3e67a in Object.wait() [0x00007f7d58126000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at sun.nio.ch.NativeThreadSet.signalAndWait(NativeThreadSet.java:101)
- locked <0x00007f86336b5540> (a sun.nio.ch.NativeThreadSet)
at sun.nio.ch.FileChannelImpl.implCloseChannel(FileChannelImpl.java:129)
at java.nio.channels.spi.AbstractInterruptibleChannel$1.interrupt(AbstractInterruptibleChannel.java:165)
- locked <0x00007f86336b5560> (a java.lang.Object)
at java.lang.Thread.interrupt(Thread.java:919)
- locked <0x00007f86c01a91e0> (a java.lang.Object)
import com.sun.management.ThreadMXBean;
import java.lang.management.ManagementFactory;
import java.util.Arrays;
public final class ThreadMemory
{
public static void main(String[] args)
{
ThreadMXBean threadMXBean = (ThreadMXBean) ManagementFactory.getThreadMXBean();