Skip to content

Instantly share code, notes, and snippets.

View iamalbert's full-sized avatar

Albert Zhuang iamalbert

View GitHub Profile
@iamalbert
iamalbert / cjk.tex
Created December 15, 2015 07:12
XeLaTex 中文
\usepackage{fontspec} %加這個就可以設定字體
\usepackage{xeCJK} %讓中英文字體分開設置
\setCJKmainfont{微軟正黑體} %設定中文為系統上的字型,而英文不去更動,使用原TeX字型
\XeTeXlinebreaklocale "zh" %這兩行一定要加,中文才能自動換行
\XeTeXlinebreakskip = 0pt plus 1pt %這兩行一定要加,中文才能自動換行
\defaultCJKfontfeatures{AutoFakeBold=6,AutoFakeSlant=.4} %以後不用再設定粗斜
\newCJKfontfamily\Kai{標楷體} %定義指令\Kai則切換成標楷體
\newCJKfontfamily\Hei{微軟正黑體} %定義指令\Hei則切換成正黑體
\newCJKfontfamily\NewMing{新細明體} %定義指令\NewMing則切換成新細明體
@iamalbert
iamalbert / Assert.hpp
Last active June 5, 2022 04:51
C++ SMART ASSERT
#define __ASSERT1__(x) __REPORT__(x).__ASSERT2__
#define __ASSERT2__(x) __REPORT__(x).__ASSERT1__
#define __REPORT__(x) report(#x,(x))
#define ASSERT(cond, msg) if(!(cond)) Assert(#cond,msg,__FILE__,__LINE__).__ASSERT1__
#include <iostream>
struct Assert {
template<class T>
# Json Pretty Print
json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4)
# Json Print Entities instead of \uXXXX
json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4, ensure_ascii=True)
-- in global scope
if not ... then
print "main"
else
print "library"
end
[[
$ luajit test.lua
@iamalbert
iamalbert / test.lua
Created August 31, 2016 09:11
lua coroutine vs plain loop
require 'sys'
local n = 100000
local seq = {}
for i = 1, n do seq[i] = i end
local bs = 405
local plainLoop = function()
local yield = {}
for i = 1, #seq do
@iamalbert
iamalbert / normalizeText.py
Created September 29, 2016 08:43
normalize_text
FULL2HALF = {
r' ' : r' ', # full space and halfspace
r'!' : r'!', r'"' : r'"', r'#' : r'#', r'$' : r'$', r'%' : r'%',
r'&' : r'&', r''' : r"'", r'(' : r'(', r')' : r')', r'*' : r'*',
r'+' : r'+', r',' : r',', r'-' : r'-', r'.' : r'.', r'/' : r'/',
r'0' : r'0', r'1' : r'1', r'2' : r'2', r'3' : r'3', r'4' : r'4',
r'5' : r'5', r'6' : r'6', r'7' : r'7', r'8' : r'8', r'9' : r'9',
r':' : r':', r';' : r';', r'<' : r'<', r'=' : r'=', r'>' : r'>',
r'?' : r'?', r'@' : r'@', r'A' : r'A', r'B' : r'B', r'C' : r'C',
r'D' : r'D', r'E' : r'E', r'F' : r'F', r'G' : r'G', r'H' : r'H',
@iamalbert
iamalbert / argparse.py
Last active October 25, 2016 05:57
Python Collection
#!/usr/bin/env python3
import argparse
import json
import sys
import collections
import itertools
def main(args):
pass
import torch
from torch.autograd import Variable as V
import numpy as np
a = V( torch.from_numpy( np.asarray([1.112]) ) ).float()
b = V( torch.rand(1) )
c = a + b
@iamalbert
iamalbert / util.py
Last active July 5, 2017 06:43
python utilities
# get dir of current file
import os
this_path = os.path.dirname(os.path.realpath(__file__))
@iamalbert
iamalbert / util.vim
Created May 15, 2017 06:04
vim commands
" convert \xHHHH into Unicode character.
:%s#\\x\([0-9a-f]\{4\}\)#\=nr2char(str2nr(submatch(1),16))#g