Skip to content

Instantly share code, notes, and snippets.

@macrat
macrat / ng_maker.py
Created September 30, 2016 06:16
背景データを切り出してネガティブデータを作る
import math
import cv2
import numpy
count = 0
for i in range(12):
print('makeing {0}.mp4 background image'.format(i+1))
video = cv2.VideoCapture('src/{0}.mp4'.format(i+1))
@macrat
macrat / cnn_finder.py
Created September 30, 2016 06:15
CNNで特定物体認識
import chainer
import numpy
import sklearn.base
class CNNFinder(chainer.FunctionSet):
def __init__(self):
super().__init__(conv1=chainer.functions.Convolution2D(1, 10, 4),
conv2=chainer.functions.Convolution2D(10, 20, 4),
conv3=chainer.functions.Convolution2D(20, 40, 4),
@macrat
macrat / cut-object.py
Last active September 29, 2016 02:28
動画から物体を認識して切り出すやつ。
import math
import cv2
import numpy
MOVIE_NUM = 12
count = 0
@macrat
macrat / add.py
Created September 22, 2016 07:19
addとraddが両方実装されてたらどっちが呼ばれるのか、というはなし。addだった。
class Tea:
def __init__(self, n):
self.n = n
def __add__(self, v):
print('add of {}'.format(self.n))
def __radd__(self, v):
print('radd of {}'.format(self.n))
@macrat
macrat / play_radiko.sh
Last active August 28, 2016 15:21 — forked from ihsoy-s/play_nhk-radio.sh
コンソールからradiko.jp聞くやつ。
#!/bin/bash
if [ $# -eq 1 ]; then
channel=$1
else
echo "usage : $0 channel_name"
echo " channel_name list"
echo " TBS Radio: TBS"
echo " Nippon Cultural Broadcasting: QRR"
echo " Nippon Broadcasting: LFR"
@macrat
macrat / loop.py
Created August 18, 2016 05:25
C言語使いには理解出来ない挙動をするpython
i = 10
while --i >= 0:
print(i)
@macrat
macrat / iroha.py
Last active July 28, 2016 14:36
こだわり者いろはちゃん。雑すぎて死にそう実装。 http://abc042.contest.atcoder.jp/tasks/arc058_a
target = input().split(' ')[0]
coins = {*range(10)} - {*map(int, input().split(' '))}
result = ''
for c in target:
try:
result += str(min(x for x in coins if int(c) <= x))
except ValueError:
for i in range(-1, -len(result), -1):
try:
@macrat
macrat / hello-python.py
Last active July 24, 2016 11:12
あらゆる文字列が"hello!"で置き換えられるpython処理系的なもの。
import ast
import sys
if len(sys.argv) != 2:
print('usage: python {} [FILE.py]'.format(sys.argv[0]))
sys.exit(1)
with open(sys.argv[1]) as f:
a = ast.parse(f.read(), f.name)
@macrat
macrat / calc.exs
Created June 17, 2016 15:30
インクリメントとデクリメントで四則演算 with Elixir
defmodule Main do
def inc x do
x + 1
end
def dec x do
x - 1
end
defp minus(x, y) when x < 0 do
@macrat
macrat / iostream.py
Last active June 16, 2016 04:05
pythonでもiostreamを実装出来るんじゃないだろうか。
import enum
import functools
import sys
class Align(enum.Enum):
left = lambda w, c, x: str(x) + c*(w-len(str(x)))
right = lambda w, c, x: c*(w-len(str(x))) + str(x)
@classmethod