Skip to content

Instantly share code, notes, and snippets.

@shunsugai
shunsugai / event_type_wave_type_stats.sql
Created February 16, 2021 12:06
イベント・潮位別成功率
WITH all_waves AS (
SELECT
CONCAT(
CAST(job_id AS VARCHAR),
'-',
CAST(details.quota_num AS VARCHAR)
) AS wave_id,
job_id,
details.quota_num,
details.event_type.name AS event,
@shunsugai
shunsugai / create_table_for_salmon_run.sql
Created February 16, 2021 11:46
サーモンランの結果をAmazon Athenaで分析するためのCREATE TABLE文
CREATE EXTERNAL TABLE IF NOT EXISTS {your_table_name_here} (
job_score int,
job_result struct<failure_wave: int,
failure_reason: string,
is_clear: boolean
>,
wave_details array<struct<golden_ikura_pop_num: int,
ikura_num: int,
golden_ikura_num: int,
quota_num: int,
@shunsugai
shunsugai / MyAdapter.java
Created July 29, 2012 09:06
AndroidのListViewで非同期で画像を表示する
package com.sugaishun.sample;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import java.util.Locale;
import org.joda.time.DateTime;
import android.content.Context;
@shunsugai
shunsugai / android_gradient.xml
Created August 26, 2012 06:07
Android rich gradient drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- ベースのグラデーション -->
<item android:state_pressed="true">
<shape android:shape="rectangle">
<gradinent
android:angle="270"
android:endColor="#009FD9"
android:startColor="#55CBF6" />
</shape>
z,d=a=%W|ズン ドコ|;s="";until s[z*4+d] do puts c=a.sample;s+=c end;puts "キ・ヨ・シ!"
def zundoko(history = [])
return puts 'キ・ヨ・シ!' if history == ['ズン', 'ズン', 'ズン', 'ズン', 'ドコ']
zundoko(history.last(4) << ['ズン', 'ドコ'].sample.tap { |x| puts x })
end
zundoko
history = []
while history != [0, 0, 0, 0, 1] do
n = rand(2)
history.push(n)
history.shift if history.size > 5
puts n == 0 ? 'ズン' : 'ドコ'
end
puts 'キ・ヨ・シ!'
@shunsugai
shunsugai / lazy_demo.rb
Last active December 15, 2015 00:49
Ruby2.0の新機能、lazyを調査中。
# Benchmark of Enumerable#lazy.
# 'production.log' is a log of Rails application that size is 43.6MB.
require 'benchmark'
Benchmark.bm do |x|
x.report('normal') do
100.times do
File.open("./production.log") do |f|
f.each_line.select { |line| line =~ /RoutingError/ }.first(10)
@shunsugai
shunsugai / inject.rb
Last active December 13, 2015 19:58
たぶんこれでOK
require 'pp'
data = [
{:code => 001, :item => {:name => 'jan'}},
{:code => 001, :item => {:name => 'jan'}},
{:code => 001, :item => {:name => 'aaa'}},
{:code => 002, :item => {:name => 'feb'}},
{:code => 002, :item => {:name => 'aab'}},
{:code => 003, :item => {:name => 'mar'}},
{:code => 003, :item => {:name => 'abb'}},
#かなり雑だけどこんな書き方もできる
class Bar
def initialize(options={})
@options = options
end
def method_missing(name, *args)
if name =~ /=$/
@options[name.to_s.chop.to_sym] = args.first
else