Skip to content

Instantly share code, notes, and snippets.

View tomoh1r's full-sized avatar
💭
I may be slow to respond.

NAKAMURA, Tomohiro tomoh1r

💭
I may be slow to respond.
View GitHub Profile
@tomoh1r
tomoh1r / each_slice.py
Last active August 29, 2015 14:14
each_slice.py
dummy = object()
def each_slice(lst, number, fill=dummy):
typ = type(lst)
lower, upper = 0, number
while True:
# slice 取ったときに範囲外なら空のリストがとれる
sliced = lst[lower:upper]
if sliced:
if fill == dummy or len(sliced) == number:
@tomoh1r
tomoh1r / testutil.py
Created April 9, 2015 07:59
ユニットテスト時に datetime.now() を置き換える
# -*- coding: utf-8 -*-
from datetime import datetime
@contextlib.contextmanager
def mock_datetime_now(module_path, return_value):
"""
適当なモジュールの datetime.now() mock 適当な日付を返すようにする
>>> from datetime import datetime
@tomoh1r
tomoh1r / StringSwitch.java
Created April 13, 2015 03:39
String switch と Optional の連携
import java.util.Optional;
public class StringSwitch {
public static void main(String[] args) {
String text = null;
switch(Optional.ofNullable(text).orElse("")){
case "a":
System.out.println("AA");
break;
case "b":
@tomoh1r
tomoh1r / mock_with_stmt.py
Created April 14, 2015 13:58
with 文を mock する
# -*- coding: utf-8 -*-
import mock
import contextlib
@contextlib.contextmanager
def hoge():
yield u'ハリルホジッチ'
@tomoh1r
tomoh1r / gist:3560df167c7ce41021bb
Last active August 29, 2015 14:23
msys2_vim_build_with_lua_PKGBUILD.diff
diff --git a/vim/PKGBUILD b/vim/PKGBUILD
index ba3e6990049c..3f45acb5a503 100644
--- a/vim/PKGBUILD
+++ b/vim/PKGBUILD
@@ -2,8 +2,8 @@
pkgname=vim
_topver=7.4
-_patchlevel=728
-__hgrev=9782a8aa2d7f
@tomoh1r
tomoh1r / dump_fizzbuzz_001.py
Last active August 29, 2015 14:25
15個 fizz/buzz のリスト作ってから yield で fizzbuzz
#! /usr/bin/env python
# -*- coding: utf-8 -*-
def fizzbuzz():
loop = [
None,
None,
'fizz',
None,
@tomoh1r
tomoh1r / result.txt
Created August 13, 2015 01:19
Python で辞書を作る
>>> timeit.timeit('{x: x for x in range(10000)}', number=1000)
0.5202829837799072
>>> timeit.timeit('dict((x, x) for x in range(10000))', number=1000)
1.0116031169891357
@tomoh1r
tomoh1r / gist:1342308
Created November 6, 2011 01:10
easy_install -U all みたいな
easy_install -U `python -c "for dist in [dist for dist in __import__('pkg_resources').working_set if dist.project_name != 'Python']: print dist.project_name"`
@tomoh1r
tomoh1r / gist:1560221
Created January 4, 2012 14:14
PHP5.4RC4 ビルド用のシェルスクリプト
#!/bin/sh
# このページより PHP のオプションを参考にいたしました。
# http://blog.madapaja.net/2011/12/php54-symfony2.html
# 下記のページより、ビルド用シェルスクリプトの着想を得ました。
# http://okwave.jp/qa/q566511.html
# 改めて御礼いたします。
cd php-5.4.0RC4
make clean
./configure \
--prefix=/path/to/php-5.4.0RC4 \
@tomoh1r
tomoh1r / error.log
Created January 4, 2012 15:31
PHP5.4RC4でSilexを動かしたときのエラー
Fatal error: Call to undefined method Symfony\Component\ClassLoader\UniversalClassLoader::registerNamespaces() in phar:///path/to/silex/silex.phar/autoload.php on line 10