Skip to content

Instantly share code, notes, and snippets.

View momota10's full-sized avatar
🎯
Focusing

Momota Sasaki momota10

🎯
Focusing
View GitHub Profile
@momota10
momota10 / check.js
Last active August 11, 2021 02:23
jQuery 送信ボタンを押したときに要素が選択されているのかをcheckする。
$(document).on("submit", ".js-admin-edit-form", function(event) {
//ifに引っかかったときの処理
if( $("#hoge-form").val("abc") ){
if($("#category").val() === "" || $("#genre").val() === "") {
alert("カテゴリやジャンルが選択されていません");
return false;
}
}
[~] /usr/libexec/java_home -v 1.8.0 19:48:27
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
[~]
@momota10
momota10 / case.scala
Created November 14, 2015 02:52
[Scala]コレクションを変換する際に使えるtoMapの注意点 ref: http://qiita.com/momotas210/items/1b78954a4d7062e236bc
def testFunction(id: HogeId) = {
for {
hoge <- db.run(hoges.filter(_.id === id).result.headOption)
hugas <- db.run(hugas.filter(_.hogeId === id).result)
} yield (hoge, hugas) match {
case (Some(account), fields) => {
val test_val = fields map { pu =>
(pu.name, pu.alvue)
} toMap;
@momota10
momota10 / zip_join.scala
Created December 10, 2015 13:25
slick(play-slick)3.0を使ったjoinの方法
val q = for {
(user, pao) <- usrs.soft joinLeft paos.soft on (_.id === _.userId)
(pao, pa) <- paos.soft join pas.soft on (_.paId === _.id)
} yield (user, pao, pa)
db.run(q.result) map {
case Seq(data) => Seq(data._1.copy(pa = Some(data._3)))
case _ => Seq()
}
@momota10
momota10 / mutable-filter.scala
Created December 15, 2015 04:53
mutableなlistをfilteringする
def execute(list: Seq[Int] ) = {
for(data <- list) yield cRepository.findById(data) map {
case Some(ca) => ca.status match {
case Stopped => list filterNot (_ == ca.id.get)
case _ => list
}
case None => list
}
Future.successful(list)
}
Future.traverse(list) { listId =>
caRepository.findById(listId) filter {
case Some(c) => c.status match {
case Stopped => false
case _ => true
}
} map { cs =>
cs.get.id.get
}
}
<table id="birthday-table">
<thead>
<tr>
<th>誕生月</th>
<th>誕生日</th>
<th>削除</th>
</tr>
</thead>
<tbody>
<tr id="birthday-setting[0]" >
module.exports = function() {
$(function() {
var num = 0
$('#add-birthday-setting').on('click', function() {
num = parseInt($("#birthday-table tbody tr:last").attr('id').match(/[0-9]/))
var tr = $('#birthday-setting\\['+num+'\\]')
num++
tr.clone(true)
.insertAfter(tr)
@momota10
momota10 / sendEmail.scala
Last active January 18, 2016 09:37
play-mailerを使ったメール送信メソッド
def sendEmail = Action.async { implicit request =>
emailAddressForm.bindFromRequest.fold(
error => {
Future.successful(BadRequest("Your Aoolication"))
},
emailAddress => {
//mail transfer process
val email = Email(
"Simple email",
"title <[email protected]>",
##例外処理
scala> val n = try{"99".toInt} catch {case e:Exception => -99}
n: Int = 99
scala> val n = try{"999".toInt} catch {case e:Exception => -99}
n: Int = 999
scala> val n = try{ "momo".toInt } catch { case e:Exception => -99 }
n: Int = -99