This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Use Graham's example. | |
| # http://www.phontron.com/slides/nlp-programming-ja-03-ws.pdf | |
| INF = 1e6 | |
| edge_list = [ | |
| None, # e0 | |
| { # e1 | |
| 'id': 1, | |
| 'score': 2.5, | |
| 'begin_node_id': 0, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MetaGlobalVariables(type): | |
| @property | |
| def HOGE(cls): | |
| return cls._GlobalVariables__hoge # mangling | |
| class GlobalVariables(object, metaclass=MetaGlobalVariables): | |
| __hoge = 'xxxx' | |
| # read OK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datetime import datetime | |
| from pytz import timezone | |
| import subprocess | |
| import glob | |
| import xml.etree.ElementTree as ET | |
| # replaced time zones | |
| SRC_TZ_ZONES = ['UTC+09:00', 'UTC+01:00'] | |
| # target time zone | |
| TGT_TZ_ZONE = ['Europe/Berlin'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Use plotly orca (Docker) to save png/html files. | |
| Run plotly-orca server before running this code. | |
| % docker run -d -p 9091:9091 quay.io/plotly/orca | |
| I refer the following forum to write this code and slightly modify the code for proper import. | |
| https://community.plot.ly/t/plotly-io-with-external-orca/25600/2 | |
| """ | |
| import io | |
| import requests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| // Use IntelliSense to learn about possible attributes. | |
| // Hover to view descriptions of existing attributes. | |
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
| "version": "0.2.0", | |
| "configurations": [ | |
| { | |
| "name": "Python: Current File", | |
| "type": "python", | |
| "pythonPath": "${config:python.pythonPath}", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Remove latex blocks and replace math functiosn with (MATH) | |
| - How to debug: | |
| pandoc -t json aaa.tex | python ./this-file.py | pandoc -f json -t plain | |
| - How to use: | |
| pandoc -s aaa.tex --filter=./this-file.py -o out.text | |
| """ | |
| from pandocfilters import toJSONFilter, Str |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # けんちょんさんのめぐるん式二部探索解説 | |
| # https://qiita.com/drken/items/97e37dd6143e33a64c8c | |
| def lowerBound(nums, key): | |
| """numsの中でkey以上の要素のうちの一番左のインデックス""" | |
| ng, ok = -1, len(nums) | |
| while abs(ok - ng) > 1: | |
| mid = (ok + ng) // 2 | |
| if key <= nums[mid]: | |
| ok = mid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| activate_conda(){ | |
| eval "$(conda shell.zsh hook)" | |
| conda activate $1 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import collections | |
| import re | |
| def get_stats(vocab): | |
| pairs = collections.defaultdict(int) | |
| for word, freq in vocab.items(): | |
| symbols = word.split() | |
| for i in range(len(symbols)-1): | |
| pairs[symbols[i],symbols[i+1]] += freq |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 243.2 67.0 1 | |
| 254.5 70.1 1 | |
| 253.1 59.3 1 | |
| 228.1 70.4 1 | |
| 240.8 69.5 1 | |
| 244.0 69.0 1 | |
| 257.9 66.3 1 | |
| 255.8 68.3 1 | |
| 249.9 63.5 1 | |
| 251.3 70.3 1 |