Skip to content

Instantly share code, notes, and snippets.

View seratch's full-sized avatar

Kazuhiro Sera seratch

View GitHub Profile
@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 / 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:1768947
Created February 8, 2012 12:24
type AnyVal cannot be used in a type pattern or isInstanceOf test
scala> "ss".isInstanceOf[Any]
res3: Boolean = true
scala> "ss".isInstanceOf[AnyVal]
<console>:8: error: type AnyVal cannot be used in a type pattern or isInstanceOf test
"ss".isInstanceOf[AnyVal]
^
scala>
@seratch
seratch / build.sbt
Created March 8, 2012 03:06
Using Anorm 2.0 without Play Framework
scalaVersion := "2.9.1"
resolvers += "typesafe" at "http://repo.typesafe.com/typesafe/releases"
libraryDependencies ++= Seq(
"play" %% "anorm" % "2.0-RC4",
"com.github.seratch" %% "scalikejdbc" % "[0.5,)",
"org.hsqldb" % "hsqldb" % "[2,)"
)
@seratch
seratch / ThreadLocalForm.java
Created March 29, 2012 03:41
Working with Jersey's Form objects at outside of Resource classes
package example.threadlocal;
import com.sun.jersey.api.representation.Form;
public class ThreadLocalForm {
private static final ThreadLocal<Form> THREAD_LOCAL = new ThreadLocal<Form>();
public static void set(Form value) {
THREAD_LOCAL.set(value);
@seratch
seratch / MontyHallProblem.scala
Created March 31, 2012 00:55
Monty Hall problem
// http://en.wikipedia.org/wiki/Monty_Hall_problem
// http://d.hatena.ne.jp/hiratara/20120330/1333122309
import scala.util.Random._
case class Door(index: Int, isCar: Boolean)
def chooseDoor(doors: Seq[Door]): Door = doors(nextInt(doors.size))
object MontyHall {
@seratch
seratch / plugins.sbt
Created April 1, 2012 05:34
Play20's project/plugins.sbt for IntelliJ IDEA users
// Comment to get more information during initialization
logLevel := Level.Warn
// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.0")
resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"
@seratch
seratch / dos_64kb_limit.scala
Created April 26, 2012 08:35
java.io.DataOutputStream 64KB limitation
import java.io._
val bao = new ByteArrayOutputStream
val dos = new DataOutputStream(bao)
val chank64kMinus1 = new StringBuilder
val limit = 1024 * 64 - 1
1 to limit foreach { _ => chank64kMinus1.append("a") }
dos.writeUTF(chank64kMinus1.toString)
println(limit + " bytes is acceptable.")
@seratch
seratch / Application.scala
Created April 27, 2012 03:09
ScalikeJDBC Play20 plugin prototype
package controllers
import play.api._
import play.api.mvc._
import scalikejdbc._
object Application extends Controller {
def index = Action {
@seratch
seratch / common_followers.rb
Created May 2, 2012 15:58 — forked from yusuke/common_followers.rb
print common follower screen names of specified twitter accounts
#!/usr/bin/env ruby
require "net/https"
require "uri"
API_BASE_URL = "https://api.twitter.com/1"
def get(url)
uri = URI.parse(url)
https = Net::HTTP.new(uri.host, uri.port)