Skip to content

Instantly share code, notes, and snippets.

@fkmhrk
fkmhrk / chain.java
Created March 2, 2017 15:18
Method chain vs sequential statements
// We often see sequential method call.
AlertDialog.Builder builer = new AlertDialog.Builder(this);
builer.setTitle("タイトル");
builer.setMessage("メッセージ");
builer.setPositiveButton(android.R.string.ok, this.listener);
// We can use method chain.
AlertDialog.Builder builer = new AlertDialog.Builder(this);
.setTitle("タイトル")
.setMessage("メッセージ")
@fkmhrk
fkmhrk / rx.java
Created November 30, 2016 15:27
RxJavaで非同期処理
// https://github.com/mokelab/android-HTTPClient-Rx-OkHTTP
HTTPClient client = new HTTPClientImpl(new OkHttpClient());
// client.send()はObservableを返す
client.send(Method.GET, "https://gae-echoserver.appspot.com/test", null, null)
.subscribeOn(Schedulers.computation()) // sendの中身はワーカースレッドで実行する
.observeOn(AndroidSchedulers.mainThread()) // Observerの中はAndroidのメインスレッドで実行する
.subscribe(new Observer<HTTPResponse>() {
@Override
public void onSubscribe(Disposable d) { }
@fkmhrk
fkmhrk / gist:18147a201de6aba0f230
Created March 7, 2016 12:42
logcat for かっし〜
03-07 21:34:50.984 27340 27340 E AndroidRuntime: java.lang.RuntimeException: Unable to resume activity {org.twentyeight.momo/org.twentyeight.momo.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.contains(java.lang.CharSequence)' on a null object reference
03-07 21:34:50.984 27340 27340 E AndroidRuntime: at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3103)
03-07 21:34:50.984 27340 27340 E AndroidRuntime: at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134)
03-07 21:34:50.984 27340 27340 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481)
0
@fkmhrk
fkmhrk / DemoDialogFragment.java
Created July 16, 2015 09:17
Activityと(Dialog)Fragmentの連携をどうやるか
public class DemoDialogFragment extends DialogFragment {
public static DialogFragment newInstance(int requestCode) {
DialogFragment dialog = new DemoDialogFragment();
Bundle args = new Bundle();
args.putBoolean(ARGS_CALLER_ACTIVITY, true);
args.putInt(ARGS_REQUEST_CODE, requestCode);
dialog.setArguments(args);
return dialog;
}
<?php
// あってそうだけど、だめな例
// 1 : 普通
// 2 : 当座
// 3 : 定期 という対応があるとする。
$bankType = "1"; // DBに入っている銀行口座の種類
$label = ($bankType == '1') ? '普通' :
($bankType == '2') ? '当座' : '定期';
echo $label;
@fkmhrk
fkmhrk / impl.go
Created March 1, 2015 03:49
model generation
package impl
import (
m "../"
"database/sql"
)
type userDAO struct {
connection *Connection
}
@fkmhrk
fkmhrk / report.py
Created February 21, 2015 06:53
Google Playの収益レポート
import csv
import sys
#Description,Transaction Date,Transaction Time,Tax Type,Transaction Type,Refund Type,Product Title,Product id,Product Type,Sku Id,Hardware,Buyer Country,Buyer State,Buyer Postal Code,Buyer Currency,Amount (Buyer Currency),Currency Conversion Rate,Merchant Currency,Amount (Merchant Currency)
def debugPrint(row):
print "Description=%s" % (row[0])
print "Transaction Date=%s" % (row[1])
print "Transaction Time=%s" % (row[2])
print "Tax Type=%s" % (row[3])
print "Transaction Type=%s" % (row[4])
@fkmhrk
fkmhrk / trycatch.js
Created January 14, 2015 04:40
TypeScript try-catch
var MyException = (function () {
function MyException(status, body) {
this.status = status;
this.body = body;
}
return MyException;
})();
function moke() {
try {
throw new MyException(404, { "msg": "not found" });
@fkmhrk
fkmhrk / Overload.ts
Created December 31, 2014 03:59
TypeScript overload
module demo {
export interface App {
// ノンブロッキングAPI。callbackで結果を受け取るので結果はany
login(username:string, password:string, callback:LoginCallback);
// ブロッキングAPI。この場合はUserオブジェクトを返したい
login(username:string, password:string) : User;
}
export class AppImpl implements App {
}
@fkmhrk
fkmhrk / BlockingTask.java
Created October 1, 2014 02:19
BlockingTask
abstract class BlockingTask<T> {
private boolean mDone;
private T mResult;
private Exception mException;
public void execute() {
mDone = false;
doAsyncCall();
while (!mDone) {
try { Thread.sleep(300); } catch (Exception e) { }