Skip to content

Instantly share code, notes, and snippets.

@mashijp
mashijp / jsonread.scala
Created May 28, 2015 14:24
Scala パーサーコンビネータ で 適当JSONリード
import scala.util.parsing.combinator.JavaTokenParsers
sealed trait JsValue
case class JsString(value: String) extends JsValue
case class JsNumber(value: BigDecimal) extends JsValue
case object JsNull extends JsValue
@mashijp
mashijp / ProvidersController.scala
Last active August 29, 2015 13:55
バリデーションを全部Formのところに追いやった(play framework)
/**
* プロバイダ編集・追加フォーム
*
* @param provider 追加時はNone, 編集時は編集対象を渡す
*/
private def providerForm(provider: Option[Provider] = None) = Form(
mapping(
"name" -> text.verifying(Provider.isValidName _),
"alias" -> text.verifying(Provider.isValidAlias _).verifying("既にこのAliasは使われています", alias => {
withDatabaseSession {
namespace :app do
desc 'アプリケーションの再起動'
task :restart do
on release_roles :app do
fullpath_pidfile_default = "#{current_path}/shared/#{fetch :app_pidfile_default}"
fullpath_pidfile_sub = "#{current_path}/shared/#{fetch :app_pidfile_sub}"
now_running = nil
if test "[ -f #{fullpath_pidfile_default} ]"
now_running = :default
elsif test "[ -f #{fullpath_pidfile_sub} ]"
@mashijp
mashijp / math.coffee
Created April 7, 2013 14:43
hubotの電卓ボット(hubot-irc-runnableの適当改造版)
# Description:
# Allows Hubot to do mathematics.
# https://github.com/jgable/hubot-irc-runnable の改造版
#
# Commands:
# "calc: 1+1" で計算できる
# ACCEPT_ROOMSに入っている部屋ではcalcをつけなくてもOK
module.exports = (robot) ->
ACCEPT_ROOMS = ["example"]
robot.hear /(gcalc|calc|calculate|convert|math)?(:|>)?\s*(.*)\s*/i, (msg) ->