Skip to content

Instantly share code, notes, and snippets.

@sonesuke
sonesuke / gist:3261184
Created August 5, 2012 02:30
vim set filetype
set filetype=python
@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 / 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: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 / gist:3364994
Created August 16, 2012 00:30
.htaccess expire date
ExpiresActive On
ExpiresByType image/png "access plus 20 days"
ExpiresByType image/jpg "access plus 50 days"
ExpiresByType image/jpeg "access plus 50 days"
ExpiresByType image/ico "access plus 10 month"
ExpiresByType image/gif "access plus 30 days"
ExpiresByType text/javascript "access plus 8 days"
ExpiresByType application/javascript "access plus 8 days"
ExpiresByType text/css "access plus 8 days"
@sonesuke
sonesuke / gist:3367028
Created August 16, 2012 04:48
paste gist to tumlr
<div class="gist">https://gist.github.com/3364994</div>
@sonesuke
sonesuke / gist:3489467
Created August 27, 2012 15:24
gist css
/*
custom style for gist
div.section と組み合わせて適用範囲を限定することで、標準の.gist-xxxxの設定を上書きしている。
*/
div.section .gist .gist-file .gist-data pre{
-moz-border-radius-bottomleft: 0;
-moz-border-radius-bottomright: 0;
-webkit-border-bottom-left-radius: 0;
-webkit-border-bottom-right-radius: 0;
background: #000000 !important;
@sonesuke
sonesuke / gist:3765806
Created September 22, 2012 10:43
nunit
mcs -t:library Account.cs
mcs -t:library -r:nunit.framework,Account.dll AccountTest.cs
nunit-console AccountTest.dll
sudo apt-get install haskell-platform
cabal update
cabal install pandoc
make sure path
cabal path is ${HOME}/.cabal/bin
sudo apt-get install graphviz libgraphviz-dev pkg-config python-dev
git clone https://github.com/jgm/pandocfilters.git
@sonesuke
sonesuke / format.py
Created August 27, 2017 06:35
change row and col in pandas
import pandas as pd
def f(a):
a.index = [0 for i in range(len(a))]
del a['rot']
out = a[0:1]
for i in range(1, len(a)):
out = out.join(a[i:i+1], rsuffix='{0}'.format(i))