Skip to content

Instantly share code, notes, and snippets.

View moskomule's full-sized avatar
🎯
Focusing

Ryuichiro Hataya moskomule

🎯
Focusing
View GitHub Profile
@moskomule
moskomule / wikigraph.sql
Created November 4, 2016 03:24
create lists of vertices and edges from Wikipedia page.sql and redirects.sql
## verex list
SELECT p.page_id, p.page_title
FROM page p
WHERE p.page_namespace=0
INTO OUTFILE '/tmp/vertices.tsv'
FIELDS TERMINATED BY ' ';
## edge list
SELECT l.pl_from, p.page_id
FROM page p, pagelinks l
@moskomule
moskomule / replace_pandas.py
Created November 18, 2016 14:13
for replacing values of pd.DataFrame
import pandas as pd
csv = pd.read_csv(file_name)
# csv
# "0", "1"
# Tom, 2
# John, 3
#...
csv["2"] = np.zeros(len(csv))
for i in range(len(csv)):
@moskomule
moskomule / mk_val.py
Created January 11, 2017 11:47
create validation data
import os
import shutil
import random
src_name = 'train/'
drc_name = 'val/'
src_dir = os.listdir(src_name)[1:]
for sub_src_dir in src_dir:
os.mkdir(drc_name+sub_src_dir)
@moskomule
moskomule / twitter_urls.py
Created February 22, 2017 05:59
scrape and save urls in tweets of a specified user
import tweepy
import time
api = tweepy.API(auth)
with open("log.txt", 'w') as f:
for i in range(1,100):
users_tweets = api.user_timeline(id=user,page=i,include_entities=True,count=100)
for tweet in users_tweets:
f.write(tweet.entities['urls'][0]["expanded_url"] + "\n")
time.sleep(30)
@moskomule
moskomule / save_downloaded_images.py
Created February 22, 2017 07:21
save images in specifeied pages
from html.parser import HTMLParser
import urllib.request
import re
def download(url, path):
with urllib.request.urlopen(url) as file:
file_name = path + "/" + url.split("/")[-1]
with open(file_name, 'wb') as local:
local.write(file.read())
@moskomule
moskomule / usage_lru_cache.py
Created April 28, 2017 08:38
usage of functools.lru_cache and timeit
import timeit
import functools
@functools.lru_cache(maxsize=None)
def fib(x):
if x < 2:
return x
return fib(x-1) + fib(x-2)
print(timeit.timeit('fib(100)', setup="from __main__ import fib"))
@moskomule
moskomule / matplotlib_ja.py
Created May 14, 2017 08:04
settings of Japanese characters in matplotlib figures
import matplotlib
import os
# style setting
matplotlib.style.use('seaborn-white')
# font setting
fp = matplotlib.font_manager.FontProperties(fname=os.path.expanduser('~/Library/Fonts/ipaexg.ttf'))
plt.rcParams['font.family'] = fp.get_name()
plt.plot(0, 1)
from functools import singledispatch
import numpy as np
@singledispatch
def test_function(arg):
print("default")
@test_function.register(int)
def _(arg):
print(f"arg is integer {arg}")
@moskomule
moskomule / Dockerfile
Created October 10, 2017 15:23
easymecab
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y mecab libmecab-dev mecab-ipadic-utf8
@moskomule
moskomule / capsules.tex
Last active November 14, 2017 14:43
tikz scripts for NN description
\begin{tikzpicture}[->,>=stealth,shorten >=1pt,auto,node distance=2cm,
semithick,
val/.style={circle,fill=cyan,opacity=.6}]
\node[val] (a) {$1$};
\node[right=0.1cm of a] (a1) {$u_{1}$};
\node[above=0.1cm of a] (b) {$l$};
\node[below=0.3cm of a] (c) {$\vdots$};
\node[val, below=0.3cm of c] (d) {$i$};
\node[below=0.3cm of d] (d2) {$\vdots$};
\node[right=0.1cm of d] (d1) {$u_{i}$};