Skip to content

Instantly share code, notes, and snippets.

@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)
@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 / 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: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 / 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 / scala.snippets
Created November 8, 2012 09:46
snippets file for scala
############################
##playframework
#
#play controller
snippet playcon
package ${1:package}
import play.api._
import play.api.mvc._
import play.api.data._
@tky
tky / ltsv
Last active January 4, 2016 02:49
LTSV to json parser. this script parse ltsv file to json string.
package main
// $cat tmp.ltsv
// a:1 b:2
// a:2 b:3 c:v
// $go run ltsv.go tmp.ltsv
// {"a":1,"b":2}
// {"a":2,"b":3, "c":"v"}
import (
"encoding/json"
@tky
tky / ltsv_awk
Created January 22, 2014 12:42
shell which convert ltsv to json.
#!/bin/sh
FILE=$1
cat $FILE | awk -F"\t" '{
printf("{")
for (i = 1; i <= NF; i++) {
pos = index($i, ":")
key = substr($i, 0, pos - 1)
value = substr($i, pos + 1, length($i))
if (value ~ /[0-9]/) {
@tky
tky / gist:8578331
Last active January 4, 2016 05:58
post ltsv.file to elasticsearch. This script read ltsv file and convert json, and post elasticsearch. use go run main.go filename.ltsv
package main
import (
"encoding/json"
"os"
"bufio"
"strings"
"container/list"
"fmt"
"net/http"
!/bin/sh
#$ cat tmp.ltsv
#a:1 b:2
#a:2 b:3 c:4
#$ cat tmp.ltsv | ./filter.sh a
#1
#2
awk -v target="$1" -F'\t' '{
for (i = 1; i <= NF; i++) {
pos = index($i, ":")