Skip to content

Instantly share code, notes, and snippets.

@shinobu-aoki
shinobu-aoki / avhash.scala
Created August 3, 2012 14:00
Average HashをScalaで書いてみた
import java.awt.image.{BufferedImage => BI}
import java.io.File
import javax.imageio.ImageIO
object avhash extends App {
val (w, h) = (16, 16)
def toHash(originFile: File) = {
def toGray(originFile: File) = {
val newImage = new BI(w, h, BI.TYPE_BYTE_GRAY)
val g = newImage.createGraphics()
@shinobu-aoki
shinobu-aoki / Global.scala
Created April 2, 2012 07:10
GlobalSettingsとAkkaを使ってplay 2.0でJob(Actor)を定期実行する
import play.api._
import play.api.libs.concurrent.Akka
import akka.actor._
import akka.util.duration._
object Global extends GlobalSettings {
case class LogMessage()
class DateActor extends Actor {
def receive = {
@shinobu-aoki
shinobu-aoki / urlToInput.scala
Created March 7, 2012 12:16
scala-ioのURLからの読込でUser-Agentを設定するimplicit conversion
import java.net.URL
import scalax.io.{CloseAction, InputStreamResource, KnownName}
import scalax.io.JavaConverters.AsInput
// User-Agentを設定するimplicit conversion
object URLConverter {
implicit def asInputConverter(url: URL)(implicit userAgent: UserAgent) =
new AsInput(new InputStreamResource({
val conn = url.openConnection
conn.setRequestProperty("User-Agent", userAgent.ua)
@shinobu-aoki
shinobu-aoki / BootstrapHelper.scala
Created March 2, 2012 19:17
Play2.0でBootstrap2.0
package views
import views.html.bootstrapField
import views.html.helper.FieldConstructor
object BootstrapHelper {
implicit val bootstrapConstructor = FieldConstructor(bootstrapField.f)
}
@shinobu-aoki
shinobu-aoki / FinalVal.java
Created February 9, 2012 15:34
scalaのfinal valをコンパイルしてJava Decompilerで逆コンパイルしてみた
// finalVal.scalaをscalacしてJava Decompilerで逆コンパイルした結果
// http://java.decompiler.free.fr/
import scala.ScalaObject;
import scala.collection.mutable.StringBuilder;
import scala.reflect.ScalaSignature;
@ScalaSignature(bytes="\006\001e2A!\001\002\001\013\tAa)\0338bYZ\013GNC\001\004\003\035aT-\0349usz\032\001aE\002\001\r9\001\"a\002\007\016\003!Q!!\003\006\002\t1\fgn\032\006\002\027\005!!.\031<b\023\ti\001B\001\004PE*,7\r\036\t\003\037Ii\021\001\005\006\002#\005)1oY1mC&\0211\003\005\002\f'\016\fG.Y(cU\026\034G\017C\003\026\001\021\005a#\001\004=S:LGO\020\013\002/A\021\001\004A\007\002\005!9!\004\001b\001\n\013Y\022A\0014w+\005ar\"A\017\"\003y\tA!\0312dI\"1\001\005\001Q\001\016q\t1A\032<!\021\035\021\003A1A\005\002\r\n!A^\031\026\003\021\002\"aB\023\n\005\031B!AB*ue&tw\r\003\004)\001\001\006I\001J\001\004mF\002\003b\002\026\001\005\004%\taI\001\003mJBa\001\f\001!\002\023!\023a\001<3A!9a\006\001b\001\n\003\031\023A\001<4\021\031\001\004\001)A\005I\005\031ao\r\021\t\017I\002!\031!C\001G\005\021a\017\016\005\007i\001
@shinobu-aoki
shinobu-aoki / ShowaFilterFactory.java
Created September 1, 2011 17:13
RTLのテキストを処理するSolr用CharFilterです
package analysis;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.util.LinkedList;
import org.apache.lucene.analysis.BaseCharFilter;
import org.apache.lucene.analysis.CharReader;
import org.apache.lucene.analysis.CharStream;