Skip to content

Instantly share code, notes, and snippets.

View ki7chen's full-sized avatar
🎯
Focusing

Johnnie ki7chen

🎯
Focusing
  • Ubisoft
  • Chengdu
View GitHub Profile
@ki7chen
ki7chen / gcdata.go
Created March 16, 2024 12:48
print golang type gcdata
func TestAABB(t *testing.T) {
t.Logf("size of map = %d", unsafe.Sizeof(map[int]int{}))
var a any = gsdb.DbUser{}
var typ = reflectutil.TypeOf(a)
var n = (int(typ.PtrBytes)/8 + 7) / 8
var sb strings.Builder
var ones = 0
for i := 0; i < n; i++ {
var ptr = unsafe.Add(unsafe.Pointer(typ.GCData), i)
var v = *(*uint8)(ptr)
@ki7chen
ki7chen / go-env-with-msys2.md
Created December 8, 2022 08:56 — forked from glycerine/go-env-with-msys2.md
Go development environment on Windows with MSYS2

Go development environment on Windows with MSYS2

Normally, it is sufficient to grab the Go MSI installer from the website in order to set up the toolchain. However, some packages that provide Go wrappers for C libraries rely on cgo tool, which in turn, needs the GCC toolchain in order to build the glue code. Also, 3rd-party dependencies are usually hosted on services like GitHub, thus Git is also needed. This mini-guide illustrates how to setup a convenient development environment on Windows using MSYS2.

import xlrd
import openpyxl
# 读取指定xls文件的某一个sheet
def read_workbook_sheet_to_rows(filename: str, sheet_name: str):
print('load workbook', filename)
if filename.endswith('.xls'):
return __xlrd_read_workbook_sheet_to_rows(filename, sheet_name)
@ki7chen
ki7chen / bigdigit.go
Created August 26, 2015 07:51
print big digit
package main
import (
"fmt"
"os"
"path/filepath"
)
var print = fmt.Println
@ki7chen
ki7chen / isNumber.c
Created May 14, 2015 09:30
Validate if a given string is numeric
// Validate if a given string is numeric.
// https://leetcode.com/problems/valid-number/
bool isNumber(const char* s)
{
if (s == NULL)
{
return false;
}
@ki7chen
ki7chen / poco_jni.cpp
Created December 10, 2014 07:44
poco http for jni
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class tutorial_myfirstapp_MainActivity */
#ifndef _Included_tutorial_myfirstapp_MainActivity
#define _Included_tutorial_myfirstapp_MainActivity
#ifdef __cplusplus
extern "C" {
#endif
/*
@ki7chen
ki7chen / coroutine_socket.lua
Last active August 29, 2015 14:10
coroutine based http download
local socket = require 'socket'
local coroutine = coroutine
local threads = {}
local function receive(connection)
connection:settimeout(0)
local s, status, partial = connection:receive(2^10)
if status == 'timeout' then
@ki7chen
ki7chen / prod_con.lua
Created November 29, 2014 09:56
lua coroutine producer/consumer
local coroutine = coroutine
local function receive(p)
local s, value = coroutine.resume(p)
return value
end
local function send(x)
coroutine.yield(x)
end
-- map(table, function)
-- e.g: map({1,2,3}, function(a) return a*2 end) -> {2,4,6}
function map(tbl, func)
local newtbl = {}
for i,v in pairs(tbl) do
newtbl[i] = func(v)
end
return newtbl
end
@ki7chen
ki7chen / zmq_curve.cpp
Created November 23, 2014 04:46
zmq curve server and client
#include <assert.h>
#include <stdint.h>
#include <string>
#include <iostream>
#include <thread>
#include <chrono>
#include <zmq.h>
#include <zmq_utils.h>