Skip to content

Instantly share code, notes, and snippets.

View lmatt-bit's full-sized avatar
🎱

lmatt lmatt-bit

🎱
View GitHub Profile
@lmatt-bit
lmatt-bit / decorator.py
Created October 17, 2019 03:28
python decorator example
def timeout_function(timeout, force_clean_func):
def decorator_timeout_function(func):
@functools.wraps(func)
def run_func_in_thread(*args, **kwargs):
thread = threading.Thread(target=func, args=args, kwargs=kwargs)
thread.start()
thread.join(timeout)
if thread.is_alive():
print("timeout, begin to call force_clean_func")
force_clean_func()
@lmatt-bit
lmatt-bit / pywin32_office.py
Created October 16, 2019 02:14
pywin32 office
import os
import tempfile
from bottle import route, request, static_file, run
import win32com
from win32com.client import *
word = win32com.client.Dispatch("Word.Application")
word.visible = 1
@route('/convert', method='POST')
@lmatt-bit
lmatt-bit / vs_docker_port.txt
Created July 2, 2019 06:25
how to forward port in vs docker tool
You can add the <DockerfileRunArguments> tag to the <PropertyGroup> section in your *.csproj file and put additional run parameters there.
e.g.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<DockerfileRunArguments>-p 5000:6000</DockerfileRunArguments>
</PropertyGroup>
</Project>
@lmatt-bit
lmatt-bit / test.dockerfile
Created November 7, 2017 03:45
docker file to set the locale
# Set the locale
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
@lmatt-bit
lmatt-bit / MultiProcessingLog.py
Created August 23, 2017 12:15
MultiProcessingLog
class MultiProcessingLog(logging.Handler):
def __init__(self, log_file_name, when, backupCount):
logging.Handler.__init__(self)
self._handler = TimedRotatingFileHandler(log_file_name, when=when, backupCount=backupCount)
self.queue = multiprocessing.Queue(-1)
t = threading.Thread(target=self.receive)
t.daemon = True
t.start()
@lmatt-bit
lmatt-bit / xmlwithnamespace.linq
Created August 16, 2017 08:49
xml with namespace; .net
var path = @"C:\Users\lmatt\Desktop\MTTest\MT Test 02.docx.xlf";
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable());
namespaceManager.AddNamespace("prefix", "urn:oasis:names:tc:xliff:document:1.2");
var xelement = XElement.Load(path);
xelement.XPathSelectElements("//prefix:seg-source/prefix:mrk", namespaceManager).Select(e => e.Value).Dump();
@lmatt-bit
lmatt-bit / use_graphviz.py
Created July 12, 2017 08:42
Using graphviz
from graphviz import Digraph
import json
def generate_sub_graph(sub_graph_name, digraph, sub_data_json):
with digraph.subgraph(name="cluster_" + sub_graph_name, edge_attr={'arrowhead': 'none'}) as c:
data_len = len(sub_data_json)
edges = []
c.node(sub_graph_name + str(data_len), label=sub_graph_name + "_sentence_end")
for i in range(data_len):
c.node(sub_graph_name + str(data_len - i - 1), label=sub_data_json[data_len - i - 1])
[
"html",
"head",
"title",
"base",
"link",
"meta",
"style",
"script",
"noscript",
@lmatt-bit
lmatt-bit / .zshrc
Last active May 15, 2017 02:05
fix home & end key for zsh
#bindkey -v
bindkey '\eOH' beginning-of-line
bindkey '\eOF' end-of-line