Skip to content

Instantly share code, notes, and snippets.

View tamago324's full-sized avatar
⌨️
Enjoy Keeb!

tamago324 tamago324

⌨️
Enjoy Keeb!
  • japan
View GitHub Profile
@tamago324
tamago324 / infix2postfix.py
Last active August 30, 2020 14:10
中置記法を後置記法に変換
""" 中置記法の数式を後置記法に翻訳する
ドラゴンブックの p81 のコードを Python で書いた
再帰あり ver
"""
import string
from typing import Optional
from sys import argv
@tamago324
tamago324 / dfa.py
Last active August 22, 2020 09:28
DFA の最小化 (minimum_states.py で最小化する関数を定義した)
"""
0 を偶数個含む文字列の言語を受理する DFA
"""
from enum import Enum, auto
class DFA:
def __init__(self, states, alphabets, transition_pair, start_state, accept_states):
self.states = states
self.alphabets = alphabets
@tamago324
tamago324 / _sandbox4.py
Last active August 19, 2020 23:23
同値な状態のペアを見つける (穴埋めアルゴリズム)
"""
同値な状態を取得する 穴埋めアルゴリズム を使ってみる
"""
from enum import Enum, auto
from graphviz import generate_dot, tweak_q
from nfa import NFA
from states_equivalent import equivalent_pair_set
@tamago324
tamago324 / graphviz.py
Last active August 16, 2020 09:54
NFA で正規演算
def tweak_q(q):
if "States" in str(q):
return str(q).replace("States", "").replace(".", "_")
else:
return f"q{q}"
def generate_dot(nfa, name="sample"):
""" Graphviz でそのまま出力できるテキスト"""
result = ""
@tamago324
tamago324 / nfa.py
Created July 27, 2020 17:10
0 が 2の倍数か3の倍数の個数なら受理する NFA
"""
0 が 2の倍数か3の倍数の個数なら受理する NFA
"""
from enum import Enum, auto
from functools import reduce
class NFA:
def __init__(self, states, alphabets, transition, start_state, accept_state, E):
# self.states = states
@tamago324
tamago324 / dfa.py
Created July 26, 2020 12:44
0 を偶数個含む文字列の言語を受理する DFA
"""
0 を偶数個含む文字列の言語を受理する DFA
"""
from enum import Enum, auto
class DFA:
def __init__(self, states, alphabets, transition_method, start_state, accept_state):
# self.states = states
# self.alphabets = alphabets
@tamago324
tamago324 / cursorline_in_hlsearch.vim
Last active May 25, 2020 15:44
検索のハイライトのときだけ、cursorline を ON にする
scriptencoding utf-8
function! s:cb(timer) abort
if v:hlsearch
" マッチする文字があれば、カーソルをつける
if search(@/, 'cnw') !=# 0
if !&cursorline
set cursorline
return
endif
@tamago324
tamago324 / LeaderF-ghq.vim
Last active April 20, 2020 04:51
Only github.com
let g:Lf_Extensions = get(g:, 'Lf_Extensions', {})
function! LfExt_ghq_accept(line, args) abort
let l:path = $GHQ_ROOT . '/github.com/' . a:line
execute 'tabe | tcd ' . l:path
endfunction
function! LfExt_ghq_format_line(line, args) abort
return a:line[11:]
endfunction
scriptencoding utf-8
" input() のときに getcmdline() で取得できる技
function! NewTmpFile() abort
let l:winid = popup_create('', {
\ 'padding': [1, 1, 1, 1],
\ 'minwidth': 20,
\ 'line': 'cursor-1',
\ 'col': 'cursor+3',
from pytwitcasting import auth, api
import time
import pyperclip
client_id = "取得した値"
client_secret = "取得した値"
app_basis = auth.TwitcastingApplicationBasis(
client_id=client_id, client_secret=client_secret
)