Skip to content

Instantly share code, notes, and snippets.

@sleepless-se
sleepless-se / tabManage.java
Created January 19, 2019 17:19
Tab manage on selenium
// open first page
driver.get("http://google.com");
// open new tab
String windowHandle = driver.getWindowHandle();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.open();");
// getWindowHandles
ArrayList tabs = new ArrayList (driver.getWindowHandles());
import os,pymysql.cursors
def get_error_ids():
ids=[]
img_paths = os.listdir('./')
for img_path in img_paths:
if 'sale-error' not in img_path: continue
_id = img_path.split('-')[0]
ids.append(_id)
return ids
lis = []
new_df = raw_df['text'].apply(lambda x :prepro(x))
for i in range(len(new_df)):
# print(new_df[i:i+1].values[0])
lis.append(new_df[i:i+1].values[0])
print(lis)
new_df = pd.DataFrame(lis)
new_df
@sleepless-se
sleepless-se / make_3_dim_text_data.py
Created February 11, 2019 21:19
python,pandas,keras,pandas
texts = []
text = 'hello world good morning'
texts.append(text)
texts.append(text)
# print(texts)
token = K.preprocessing.text.Tokenizer()
token.fit_on_texts(text)
X = []
print(token.word_counts)
@sleepless-se
sleepless-se / to_index_word.py
Last active February 12, 2019 01:28
Keras word_index to index2word dict
index2word = {i+1:key for i, key in enumerate(token.word_index)}
@sleepless-se
sleepless-se / hash.py
Created February 13, 2019 21:13 — forked from nmalkin/hash.py
SHA-256 hash of a string in Python 3
#!/usr/bin/env python3
import hashlib
def hash_string(string):
"""
Return a SHA-256 hash of the given string
"""
return hashlib.sha256(string.encode('utf-8')).hexdigest()
@sleepless-se
sleepless-se / keras_rl_sample.py
Created February 21, 2019 12:32
強化学習サンプル Keras-RL
from keras.models import Sequential
from keras.layers import Dense, Activation, Flatten
from keras.optimizers import Adam
import gym
from rl.agents.dqn import DQNAgent
from rl.policy import EpsGreedyQPolicy
from rl.memory import SequentialMemory
env = gym.make('MountainCar-v0')
nb_actions = env.action_space.n
@sleepless-se
sleepless-se / mountain_car.py
Created February 21, 2019 13:09
強化学習サンプル MountainCar-v0
from keras.models import Sequential
from keras.layers import Dense, Activation, Flatten
from keras.optimizers import Adam
import gym
from rl.agents.dqn import DQNAgent
from rl.policy import EpsGreedyQPolicy
from rl.memory import SequentialMemory
env = gym.make('MountainCar-v0')
nb_actions = env.action_space.n
@sleepless-se
sleepless-se / dict.txt
Last active February 25, 2019 19:03
文章を書く時に役立つ「日本語→英語」変換辞書。プログラミングやブログで使う単語中心ですがそれ以外もOK
じぇいそーぷ jsoup 名詞
くらす <div class=""></div> 名詞
しゅってん: 出典: 名詞
みだし <h2></h2> 名詞
みだし <h3></h3> 名詞
みだし <h4></h4> 名詞
hr <hr> 名詞
h4 <h4></h4> 名詞
h3 <h3></h3> 名詞
h2 <h2></h2> 名詞
@sleepless-se
sleepless-se / get_object_center.py
Created February 27, 2019 00:52
Get object's center
def get_object_center(rois,image):
height = image.shape[0]
width = image.shape[1]
center = width / 2
print(width,height)
print('center',center)
max_area = 0
for i in range(len(rois)):
print(rois[i])
start_height = rois[i][0]