Skip to content

Instantly share code, notes, and snippets.

View seratch's full-sized avatar

Kazuhiro Sera seratch

View GitHub Profile
1
--------
val list = List("Scala", "http://scala-lang.org", "Java", "http://java.net/", "Haskell", "http://haskell.org/")
list.zipWithIndex.partition(_._2 % 2 == 0).zip.map(a => a._1._1 -> a._2._1)
2
---------
val list = List(1,2,1,3,2,4,4,2,4,3)
list.distinct
@seratch
seratch / gist:1369918
Created November 16, 2011 11:58
#daimonscala 22 My Work
// -----------------
// #daimonscala 22 ハンズオン
// -----------------
// 1. ListからMapをつくろう
val list = List("Scala", "http://scala-lang.org", "Java", "http://java.net/", "Haskell", "http://haskell.org/")
// Map(Scala -> http://scala-lang.org, Java -> http://java.net/, Haskell -> http://haskell.org/)
@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");
@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: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 / 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: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 / 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: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 / 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)