Skip to content

Instantly share code, notes, and snippets.

@sonesuke
sonesuke / gist:3336519
Created August 13, 2012 02:52
vim_input
def vim_input(message = 'input', secret = False):
vim.command('call inputsave()')
vim.command("let s:user_input = %s('%s :')" % (("inputsecret" if secret else "input"), message))
vim.command('call inputrestore()')
return vim.eval('s:user_input')
@sonesuke
sonesuke / test_Game.py
Created August 5, 2012 02:51
pytest parametrize
@pytest.mark.parametrize(
('rolls', 'expected'),
[
([1, 2], 18 + 3),
([10, 5, 5], 18 + 30),
([5, 5, 10], 18 + 30),
]
)
def test_10_frame(rolls, expected):
g = Game()
@sonesuke
sonesuke / gist:3261226
Created August 5, 2012 02:43
how to use reduce in python
class A:
@property
def value(self):
return 1
sample_list = [A(), A(), A()]
print reduce(lambda x, y: x + y.value, sample_list, 0)
print reduce(lambda x, y: x + y, map(lambda x: x.value, sample_list))
@sonesuke
sonesuke / gist:3261184
Created August 5, 2012 02:30
vim set filetype
set filetype=python