Skip to content

Instantly share code, notes, and snippets.

@xebecnan
xebecnan / win32_utf8_run.py
Last active December 27, 2015 20:49
Windows下正确显示程序打印的UTF8中文
import sys
from subprocess import PIPE, Popen, STDOUT
args = sys.argv[1:]
process = Popen(args, stdout=PIPE, shell=True, stderr=STDOUT)
count = 0
while True:
buff = process.stdout.readline()
def status_worker(body, last_modify):
try:
expire = time.time() + 10
while time.time() < expire:
mtime = os.path.getmtime(STATUS_FILE)
if mtime > last_modify:
break
time.sleep(1)
if not os.path.exists(STATUS_FILE):
body.put(json.dumps({
os.execute("gnome-settings-daemon &")
os.execute("gnome-keyring-daemon --start --components keyring,pkcs11,secrets,ssh,gpg &")
os.execute("gnome-power-manager &")
os.execute("nm-applet --sm-disable &")
-- 解决搜狗拼音的黑块问题
-- 需要先 apt-get install compton
os.execute("compton --config /dev/null &")
-- 启动搜狗拼音输入法, 需要先从官网下载 deb 包安装
import hashlib
def get_file_md5(filename):
md5 = hashlib.md5()
with open(filename,'rb') as f:
for chunk in iter(lambda: f.read(128*md5.block_size), b''):
md5.update(chunk)
return md5.hexdigest()
@xebecnan
xebecnan / is_array.lua
Created January 14, 2015 07:47
check if a lua table is an array
local _cache = {}
local function is_array(t)
local count = #t
if count == 0 then
return false
end
for i=1,count do
local v = t[i]
if v == nil then
@xebecnan
xebecnan / lundump_lua53_load_x32_bytecode_on_x64.c
Last active October 26, 2022 22:12
lua5.3 support load x32 bytecode on x64
typedef struct {
lua_State *L;
ZIO *Z;
Mbuffer *b;
const char *name;
lu_byte load_size_t_size;
lu_byte load_size_t_offset;
} LoadState;
@xebecnan
xebecnan / win32_utf8.c
Created June 16, 2015 03:25
win32: convert between wchar and utf8
wchar_t*
fromUTF8(
const char* src,
size_t src_length, /* = 0 */
size_t* out_length /* = NULL */
)
{
if(!src)
{ return NULL; }
@xebecnan
xebecnan / mymod.user.lua
Created October 26, 2015 12:48 — forked from cloudwu/mymod.user.lua
user defined loader
local M = {}
function M.test(...)
print(...)
end
return M
"LUA REQUIRE JUMPER {
function! JumpRequire()
let line=getline('.')
if line =~ "\\<require\\>\\s*(\\?\\s*['\"][^'\"]\\+['\"]\\s*)\\?\\s*$"
let path = substitute(line, "^.*\\<require\\>\\s*(\\?\\s*['\"]\\([^'\"]\\+\\)['\"]\\s*)\\?\\s*$", '\1', 'g')
let target = substitute(path, '\.', '/', 'g') . '.lua'
if &mod['ified']
execute "vs " . target
else
execute "e " . target
@xebecnan
xebecnan / lua_require_jump.vimrc
Last active October 25, 2016 03:16
lua require jumper
"LUA REQUIRE JUMPER {
function! JumpRequire()
let kws = ["require", "g_class", "show_ui", "notify_ui", "hide_ui", "get_ui", "call_ui"]
let prefix="\\(\\<" . join(kws, "\\>\\|\\<") . "\\>\\)"
let line=getline('.')
if line =~ prefix . "\\s*(\\?\\s*['\"][^'\"]\\+['\"]"
let path = substitute(line, "^.*" . prefix . "\\s*(\\?\\s*['\"]\\([^'\"]\\+\\)['\"].*$", '\2', 'g')
let target = substitute(path, '\.', '/', 'g') . '.lua'
if &mod['ified']
execute "vs " . target