Skip to content

Instantly share code, notes, and snippets.

View mocyuto's full-sized avatar
🏠
Working from home

Yuto Suzuki mocyuto

🏠
Working from home
View GitHub Profile
@mocyuto
mocyuto / beans.xml
Last active December 17, 2015 18:39
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
import scala.collection.par._
import scala.collection.par.Scheduler.Implicits.global
object iterate {
def triangles_blitz(n: Int) = for {
x <- (0 until n).toPar
y <- 0 until x
} yield { y }: @unchecked
def triangles(n: Int) = for {
@mocyuto
mocyuto / sql2case.py
Last active August 29, 2015 14:06
SQLをcase classに変換
# -*- coding:utf-8 -*-
import re
import sys
def to_camel_case(snake_str):
components = snake_str.split('_')
return components[0] + "".join(x.title() for x in components[1:])
def caseClass(list):
for i,elem in enumerate(list[0]):
@mocyuto
mocyuto / update.scala
Created October 9, 2014 15:31
update を普通に実装した場合
case class Coffees(id: Int, name: String, supId:Int, price: Double)
class CoffeesTable(tag: Tag) extends Table[(String, Int, Double, Int, Int)](tag, "coffees") {
def id = column[Int]("COF_NAME", O.PrimaryKey)
def name = column[String]("name")
def supID = column[Int]("SUP_ID")
def price = column[Double]("PRICE")
def * = (id, name, supID, price) <> (Coffees.tupled, Coffees.unapply)
// A reified foreign key relation that can be navigated to create a join
}
@mocyuto
mocyuto / update2.scala
Created October 9, 2014 15:56
updateでcase classの値が埋まっているところのみ更新
case class Coffees(id: Int, name: String, supId:Option[Int], price: Option[Double])
class CoffeesTable(tag: Tag) extends Table[(String, Int, Double, Int, Int)](tag, "coffees") {
def id = column[Int]("COF_NAME", O.PrimaryKey)
def name = column[String]("name")
def supID = column[Int]("SUP_ID")
def price = column[Double]("PRICE")
def * = (id, name, supID, price) <> (Coffees.tupled, Coffees.unapply)
}
@mocyuto
mocyuto / DBConnection.scala
Last active August 29, 2015 14:10
slickでcommons-dbcpを使う場合の書き方
package com.cyberz.foxapi.util
import javax.sql.DataSource
import com.typesafe.config.ConfigFactory
import org.apache.commons.dbcp.BasicDataSource
import scala.slick.jdbc.JdbcBackend.Database
/**
@mocyuto
mocyuto / application.conf
Created November 22, 2014 00:28
confファイル
db {
driver = "com.mysql.jdbc.Driver"
salt = "xxxxxx"
max-active = 10
max-idle = 5
max-wait = 5000
initial-size = 1
validation-query = "SELECT 1"
test-on-borrow = true
time-between-evection-runs-mills = 30000
@mocyuto
mocyuto / sshDao.scala
Created December 27, 2014 00:25
ssh-scalaで画像をscpするコード
import java.io.File
import com.decodified.scalassh._
import com.typesafe.config.ConfigFactory
import org.slf4j.LoggerFactory
import spray.http.StatusCodes
import scala.io.Source
/**
* Created by Yuto Suzuki on 2014/12/24.
*/
object SshDao {
@mocyuto
mocyuto / dbTest.py
Last active August 29, 2015 14:14
MySQLとinfluxDBの比較スクリプト
# coding: utf-8
import doctest
import MySQLdb
from influxdb import InfluxDBClient as ifdb
from datetime import datetime
DATA = "123456789012345678901234567890123456789012345678901234567890"
COUNT = 10000 * 1
@mocyuto
mocyuto / IconGetter.scala
Created February 15, 2015 01:25
GooglePlayからIcon画像のURLを引っ張ってくる
def googlePlayIconUrl(appIdentifier: String): Option[String] = {
val googleImgTag = "div.cover-container img.cover-image"
def googlePlayUrl(appIdentifier: String): String = s"https://play.google.com/store/apps/details?id=$appIdentifier"
try {
val doc = Jsoup.connect(googlePlayUrl(appIdentifier)).get
Option(doc.select(googleImgTag).first.attr("src"))
} catch {
case e: HttpStatusException => {
// loggerに関しては、適当なものを定義してください。
logger.error(s"GooglePlayにアクセスできません。$appIdentifier")