Skip to content

Instantly share code, notes, and snippets.

@tky
tky / gist:3220383
Created July 31, 2012 20:47
inverse fizzbuzz
def inverseFizzBuzz(xs: Seq[String]):Int = {
def fizzBuzz: Stream[String] = {
def f(x:Int): Stream[String] = {
def fizz(x: Int) = if (x % 3 == 0) "fizz" else ""
def buzz(x: Int) = if (x % 5 == 0) "buzz" else ""
Stream.cons(fizz(x) + buzz(x), f(x + 1))
}
f(1)
}
fizzBuzz.indexOfSlice(xs) + 1
@tky
tky / gist:2699350
Created May 15, 2012 05:33
nothing.snip
# Specs2
snippet specs2
abbr specs2 snipet
prev_word '^'
import org.specs2.mutable.Specification
import anorm._
import play.api.db.DB
import play.api.Play.current
import org.specs2.mutable._
import play.api.test.Helpers._
@tky
tky / vimrc
Created April 21, 2012 04:44
vimrc
set nocompatible
filetype off
set rtp+=~/.vim/vundle.git/
call vundle#rc()
Bundle 'tpope/vim-fugitive'
Bundle 'neocomplcache'
"required make -f mak_mac.mak
@tky
tky / gist:2204740
Created March 26, 2012 12:21
配列をimageに変換
object ImageUtil {
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.awt.Color
import java.io.{File, FileOutputStream, OutputStream}
def alpha(x: Int): Int = x >>> 24
def red(x: Int): Int = x >> 16 & 0xff
def green(x: Int): Int = x >> 8 & 0xff
def blue(x: Int): Int = x & 0xff
@tky
tky / kansuujiToNumber
Created December 11, 2011 05:30
漢数字をintに変換
val largeDigits = Map('億' -> 100000000, '万' -> 10000)
val digits = Map('千' -> 1000, '百' -> 100, '十' -> 10)
val nums = Map('一' -> 1, '二' -> 2, '三' -> 3, '四' -> 4, '五' -> 5, '六' -> 6, '七' -> 7, '八' -> 8, '九' -> 9)
def slice(xs:String, p:(Char) => Boolean): List[String] = {
if (xs.isEmpty) Nil
else {
val pos = xs indexWhere p
xs splitAt(pos + 1) match {
case ("", y) => List(y)