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
@cloudwu
cloudwu / sslice.c
Last active November 5, 2015 10:13
make string to slices
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct sslice {
const char *ptr;
size_t sz;
};
int
@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
@tevino
tevino / n2n_v2_osx_fix.diff
Created March 27, 2014 02:10
This fix an error about the function `tun_close` in n2n_v2(r7394 tested) when compiling on OS X
If you see the error message below, you may need this patch:
Undefined symbols for architecture x86_64:
"_tun_close", referenced from:
_tuntap_open in n2n.a(tuntap_osx.o)
ld: symbol(s) not found for architecture x86_64
# How to use
If you got the source code from official repository, like me:
svn co https://svn.ntop.org/svn/ntop/trunk/n2n
@cypres
cypres / iconv-test.cpp
Created September 16, 2011 11:03
iconv convert
#include <iostream>
#include <iconv.h>
#include <stdlib.h>
#include <string.h>
#include <sys/errno.h>
using namespace std;
char *
convert(const char *from_charset, const char *to_charset, const char *input) {
size_t inleft, outleft, converted = 0;
@philchristensen
philchristensen / svn-color.py
Created August 10, 2010 20:20
Color-Coded `svn status`

First there was: http://snipplr.com/view/15246/color-coded-svn-status

Then there was: http://snipplr.com/view/16540/color-coded-svn-status-v2

A few days ago, I found a handy script online that colorized the output of SVN status. It worked pretty well, but needed a little polish and a couple of tweaks to make it use more common Python idioms. As I continued to use it and fix bugs and inefficiencies, I ended up replacing nearly every line in the original, but it was still a great starting point.

Additional changes include ANSI word-wrapping, a configurable tab expansion feature (for better code alignment), the 'colorizedSubcommands' sequence so that only applicable commands get colorized, use of proper subprocess module calls so that piping through less will work (for example, try svn-color diff | less -r to see colorized diff output).

To use, stick it somewhere, make executable (`chmod 7

@daurnimator
daurnimator / fengari-vue.lua
Last active June 17, 2021 11:43
Playing with Vue from fengari
-- Load Vue library
package.loadlib("https://cdn.jsdelivr.net/npm/vue@2.5.13/dist/vue.js", "*")
-- Get Object helper
local Object = dofile("https://gist.githubusercontent.com/daurnimator/5a7fa933e96e14333962093322e0ff95/raw/8c6968be0111c7becc485a692162ad100e87d9c7/Object.lua").Object
local myapp = js.new(js.global.Vue, Object{
el = "#foo";
template = [[
<div id="foo">{{message}}</div>
]];
@cloudwu
cloudwu / mq.c
Last active July 12, 2021 09:00
concurrence fifo queue
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define QSZ (1 << 10)
#define QMSK (QSZ - 1)
struct queue {
volatile uint32_t head;
adb kill-server
adb connect 127.0.0.1:53001
local DIRSEP = package.config:sub(1, 1)
local function is_readable(filename)
local fd = io.open(filename, "r")
if fd then
fd:close()
return true
else
return false
end
@paulodeleo
paulodeleo / .tmux.conf
Last active July 15, 2022 10:16
Tmux configuration to enable mouse scroll and mouse panel select, taken from: http://brainscraps.wikia.com/wiki/Extreme_Multitasking_with_tmux_and_PuTTY
# Make mouse useful in copy mode
setw -g mode-mouse on
# Allow mouse to select which pane to use
set -g mouse-select-pane on
# Allow mouse dragging to resize panes
set -g mouse-resize-pane on
# Allow mouse to select windows