Skip to content

Instantly share code, notes, and snippets.

@tmf16
tmf16 / UserController.php
Last active December 20, 2018 05:26
test
class UserController extends Controller
{
private const USER_PATH = "/tmp/users.csv";
/*
* $user_idに対応するユーザデータをjsonで返す
*/
public function show(int $user_id)
{
$user = null; // ここで作成したクラスのメソッドを呼ぶ
@tmf16
tmf16 / 0_reuse_code.js
Created March 20, 2014 06:30
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
@tmf16
tmf16 / HogeListView.java
Created February 25, 2014 05:55
ListViewを継承してonTouchEventを実装するとNullPointerException(Android 2.3以前)になるので回避策でgetChildCount使う実装
public class HogeListView extends ListView {
public HogeListView(Context context) {
super(context);
}
public HogeListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@tmf16
tmf16 / MainActivity.java
Created February 20, 2014 01:52
Gsonでsnake_caseのjsonをcamelCaseのクラスで受け取る
String json = "{id:3, age:30, first_name: 'hoge', last_name: 'fuga'}";
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
User user = gson.fromJson(json, User.class);
@tmf16
tmf16 / HogeActionProvider.java
Last active August 29, 2015 13:56
ActionBar(android.support.v7.app.ActionBar)に独自Viewを追加する方法
package com.example.android;
import com.example.android.R;
import android.content.Context;
import android.support.v4.view.ActionProvider;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
@tmf16
tmf16 / gist:3921711
Created October 20, 2012 02:06
可変長引数にdictを渡す
>>> def func_dict(**argv):
... print 'dict ----'
... print argv
...
>>>
>>> d = {'a': 1, 'b': True, 'c': u'ほげ'}
>>>
>>> func_dict(d)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
@tmf16
tmf16 / gist:3921703
Created October 20, 2012 02:03
可変長引数にtupleを渡す
>>> def func_tuple(*argv):
... print 'tuple ----'
... print argv
...
>>>
>>> t = (1, True, 'A')
>>>
>>> func_tuple(t)
tuple ----
((1, True, 'A'),)
@tmf16
tmf16 / gist:3921666
Created October 20, 2012 01:55
可変長引数を次の関数へ
>>> def test(*argv):
... hoge(argv)
... fuga(*argv)
...
>>> def hoge(*argv):
... print argv
...
>>> def fuga(*argv):
... print argv
...
@tmf16
tmf16 / gist:3916678
Created October 19, 2012 07:14
Pythonでの可変長引数
# 可変長引数(tuple)
>>> def func(*v):
... print v
...
>>> func(1)
(1,)
>>> func(1, "ABC", True)
(1, 'ABC', True)
# 可変長引数(dict)
@tmf16
tmf16 / gist:3904639
Created October 17, 2012 09:19
pythonでの配列処理いろいろ
# 連結
>>> a = [1, 2, 3]
>>> b = [4, 6, 6]
>>> a + b
[1, 2, 3, 4, 6, 6]
# 重複の削除
>>> a = [100, 20, 5, 10, 5, 20, 8]
>>> list(set(a))
[8, 20, 10, 100, 5]