Skip to content

Instantly share code, notes, and snippets.

@kxbmap
kxbmap / GoodCodeRed.java
Created October 18, 2014 12:05
IDEA 139.69.2 - good code red
package sample;
import java.util.Map;
/**
*
*/
public class GoodCodeRed<V> {
public <K> Map<K, V> test(K k) {
$ scalac sample.scala
sample.scala:14: error: applyDynamic does not support passing a vararg parameter
new Foo().foo(xs:_*).foobar(new Bar().bar)
^
one error found
object Sample {
def unapply(i: Int): Option[String] = Some(i.toString)
def run(): Unit = (0: Short) match {
case Sample(r) => println(r)
}
}
@kxbmap
kxbmap / Main.scala
Last active December 17, 2015 17:49
色んなSQLをSlickで書くと?
import scala.slick.session.Database
import scala.slick.driver.H2Driver.simple._
case class Club(name: String, id: Option[Long] = None)
case class Student(name: String, classroom: String, clubId: Option[Long], id: Option[Long] = None)
trait DAO {
import io.netty.buffer.{Unpooled, ByteBuf}
import java.nio.charset.Charset
object NettyUtil {
implicit class ByteBufOps(val buf: ByteBuf) extends AnyVal {
def getUTF(index: Int): String = {
val length = buf.getUnsignedShort(index)
sliceToString(index + 2, length)
@kxbmap
kxbmap / Option.nut
Created June 28, 2012 16:43
SquirrelでOption
class Option {}
class Some extends Option {
constructor(value) {
this.value = value;
}
function map(f) {
return ::Some(f(value));
}
@kxbmap
kxbmap / 1.scala
Created January 10, 2012 12:30
Scala標準バージョンとScalazバージョン
val ACGT = "ACGT".to[Stream]
@annotation.tailrec
def solve0(n: Int, ss: Stream[List[Char]]): Stream[List[Char]] =
if (n == 0) ss
else solve0(n - 1, ACGT.flatMap(c => ss.map(c :: _)))
def solve(n: Int): Stream[String] =
solve0(n, Stream(Nil)) collect {
case cs if cs.containsSlice("AAG") => cs.mkString
@kxbmap
kxbmap / Sample
Created December 10, 2011 06:22
Scalazのminimum/maximumならOptionが返るから安心
object Sample extends App {
val seq = Seq(1, 2, 3)
val empty = Seq[Int]()
println(seq.max) // -> 3
// println(empty.max) // -> java.lang.UnsupportedOperationException: empty.max
import scalaz._, Scalaz._
package sample.plugin.google
import com.intellij.openapi.actionSystem.{PlatformDataKeys, AnAction, AnActionEvent}
import com.intellij.ide.BrowserUtil
import java.io.UnsupportedEncodingException
import java.net.URLEncoder
import scala.util.control.Exception._
class GoogleSearchAction extends AnAction {
@kxbmap
kxbmap / gist:921241
Created April 15, 2011 06:24
Scala2.8.1でList[java.util.Date].min
scala> trait DateOrdering extends scala.math.Ordering[java.util.Date] {
| def compare(x: java.util.Date, y: java.util.Date) = x.compareTo(y)
| }
defined trait DateOrdering
scala> implicit object Date extends DateOrdering
defined module Date
scala> List(new java.util.Date()).min
res6: java.util.Date = Fri Apr 15 15:16:18 JST 2011