Skip to content

Instantly share code, notes, and snippets.

View yatakeke's full-sized avatar

Yatakeke a.k.a Agile Zamurai yatakeke

View GitHub Profile
import MeCab
def tokenization(text, dic_path, lex = None):
# -Oyomi (ヨミ付与) -Ochasen (ChaSen互換) -Odump (全情報を出力)
unknown_option = "-U %M\\t未知語,*,*,*,*,*,*,*,*\\n"
mecab_options = " ".join(["-d", dic_path, unknown_option])
tagger = MeCab.Tagger(mecab_options)
parse = tagger.parse(text).replace('\t',',')
@yatakeke
yatakeke / createAndBuildAppInHeroku.php
Last active February 18, 2019 01:56
methods to create and build app in heroku
<?php
public function createapp($email, $password){
$url = "https://api.heroku.com/apps";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, $email.":".$password);
$headers = ['Accept: application/vnd.heroku+json; version=3',"Content-Type: application/json"];
from glob import glob
from os import path
def listup_file_name(data_path, extension=None, abspath=True):
extension = '.' + extension if extension else ''
if abspath:
return glob(data_path + '*' + extension)
else:
return glob(path.relpath(data_path + '*' + extension))
@yatakeke
yatakeke / step_function.py
Last active February 18, 2019 01:53
this is the code for step function in Python
def step_function(x):
return np.where(x >= 0, 1, 0)
### It is equivalent to below code to give 1-D array to np.where.
### variables = np.where(condition, val1, val2) <=> variables = val1 if x >= 0 else val2
def step_function(x:list):
return np.maximum(x, 0)
a = list(range(10))
print("before : ", a)
b = np.random.permutation(a)
print("after : ", b)
====>>>>
before : [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
after : [9 7 4 0 8 3 2 6 5 1]
a = np.zeros([2,2])
a[(0, 1),(0, 1)] = 1
print(a)
return
====>>>> array([1, 0],
[0, 1])
@yatakeke
yatakeke / magic_methods.py
Last active February 18, 2019 01:51
Pythonの特殊メソッドについて
def __str__(self)
# printやformat文の引数としてオブジェクトが指定された時に
# 呼び出され、非公式の文字列表現を返す。
def __call__()
# classを直接呼び出す時に実行される。
def __repr__()
# 正式なオブジェクトの内容を文字列で返し、
# インタプリターが同値性をチェックする時に使われる。
@yatakeke
yatakeke / fish
Created February 16, 2019 01:49
fishについての知見
環境変数の設定の仕方
- ~/.config/fish/config.fishに書き込む
import os
current_dir = os.path.dirname(os.path.abspath("__file__"))
from datetime import datetime as dt
def get_timestamp():
dt_obj = dt.now()
return dt_obj.strftime("%Y/%m/%d, %H:%M:%S")