Skip to content

Instantly share code, notes, and snippets.

View drahot's full-sized avatar
🐤

Tatsuya Hotta drahot

🐤
  • Japan
View GitHub Profile
@drahot
drahot / AlbumsService.kt
Last active September 26, 2016 16:25
Albumを管理するサービスクラス
package jp.co.marginal.demo.model
import android.content.res.Resources
import jp.co.marginal.demo.R
import jp.co.marginal.demo.extension.getResourceIdList
/**
* Albums Service
*/
class AlbumsService(private val resources: Resources) {
@drahot
drahot / TypedArrayExtensions.kt
Last active September 26, 2016 22:32
TypedArrayにResourceId、DrawableのListを返すメソッドを生やす
package jp.co.marginal.demo.extension
import android.content.res.TypedArray
import android.graphics.drawable.Drawable
fun TypedArray.getResourceIdList(defaultValue: Int = 0): List<Int> =
toList{ i -> getResourceId(i, defaultValue) }
fun TypedArray.getDrawableList(): List<Drawable> = toList{ i -> getDrawable(i) }
@drahot
drahot / array.xml
Created September 26, 2016 15:09
アルバム情報を管理するリソースファイル
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer-array name="album_ids">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
@drahot
drahot / trait_use_validator_sample.php
Last active September 21, 2016 15:33
TraitUseValidatorの使用方法
<?php
use App\Utils\TraitUseValidator;
trait HogeTrait {
public function sayHoge() {
return "hogege!";
}
}
@drahot
drahot / TraitUseValidator.php
Last active September 21, 2016 15:16
TraitがUseされているかをチェックするクラス
<?php
namespace App\Util;
/**
* Class TraitUseValidator
* @package App\Util
*/
class TraitUseValidator
{
@drahot
drahot / load_prefectres.scala
Last active September 3, 2016 16:02
HOCON形式の都道府県をScalaで扱う
/**
* Config
*/
private val config = Configuration(ConfigFactory.load())
/**
* 都道府県
*/
lazy private val prefectures: Seq[(String, String)] = {
val list = config.getObjectList("prefectures").getOrElse(new util.ArrayList()).asScala
@drahot
drahot / application_prefecture_sample.conf
Created September 3, 2016 15:46
都道府県を保持するHOCON形式ファイル
# 都道府県
prefectures = [
{ 1 : "北海道" },
{ 2 : "青森県" },
{ 3 : "岩手県" },
{ 4 : "宮城県" },
{ 5 : "秋田県" },
{ 6 : "山形県" },
{ 7 : "福島県" },
{ 8 : "茨城県" },
@drahot
drahot / play_25_file_created_notify.scala
Last active July 4, 2016 04:29
WebSocketによるS3ファイル監視サンプル( PlayFramework2.5.x)
// 30秒おきにS3上に指定ファイルが作成されているかを監視する。
def notifyFileCreated(filename: String) = WebSocket.accept[JsValue, JsValue] { implicit request =>
val path = Seq(S3_ROOT_URL, S3_BUCKET_NAME, filename).mkString("/")
val tick = Source.tick(initialDelay = 0.seconds, interval = 30.seconds, tick = "tick")
val source = tick.map { _ =>
val created = S3Service.ls(path).nonEmpty
Json.toJson(Map("file_created" -> Json.toJson(created)))
}
val sink = Sink.ignore
Flow.fromSinkAndSource(sink, source)
@drahot
drahot / play_24_file_created_notify.scala
Last active July 4, 2016 04:27
WebSocketによるS3ファイル監視サンプル( PlayFramework2.4.x)
// 30秒おきにS3上に指定ファイルが作成されているかを監視する。
def notifyFileCreated(filename: String) = WebSocket.using[JsValue] { implicit request =>
val path = Seq(S3_ROOT_URL, S3_BUCKET_NAME, filename).mkString("/")
val out: Enumerator[JsValue] = Enumerator.generateM(Promise.timeout({
val created = S3Service.ls(path).nonEmpty
Some(Json.toJson(Map("file_created" -> Json.toJson(created))))
}, 30.seconds.toMilli))
(Iteratee.ignore[JsValue], out)
}
@drahot
drahot / 0_reuse_code.js
Created March 20, 2014 03:57
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console