Skip to content

Instantly share code, notes, and snippets.

View yunyyyun's full-sized avatar
🤩

mengyun yunyyyun

🤩
View GitHub Profile
@yunyyyun
yunyyyun / HumpNaming.lua
Created May 27, 2017 07:45
将字符串里的中文(utf-8)转为驼峰格式拼音
------------------------------chinesePhoneticData.lua
local hash = {};
hash = {
["中"] = "Zhong";
["国"] = "Guo";
["股"] = "Gu";
["票"] = "Piao";
["名"] = "Ming";
["称"] = "Cheng";
@yunyyyun
yunyyyun / table2string
Created May 27, 2017 07:58
把table转string,字符串结果可直接反过来load成table
table.tostring = function(t)
if t==nil then
return "error,print table is nil!"
end
local assign={}
local function ser_table(tbl,parent)
local tmp={}
for k,v in pairs(tbl) do
local key= type(k)=="number" and "["..k.."]" or "[".. string.format("%q", k) .."]"
if type(v)=="table" then
@yunyyyun
yunyyyun / Base64.lua
Last active August 10, 2017 02:38
Base64 encode/decode
--base64加密
function base64_encode(data)
local base64Table='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
return ((data:gsub('.', function(x)
local r,b='',x:byte()
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
return r;
end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
if (#x < 6) then return '' end
local c=0
@yunyyyun
yunyyyun / hash.lua
Last active August 23, 2017 07:21
一种均匀散列方法(hash)
g_HashTable = 0
--创建hash表
function createHashTable()
local tb = {};
local _insert = function(k,v)
if k==0 then
k=1;
end
for i = k,k+999,1 do
if i>1000 then