This file contains 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 strings = Array("Foo", "") map { str => | |
Some(str).filter(_ != "").getOrElse("Bar") | |
} | |
strings.foreach(println) |
This file contains 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 timeParser: (String => (String, String)) = { str => | |
val ptn = """^(0?[0-9]|1[0-9]|2[0-3]):(0?[0-9]|[1-5][0-9])$""".r | |
ptn findFirstIn str match { | |
case Some(ptn(h, m)) => ("%02d".format(h.toInt), "%02d".format(m.toInt)) | |
case None => ("--", "--") | |
} | |
} | |
Array("01:23", "1:23", "12:34", "23:60", "25:00") foreach { str => | |
val (hour, min) = timeParser(str) |
This file contains 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 urlMatcher: (String => Option[Map[Symbol, String]]) = { str => | |
val ptn = """^(https?)://([^/]+)(.*)$""".r | |
for { ptn(m1, m2, m3) <- ptn findFirstIn str } yield { | |
Map( | |
'scheme -> m1, | |
'host -> m2, | |
'uri -> m3 | |
) | |
} | |
} |
This file contains 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
import java.util.Date | |
// Use StringLike#format | |
println("%tY-%<tm-%<td %<tH:%<tM:%<tS".format(new Date())) |
This file contains 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
import java.io._ | |
object HexDumper { | |
def main(args: Array[String]) { | |
def withCloseable(args: Array[Closeable])(f: (Array[Closeable]) => Unit) = | |
try f(args) finally args map { _.close } | |
withCloseable( |
This file contains 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 directory=$HOME/.vim/swap | |
set nobackup | |
set number | |
set expandtab | |
set tabstop=2 | |
set softtabstop=2 | |
set shiftwidth=2 | |
"set foldmethod=marker |
This file contains 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
# Unix timestamp | |
% date "+%s" | |
1348029114 | |
% date -d @1348029114 "+%Y-%m-%d %H:%M:%S" | |
2012-09-19 13:31:54 |
This file contains 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
$:.unshift File.dirname(__FILE__) | |
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) # "../lib" |
This file contains 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
PID = /path/to/unicorn.pid | |
all: | |
@echo Usage: (start|stop|restart|graceful) | |
start: | |
@bundle exec unicorn -c config/unicorn.rb -D | |
stop: | |
@[[ -s "$(PID)" ]] && kill -QUIT `cat $(PID)` | |
restart: | |
@[[ -s "$(PID)" ]] && kill -HUP `cat $(PID)` |
This file contains 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
% su - | |
% dd if=/dev/zero of=/swap bs=1M count=2048 | |
% mkswap /swap | |
% swapon /swap | |
% vi /etc/fstab | |
.... | |
/swap swap swap defaults 0 0 |
OlderNewer