Skip to content

Instantly share code, notes, and snippets.

View hanxi's full-sized avatar
:octocat:
Happy Coding!!!

涵曦 hanxi

:octocat:
Happy Coding!!!
View GitHub Profile
@hanxi
hanxi / packfloat.c
Created January 29, 2015 08:03
pack and unpack float
#include <stdio.h>
#include <inttypes.h>
static uint64_t pack754(long double f, uint8_t bits, uint8_t expbits)
{
long double fnorm;
int shift;
uint64_t sign;
uint64_t exp;
uint64_t significand;
@hanxi
hanxi / HXProtHandler.lua
Created August 26, 2013 06:35
单消息多处理函数的实现.注册消息处理函数时可提供优先执行函数列表(即在优先执行函数列表中的函数先于正在注册的函数).
--[[=============================================================================
# FileName: HXProtHandler.lua
# Desc: 单个消息多个处理函数带有优先级的实现
# Author: hanxi
# Email: hanxi.com@gmail.com
# HomePage: http://hanxi.cnblogs.com
# Version: 0.0.1
# LastChange: 2013-08-26 11:42:37
# History: 添加优先级冲突检测
=============================================================================]]
@hanxi
hanxi / point_to_menber_func.cpp
Created August 31, 2013 17:02
类成员函数指针指向类成员
#include <iostream>
using namespace std;
class A {
public:
A() {
q=&A::funcA;
cout << "q=" << q << endl;
//(this ->* ((A*)this)->A::q) ();
@hanxi
hanxi / deepcopy.lua
Created September 29, 2013 03:55 — forked from Deco/deepcopy.lua
--[[ deepcopy.lua
Deep-copy function for Lua - v0.2
==============================
- Does not overflow the stack.
- Maintains cyclic-references
- Copies metatables
- Maintains common upvalues between copied functions (for Lua 5.2 only)
TODO
#include "lua.h"
#include "lauxlib.h"
#include <stdio.h>
int
dylib_add(lua_State* L) {
int a = lua_tonumber(L,1);
int b = lua_tonumber(L,2);
int c = a+b;
@hanxi
hanxi / util.py
Last active September 13, 2018 03:35
Python Dump
static void PrintRefCnt(const char *s, PyObject *obj)
{
printf("PrintRefCnt:%s.%ld\n", s, (long)(obj->ob_refcnt));
}
static void DumpPyObject(const char *s, PyObject *obj)
{
PyObject *str = PyObject_Str(obj);
printf("DumpPyObject:%s.%s\n", s, PyString_AsString(obj));
Py_DECREF(str);
@hanxi
hanxi / lru.lua
Last active November 30, 2018 05:31
用 Lua 实现 LRU
local lru = {}
local lru_mt = { __index = lru }
local function addnode(self, node)
local head = self._head
node._next = head
if head then
head._pre = node
end
self._head = node
@hanxi
hanxi / dracula.minttyrc
Created January 17, 2019 07:27
mintty color to putty color
ForegroundColour=248,248,242
BackgroundColour=40,42,54
Black=0,0,0
BoldBlack=104,104,104
Red=255,85,85
BoldRed=255,110,103
Green=80,250,123
BoldGreen=90,247,142
Yellow=241,250,140
BoldYellow=244,249,157
function! SearchRoot()
let l:scm_list = ['.root', '.svn', '.git']
for l:item in l:scm_list
let l:dirs = finddir(l:item, '.;', -1)
if !empty(l:dirs)
return fnamemodify(l:dirs[-1].'/../', ':p:h')
endif
endfor
return getcwd()
endfunction
function! s:gen_tags_find(cmd, keyword) abort
" Mark this position
execute "normal! mY"
" Close any open quickfix windows
cclose
" Clear existing quickfix list
cal setqflist([])
let l:cur_buf=@%
let l:cmd = 'cs find ' . a:cmd . ' ' . a:keyword