Skip to content

Instantly share code, notes, and snippets.

View starwing's full-sized avatar

Xavier Wang starwing

  • Chengdu
View GitHub Profile
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#define SHIFT (sizeof(unsigned)*CHAR_BIT)
#define RANGE_MAX (~0u)
#define CHAR_MASK ((1u<<CHAR_BIT)-1)
@starwing
starwing / .gitmodules
Last active November 14, 2019 08:59
Generate holidays for erlang
[submodule "holiday-cn"]
path = holiday-cn
url = https://github.com/NateScarlet/holiday-cn
@starwing
starwing / lfastlz.c
Last active September 7, 2019 10:20
Lua FastLZ binding
#define LUA_LIB
#include <lua.h>
#include <lauxlib.h>
#include "fastlz.h"
#include "fastlz.c"
#include <stdlib.h>
static int Lcompress(lua_State *L) {
Froum: http://www.colm.net/pipermail/ragel-users/2017-April/003473.html
I don't use Windows machines much also nowadays but I have a simple
solution that one without a Windows can also build ragel windows binary:
1. Login into https://gist.github.com/ (is GitHub pastebin service which
also provides Git repos at the same time) and type something and create an
empty gist.
2. Login into https://ci.appveyor.com (is a Windows CI service) with your
@starwing
starwing / huffman.c
Created January 14, 2019 07:21
Huffman coding convertion
#define _CRT_SECURE_NO_WARNINGS
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
/* 能处理的最大文件大小,在这种情况下,最大的霍夫曼编码也不可能超过
@starwing
starwing / luastate.c
Created November 29, 2017 14:28
luastate -- bind lua to lua.
#define LUA_LIB
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <assert.h>
#include <string.h>
#define LL_STATE_TYPE "lua.State"
@starwing
starwing / rbtree.c
Last active August 13, 2019 14:41
新写的红黑树……求轻喷……
#include <assert.h>
#include <stdlib.h>
#include <limits.h>
typedef struct rb_Node rb_Node;
struct rb_Node {
rb_Node *parent, *k[2];
unsigned size : sizeof(unsigned)*CHAR_BIT-1;
unsigned color : 1;
@starwing
starwing / tmux.conf
Last active December 16, 2017 07:21
My tmux configure file
# vim: nu et fdc=2 fdm=marker fmr={,}
# General {
# set prefix
set -g prefix "`"
unbind C-b
bind C-a last-window
bind "`" last-window
@starwing
starwing / cassowary.lua
Created June 14, 2016 08:06
the Cassowary layout constraint algorithm in pure Lua
local function meta(name, parent)
t = {}
t.__name = name
t.__index = t
return setmetatable(t, parent)
end
local function approx(a, b)
if a > b then return a - b < 1e-6 end
@starwing
starwing / lua_csv.c
Last active May 24, 2016 13:07
LuaCsv - a CSV reading/writting module for Lua language.
#ifdef _MSC_VER
# define _CRT_SECURE_NO_WARNINGS
#endif /* _MSC_VER */
#define LUA_LIB
#include <lua.h>
#include <lauxlib.h>
#if LUA_VERSION_NUM < 503
static int lua53_rawgeti(lua_State *L, int idx, lua_Integer n)
{ lua_rawgeti(L,idx,n); return lua_type(L,-1); }