This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set nocompatible | |
filetype off | |
set rtp+=~/.vim/vundle.git/ | |
call vundle#rc() | |
Bundle 'tpope/vim-fugitive' | |
Bundle 'neocomplcache' | |
"required make -f mak_mac.mak |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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._ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################ | |
##playframework | |
# | |
#play controller | |
snippet playcon | |
package ${1:package} | |
import play.api._ | |
import play.api.mvc._ | |
import play.api.data._ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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]/) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"os" | |
"bufio" | |
"strings" | |
"container/list" | |
"fmt" | |
"net/http" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!/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, ":") |
OlderNewer