Skip to content

Instantly share code, notes, and snippets.

@kota7
kota7 / hisha-kaku-swap.py
Last active April 12, 2022 22:30
Find shortest path for swapping Hisha and Kaku from the initial position (Puzzle from Shogi Focus 2022.4.10)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from collections import namedtuple, deque
from datetime import datetime
# We express a "state" as the locations of the seven pieces
# in the order of: ou, hi, kaku, kin1, kin2, gin1, gin2
# with we make sure kin1 < kin2 and gin1 < gin2 to avoid duplicates
@kota7
kota7 / ggplot-on-pykernel.ipynb
Last active September 7, 2021 17:04
Make R's ggplot2 graph on Juypter Python kernel.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kota7
kota7 / venv-like-conda
Last active August 27, 2021 23:21
Add this to `.bashrc`, `.bash_profile` or alike to use `venv` in a similar manner as conda
# ****************************************
# VENV WRAPPER to use like conda
# add this to .bashrc or .bash_profile
#
#
# Create env:
#
# venvc <envname>
#
# Activate env:
@kota7
kota7 / bert-solves-eiken-problems.ipynb
Last active August 24, 2021 17:30
BERT solves Eiken problems
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kota7
kota7 / byte-embed.py
Last active January 12, 2021 11:58
A way to hard-code a python object in a script using pickle dumps and loads
# This works when run as a script
# but not when copied to a notebook cell and run it.
import pickle
from collections import namedtuple
# We want to embed this object into a script
Foo = namedtuple("Foo", "a b")
a = Foo(1, 2)
@kota7
kota7 / display-ggplot-with-japanese.ipynb
Created November 4, 2020 12:38
Display ggplot graphs with Japanese text on Jupyter notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kota7
kota7 / jumanpp-parallel-minibatch.py
Last active October 14, 2020 00:55
Apply JUMAN++ to many texts in parallel.
#!/usr/bin/env python
# coding: utf-8
"""
Apply JUMAN++ to many texts in parallel.
Requirements.
JUMAN++: http://nlp.ist.i.kyoto-u.ac.jp/index.php?JUMAN++
Python library:
mojimoji (https://github.com/studio-ousia/mojimoji) or