Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Yota takuwan0405

🏠
Working from home
View GitHub Profile
@takuwan0405
takuwan0405 / script
Created Feb 7, 2020
Sql to sum up weekly retention with Firebase Analytics
View script
WITH start AS (
SELECT
user_pseudo_id,
EXTRACT(DATE FROM TIMESTAMP_MICROS(event_timestamp)) AS start_date
FROM
`your.database.events_*`
WHERE
_TABLE_SUFFIX BETWEEN FORMAT_DATE("%Y%m%d", DATE_SUB(DATE_TRUNC(CURRENT_DATE(), WEEK), INTERVAL 5 WEEK)) AND FORMAT_DATE("%Y%m%d", DATE_SUB(DATE_TRUNC(CURRENT_DATE(), WEEK), INTERVAL 1 DAY))
AND event_name = "your event name"
AND EXTRACT(DATE FROM TIMESTAMP_MICROS(event_timestamp)) BETWEEN DATE_SUB(DATE_TRUNC(CURRENT_DATE(), WEEK), INTERVAL 5 WEEK) AND DATE_SUB(DATE_TRUNC(CURRENT_DATE(), WEEK), INTERVAL 1 DAY)
@takuwan0405
takuwan0405 / sample.rule
Last active Feb 10, 2020
Firestore security rule
View sample.rule
service cloud.firestore {
match /databases/{database}/documents {
function isOwn() {
return request.resource.userId == request.auth.uid;
}
function hasTimestamp() {
return request.resource.data.timestamp == request.time;
}
function isCalm() {
return request.time > resource.data.timestamp + duration.value(5, 's');
@takuwan0405
takuwan0405 / GAE directory tree with golang
Last active Feb 28, 2017
GAE directory tree with golang
View GAE directory tree with golang
.
├── readme.md
├── config.toml
└── v1
├── app
│   ├── app-engine.go
│   ├── app.go
│   ├── app.yaml
│   └── queue.yaml
├── app-standalone.go
View GAE sample app.yaml
application: your app id
service: default
version: 1
runtime: go
api_version: go1
default_expiration: "1d"
instance_class: F1
env_variables:
MY_VAR: 'my value'
View RxCounterResult.swift
Started ----
Subscribed
Subscribed
First 0
Second 0
First 1
Second 1
First 2
Second 2
First 3
View RxCounter.swift
// 秒数カウンターを実装。いまは実装内容を深く考えないでください。
func myInterval(interval: NSTimeInterval) -> Observable<Int> {
return Observable.create { observer in
print("Subscribed")
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
let timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue)
var next = 0
dispatch_source_set_timer(timer, 0, UInt64(interval * Double(NSEC_PER_SEC)), 0)
View EventsViewController.swift
import UIKit
import RxSwift
import RxCocoa
/**
Event一覧を表示するViewController
*/
class EventsViewController: UIViewController {
private let viewModel = EventsViewModel()
View RxScheduler.swift
import RxSwift
import RxCocoa
/**
RxSwiftで同期・非同期・並列処理をするためのシングルトン
- main: 同期処理
- serialBackground: 非同期処理
- concurrentBackground: 並列処理
*/
View ViewState.swift
/**
Viewの状態を扱うenum
- .Working: 描画する要素があり、アプリが正常に動いている状態
- .Blank: 描画する要素がない状態
- .Requesting: 描画する要素を読み込んでいる状態
- .Error(ErrorType): エラーが起きている状態
*/
enum ViewState {
case Working
case Blank
View EventsViewModel.swift
import RxSwift
import UIKit
/**
EventsViewControllerの状態を扱うViewModel
- eventModel: Eventに関するデータを扱うモデル
- scheduler: RxSwiftで非同期通信を行うためのシングルトン
- disposeBag: RxSwiftで不要なstreamを削除するためのクラス
- events: Event一覧を格納
You can’t perform that action at this time.