Skip to content

Instantly share code, notes, and snippets.

@trsqxyz
trsqxyz / file0.txt
Last active September 1, 2015 05:19
Python の yield from をつかって flatten する ref: http://qiita.com/trsqxyz/items/013ea4ece0de52328f17
def flatten(x):
if hasattr(x, '__iter__') and not isinstance(x, str):
for y in x:
yield from flatten(y)
else:
yield x
@trsqxyz
trsqxyz / flatten.py
Last active September 1, 2015 05:20
def flatten(x):
if hasattr(x, '__iter__') and not isinstance(x, str):
for y in x:
yield from flatten(y)
else:
yield x
@trsqxyz
trsqxyz / bar
Last active August 29, 2015 14:25
plotly でいい感じのグラフをつくる ref: http://qiita.com/trsqxyz/items/d797919c19ee6c49ae72
trace = Bar(x=list(range(10)), y=list(np.random.randint(0,30,10)))
data = Data([trace])
py.image.save_as(data, filename='bar.png')
@trsqxyz
trsqxyz / file0.txt
Last active August 29, 2015 14:24
plotly でいい感じのグラフをオンラインに公開する ref: http://qiita.com/trsqxyz/items/27b84bb72de5371b062d
import plotly.plotly as py
from plotly.graph_objs import *
trace0 = Scatter(
x=[1, 2, 3, 4],
y=[10, 15, 13, 17]
)
trace1 = Scatter(
x=[1, 2, 3, 4],
import msvcrt
def inp():
w = []
while True:
w.append(msvcrt.getwch())
if w[-1] == '\x10': break
return ''.join(w[:-1])
In [175]: for i in range(len(df.mean().index)):
.....: plt.bar(i, df.mean().iloc[i].gross, label=df.mean().index[i], color='0.{0}1'.format(i))
.....:
In [176]: plt.legend(loc='best')
Out[176]: <matplotlib.legend.Legend at 0xc5c1770>
In [177]: plt.show()
import sys
import math
def compass(n):
cells = math.ceil(math.sqrt(n))
maps = [[[] for _ in range(cells)] for __ in range(cells)]
row = math.ceil(cells//2)
col = row if cells%2 == 0 else row + 1
pos = 'S'
direction = {
>>> for s in ('C-c', 'C-s', 'C-r'):
... print(s)
... msvcrt.getch()
...
C-c
b'\x03'
C-s
b'\x13'
C-r
b'\x12'
s='Supercalifragilisticexpialidocious';[print(''.join(__import__('random').sample(s,len(s)))) for _ in s]
Supercalifragilisticexpialidocious = lambda x: ''.join(random.sample(x ,len(x))