Skip to content

Instantly share code, notes, and snippets.

View seratch's full-sized avatar

Kazuhiro Sera seratch

View GitHub Profile
@seratch
seratch / gist:1768517
Created February 8, 2012 12:02
??? in Scala
scala> ???
scala.NotImplementedError: an implementation is missing
at scala.Predef$.$qmark$qmark$qmark(Predef.scala:233)
at .<init>(<console>:8)
at .<clinit>(<console>)
at .<init>(<console>:11)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
@seratch
seratch / gist:1768483
Created February 8, 2012 11:52
SIP 11 example
$ scala_2.10.0-M1 -Xexperimental
Welcome to Scala version 2.10.0-M1 (Java HotSpot(TM) Client VM, Java 1.6.0_18).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val name = "Martin"
name: String = Martin
scala> val intro = s"My name is $name"
intro: String = My name is Martin
@seratch
seratch / uriunescape.scala
Created January 26, 2012 03:51 — forked from hiratara/uriunescape.scala
@hiratara's first sample of Scala
val uriEscaped = args(0)
def unescapeHexChars(char1: Char, char2: Char): Byte = {
Integer.decode("0x" + char1 + char2).toByte
}
def unescape(str: List[Char]): List[Byte] = {
str match {
case '%' :: x1 :: x2 :: xs => unescapeHexChars(x1, x2) :: unescape(xs)
case x :: xs => x.toByte :: unescape(xs)
@seratch
seratch / gist:1663991
Created January 23, 2012 16:05
Scraping picasaweb example
// libraryDependencies += "org.jsoup" % "jsoup" % "1.6.1"
import org.jsoup._
import java.io._
import java.net.URL
import collection.JavaConversions._
val url = "https://picasaweb.google.com/xxx"
val dir = "downloaded"
@seratch
seratch / gist:1441243
Created December 7, 2011 03:00
Fixing the conflict of org.hamcrest.Matchers and org.mockito.Mathers
package tools;
import static org.mockito.Matchers.*;
/**
* Problem: cannot compile the following code
*
* <pre>
* import static org.hamcrest.Matchers.*;
* import static org.mockito.Matchers.*;
@seratch
seratch / gist:1426936
Created December 3, 2011 11:44
urlencode instant benchmark script
@Grab('commons-codec:commons-codec:1.2')
import org.apache.commons.codec.net.URLCodec;
def input = URLDecoder.decode("http://www.google.co.jp/?q=URLEncoder%E3%81%AF%E3%81%A9%E3%82%8C%E3%81%8F%E3%82%89%E3%81%84%E9%81%85%E3%81%84%E3%81%AE%E3%81%8B%E3%80%81commons-codec%E3%81%A8%E6%AF%94%E8%BC%83%E3%81%97%E3%81%A6%E3%81%BF%E3%81%BE%E3%81%99", "UTF-8")
int times = 1000000;
class Stopwatch {
Integer startTime = null
Integer endTime = null
@seratch
seratch / build.sbt
Created December 1, 2011 06:07
Scala School - Testing with specs2 examples
organization := "net.seratch"
name := "sandbox"
version := "0.1"
scalaVersion := "2.9.1"
libraryDependencies ++= Seq(
"junit" % "junit" % "4.9" withSources(),
@seratch
seratch / gist:1408644
Created November 30, 2011 10:49
myFirstMiddlewareForConnect.js
// #nodejyuku
var connect = require("connect");
// my first middleware
var requestDumper = function() {
return function(req, res, next) {
console.log(req);
next();
};
@seratch
seratch / gist:1404423
Created November 29, 2011 11:04
keyczar_tool.sh
#!/bin/sh -x
# --- KeyczarTool Script ---
# @see http://code.google.com/p/keyczar/wiki/KeyczarTool
wget http://keyczar.googlecode.com/files/KeyczarTool.jar
java -jar ./KeyczarTool.jar create --location=. --purpose=crypt --name="$1"
java -jar ./KeyczarTool.jar addkey --location=. --status=primary
ls # 1 meta
@seratch
seratch / gist:1399369
Created November 28, 2011 06:35
lsync.groovy
@GrabResolver(name='seratch_github_com_releases', root='http://seratch.github.com/mvn-repo/releases', m2Compatible='true')
@Grab('com.github.seratch:httpilot:0.1')
import httpilot.*;
import java.util.*;
formParams = new HashMap<String, Object>();
formParams.put("user", "seratch");
formParams.put("repo", "scalikesolr");
formParams.put("version", "3.5.0");
req = new Request("http://ls.implicit.ly/api/1/libraries");