Skip to content

Instantly share code, notes, and snippets.

View oogatta's full-sized avatar

Naohiro Oogata oogatta

  • Otaru, Hokkaido, Japan
  • 01:06 (UTC +09:00)
View GitHub Profile
@oogatta
oogatta / subscribe.kt
Created June 5, 2017 14:38
RxKotlin's subscribe
@CheckReturnValue
@SchedulerSupport("none")
public final Disposable subscribe(Consumer<? super T> onNext) {
return this.subscribe(onNext, Functions.ON_ERROR_MISSING, Functions.EMPTY_ACTION, Functions.emptyConsumer());
}
@oogatta
oogatta / use_rxkotlin_subscribe.kt
Last active June 5, 2017 14:41
use RxKotlin's subscribe
RxView.clicks(cancel_button).subscribe { println("clicked!") }
@oogatta
oogatta / use_rxswift_subscribe.swift
Last active June 5, 2017 14:43
Use RxSwift's subscribe
cancelButton.rx.tap.subscribe(onNext: { print("yes!") })
@oogatta
oogatta / one_method.kt
Created June 5, 2017 14:46
pass an object implementing interface that requires one method.
FirebaseStorage.getInstance().reference
.child("header-photos")
.putFile(uri)
.addOnCompleteListener(object: OnCompleteListener<UploadTask.TaskSnapshot> {
override fun onComplete(p0: Task<UploadTask.TaskSnapshot>) {
TODO("not implemented")
}
})
FirebaseStorage.getInstance().reference
.child("header-photos")
.putFile(uri)
.addOnCompleteListener {
TODO("not implemented")
}
@oogatta
oogatta / multiple_methods.kt
Created June 5, 2017 14:48
pass an object implementing interface that requires multiple methods.
FirebaseDatabase.getInstance().reference
.child("photos")
.child(photoId)
.addListenerForSingleValueEvent(object : ValueEventListener {
override fun onCancelled(p0: DatabaseError?) {
TODO("not implemented")
}
override fun onDataChange(p0: DataSnapshot?) {
TODO("not implemented")
@oogatta
oogatta / crypto.js
Created June 6, 2017 13:46
use crypto
const crypto = require('crypto');
const hash = crypto.createHash('sha1');
hash.update('#ハッシュタグです');
console.log(hash.digest('hex'));
@oogatta
oogatta / template-literal.js
Created June 6, 2017 13:49
Template literals ( JS's string interpolation )
const hi = `yes`;
const test = `test ${hi} test`;
console.log(test);
@oogatta
oogatta / concatMap.kt
Created August 22, 2017 18:55
concatMap
// https://dzone.com/articles/rxjava-flatmap-vs-concatmap-vs-concatmapeager
package com.example.oogatta.concatmap
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import io.reactivex.BackpressureStrategy
import io.reactivex.Flowable
import io.reactivex.schedulers.Schedulers
// 適当コードです。全体は記事の一番下にあります。
exports.createPost = functions.database.ref("/commands/create_post/{postId}/").onWrite(event => {
const data = event.data.val();
const postId = event.params.postId;
const userId = data.userId;
console.log(`postId: ${postId}`);
console.log(`userId: ${userId}`);
// 投稿ユーザーの現在地を取るぞ!