Skip to content

Instantly share code, notes, and snippets.

Avatar

Tsukasa Kitachi kxbmap

  • Japan
View GitHub Profile
@kxbmap
kxbmap / GoodCodeRed.java
Created Oct 18, 2014
IDEA 139.69.2 - good code red
View GoodCodeRed.java
package sample;
import java.util.Map;
/**
*
*/
public class GoodCodeRed<V> {
public <K> Map<K, V> test(K k) {
View sample.scala
$ 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
View Sample.scala
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 Dec 17, 2015
色んなSQLをSlickで書くと?
View Main.scala
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 {
View NettyUtil.scala
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 Jun 28, 2012
SquirrelでOption
View Option.nut
class Option {}
class Some extends Option {
constructor(value) {
this.value = value;
}
function map(f) {
return ::Some(f(value));
}
@kxbmap
kxbmap / 1.scala
Created Jan 10, 2012
Scala標準バージョンとScalazバージョン
View 1.scala
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 Dec 10, 2011
Scalazのminimum/maximumならOptionが返るから安心
View Sample
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._
View GoogleSearchAction.scala
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 Apr 15, 2011
Scala2.8.1でList[java.util.Date].min
View gist:921241
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
You can’t perform that action at this time.