Skip to content

Instantly share code, notes, and snippets.

@itang
itang / create_jdk9_runtime.sh
Created February 26, 2016 10:19
create jdk9 runtime image
#!/bin/bash
## hacked for https://github.com/AdoptOpenJDK/jdk9-jigsaw/blob/master/09_JLink/link.sh
set -eu
echo "Removing any existing executable directory"
rm -rf executable
@itang
itang / TestVertxWeb.kt
Created January 29, 2016 09:45
Test Vertx Web
package demo
import io.vertx.core.Vertx
import io.vertx.core.http.HttpServer
import io.vertx.core.http.HttpServerResponse
import io.vertx.ext.web.Route
import io.vertx.ext.web.Router
import io.vertx.ext.web.RoutingContext
fun Router.get(path: String, handler: (RoutingContext) -> Unit): Route {
@itang
itang / listToMap.scala
Created October 24, 2015 06:01
List to Map in Scala
scala> :paste
// Entering paste mode (ctrl-D to finish)
def listToMap[T](list: List[T])(init : Map[T,T] = Map[T,T]()): Map[T,T] = list match {
case Nil => init
case a :: Nil => init
case a :: b :: rest => listToMap(rest)( init + (a -> b))
}
// Exiting paste mode, now interpreting.
@itang
itang / Option.elm
Created October 21, 2015 03:39
Option for Elm lang
module Option where
type Option a = None | Some a
getOrElse : Option a -> a -> a
getOrElse o e =
case o of
None -> e
Some a -> a
@itang
itang / Main.java
Last active September 10, 2015 06:15
Parallel Stream
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.concurrent.TimeUnit;
public class Main {
public static void main(String[] args) {
time(() -> {
List<String> strs = Arrays.asList("hello", "world", "google");
@itang
itang / tap_when.ex
Created August 31, 2015 09:33
tap when
defmodule A do
def tap_when(target, c, f) do
if c do
IO.puts "yes"
f.(target)
else
IO.puts "no"
target
end
end
@itang
itang / crystal_shell.cr
Created August 13, 2015 09:07
Crystal as Shell
#!/usr/bin/env crystal
puts "hello, world"
@itang
itang / crystal_macro_reflect.cr
Created August 10, 2015 11:29
Test Crystal macro reflect
macro new_instance(clazz, args)
{{clazz.id}}.new({{*args}})
end
module Util
class A
getter msg
def initialize(@msg)
@itang
itang / open_class.cr
Created August 7, 2015 02:15
Crystal: Open class for nil
class Object
def hello
puts "hello"
end
def to (&block)
yield self if self
end
end
@itang
itang / test_csv.ex
Last active August 29, 2015 14:25
test csv in Elixir
ret =
File.stream!("GeoID.csv")
|> CSV.decode(separator: ?,)
|> Enum.map(fn row -> row |> Enum.map &String.upcase/1 end)
ret
|> tl
|> Enum.each fn row ->
{t1, t2, t3, t4, t5, t6, _} = List.to_tuple row
IO.puts t5