Skip to content

Instantly share code, notes, and snippets.

View lfkdsk's full-sized avatar
🐶
Focusing

lfkdsk lfkdsk

🐶
Focusing
View GitHub Profile
@lfkdsk
lfkdsk / collect.c
Created January 15, 2019 10:40
python gc collection
/* Invoke progress callbacks to notify clients that garbage collection
* is starting or stopping
*/
static Py_ssize_t
collect_with_callback(int generation)
{
Py_ssize_t result, collected, uncollectable;
invoke_gc_callback("start", generation, 0, 0);
result = collect(generation, &collected, &uncollectable, 0);
invoke_gc_callback("stop", generation, collected, uncollectable);
@lfkdsk
lfkdsk / app.py
Created December 2, 2018 00:26
app.py
import click
click.disable_unicode_literals_warning = True
import json
import random
import re
from concurrent.futures import ThreadPoolExecutor, as_completed
# from flaskext.mysql import MySQL
@lfkdsk
lfkdsk / test_yapypy.py
Created October 12, 2018 08:30
test_yapypy
import logging
import sys
from concurrent.futures import ThreadPoolExecutor
from subprocess import call, check_output, PIPE, Popen
from Redy.Tools.PathLib import Path
test_dir = Path('test')
logging.basicConfig(level=logging.INFO,
@lfkdsk
lfkdsk / alg.py
Created August 9, 2018 09:18
closure
# alg.9 in paper
def closure(d_state, conf):
# to prevent compute over and over again...
if conf in d_state.busy:
return set()
else:
d_state.busy.add(conf)
ret = set()
ret.add(conf)
@lfkdsk
lfkdsk / alg.py
Created August 9, 2018 08:51
create dfa
# alg.8 in paper
def create_dfa(a_start_state):
ret = dfa()
work = []
D0 = dfa_state() # dfa start state for this rule
for alt in range(
len(a_start_state.transitions)): # init all final states, num of start state transitions is num of alts
f_i = dfa_state(alt)
ret.add_dummy_final_state(alt, f_i)
for i, (_, pa_i) in enumerate(a_start_state.transitions):
@lfkdsk
lfkdsk / merge_atn.py
Created August 9, 2018 08:45
merge ATN
def merge_to_atn(self, a_net):
ret = a_net
pa = self.__new_atn_state(self.name, ret) # start state
ret.n_term_start_state_mapping[self.get_n_term_this_rule()] = pa
pa1 = self.__new_atn_state(self.name + "_end", ret, True) # end state
for i, alt in enumerate(self.alts):
pai = self.__new_atn_state(self.name + "_" + str(i), ret) # alt start state
pa.add_transition(epsilon, pai) # start state epsilon transition to alt start state
if len(alt) != 0: