Skip to content

Instantly share code, notes, and snippets.

@xerial
xerial / Prestobase Connection.ipynb
Last active August 22, 2018 05:56
Interactive Analysis Using Treasure Data Presto and Python
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@xerial
xerial / scala-plot.ipynb
Last active May 3, 2018 04:51
Scala Jupyter Notebook Plot Example
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@xerial
xerial / MapConverter.scala
Created October 8, 2017 16:32
Using Surface to convert objects into Map
import wvlet.surface
import wvlet.surface.Surface
import scala.reflect.runtime.{universe => ru}
class MapConverter[A](surface: Surface) {
def toMap(a: A): Map[String, Any] = {
val m = Map.newBuilder[String, Any]
for (p <- surface.params) {
m += (p.name -> p.get(a))
class MyServic(d1:D1, d2:D2, d3:D3, ...)
val d1 = new D1(....)
val d2 = new D2(....)
val d3 = new D3(....)
val service = new MyService(d1, d2, d3, ...)
@xerial
xerial / README.md
Last active July 20, 2017 22:47
presto-jdbc TD connection example

Presto JDBC Setup

This is how to connect Treasure Data's Presto using Presto JDBC Driver:

  • Download presto-jdbc driver https://prestodb.io/docs/current/installation/jdbc.html
    • For using secure HTTPS (port 443) connection you need to use presto 0.148 or later.
  • Use the following parameters to connect prestobase on development server:
    • Driver name: com.facebook.presto.jdbc.PrestoDriver
    • user: (Your TD API key)
    • password: (can be empty or any string)
  • Connection URL examples:
@xerial
xerial / RequestDispatcher.scala
Last active September 3, 2015 07:32 — forked from seratch/app.scala
AutoRouting idea
import xerial.lens.ObjectSchema
class RequestDispatcher {
// Prepare mappings from a path to ObjectSchema of an WebApp class
private val webAppMapping = {
// ObjectSchema contains a list of methods
for(cl <- webAppClasses; schema <- ObjectSchema.of(cl)) yield {
val basePath = m.findAnnotaionOf[path].map(_.value)getOrElse("/" + schema.name)
basePath -> schema
@xerial
xerial / prestop.rb
Last active April 29, 2016 20:47
prestop.rb
require 'formula'
class Prestop < Formula
homepage 'https://github.com/treasure-data/presto-ops'
head '[email protected]:treasure-data/presto-ops.git', :branch => 'pack', :using => :git
def install
libexec.install Dir['*']
bin.install_symlink "#{libexec}/bin/prestop"
bin.install_symlink "#{libexec}/bin/prestop-shell"
@xerial
xerial / scala-repl.sh
Last active August 29, 2015 14:08
Script for launching Scala REPL
#!/bin/sh
if [ -z "$PROG_HOME" ] ; then
## resolve links - $0 may be a link to PROG_HOME
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
@xerial
xerial / gist:5440968
Last active December 16, 2015 13:19
Extract return type of Function3
def f(a:Int, b:String, c:Int) : Unit = {}
val f3 = f(_, _, _)
for(m <- f3.getClass.getDeclaredMethods.find(m => m.getName == "apply" && !m.isSynthetic)) {
val retType = m.getReturnType
info(s"f3 class: ${f3.getClass.getName}")
info(s"return type of f3: $retType")
}