Skip to content

Instantly share code, notes, and snippets.

View walkingmask's full-sized avatar
💩
Unchi

Kazuki NAGAMINE walkingmask

💩
Unchi
View GitHub Profile
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
def train_unigram(file_name):
my_dict = defaultdict(int)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import math
import nist_nlp01_1
def test_entropy(document, unigram):
#!/usr/bin/env bash
set -eu
if [ $# -lt 2 ] || [ $# -gt 2 ]; then
echo "Usage: $0 /PATH/TO/INPUT_DIR /PATH/TO/OUTPUT_DIR"
exit 1
fi
if [ ! -d "$1" ]; then
echo "No such directory $1"
# python でランダムな数列リストを出力するワンライナー
python -c 'num=5;import random;print(random.sample(range(1,num+1),num))'
// Google Calendar Line Bot
// Main
// Post処理するやつ
function doPost(e) {
var json = JSON.parse(e.postData.contents);
var message = json.events[0].message.text;
if (message != null) {
@walkingmask
walkingmask / send_email_with_gmail.py
Created December 15, 2017 13:56
A example of sending email with gmail.
# -*- coding: utf-8 -*-
from email.mime.text import MIMEText
from email.utils import formatdate
import smtplib
addr = ""
pswd = ""
subj = ""
body = ""
@walkingmask
walkingmask / multi_thread_test.py
Created December 19, 2017 07:10
Testing multithreading
import multiprocessing
import time
def f(x):
for i in range(10**6):
x += i/x
return x
def main(n):
with multiprocessing.Pool(n) as p:
@walkingmask
walkingmask / tictactoe.py
Created March 14, 2018 05:40
Play tictoctoe
from random import choices, random
class TicTacToe:
def __init__(self, mark1='O', mark2='X'):
self._state = [None]*9
self._actions = list(range(0,9))
# completion statuses
self._comps = [[0,1,2], [0,4,8], [0,3,6], [1,4,7],
@walkingmask
walkingmask / dungeon.py
Last active March 14, 2018 06:35
Play dungeon
class FieldPos(object):
def __init__(self, y, x):
self.y = y
self.x = x
class FieldObj(object):
def __init__(self, mark_i, mark_c):
self.mark_i = mark_i
self.mark_c = mark_c
import numpy as np
import timeit
def f(x, y):
return (x+1)*y
def ff(X, y):
res = []
for x in X:
res.append(f(x,y))