Skip to content

Instantly share code, notes, and snippets.

View cuiwm's full-sized avatar
🎯
Focusing

cuiwm cuiwm

🎯
Focusing
  • UK
View GitHub Profile
@cuiwm
cuiwm / Makefile
Created March 1, 2017 02:52 — forked from kwk/Makefile
Compiling with Address Sanitizer (ASAN) with CLANG and with GCC-4.8
.PHONY: using-gcc using-gcc-static using-clang
using-gcc:
g++-4.8 -o main-gcc -lasan -O -g -fsanitize=address -fno-omit-frame-pointer main.cpp && \
ASAN_OPTIONS=symbolize=1 ASAN_SYMBOLIZER_PATH=$(shell which llvm-symbolizer) ./main-gcc
using-gcc-static:
g++-4.8 -o main-gcc-static -static-libstdc++ -static-libasan -O -g -fsanitize=address -fno-omit-frame-pointer main.cpp && \
ASAN_OPTIONS=symbolize=1 ASAN_SYMBOLIZER_PATH=$(shell which llvm-symbolizer) ./main-gcc-static
@cuiwm
cuiwm / tcp_status.sh
Created May 3, 2017 10:11
veiw all tcp connection's status
netstat -n |awk '/^tcp/{++s[$NF]} END {for (i in s) print i, s[i]}'
@cuiwm
cuiwm / watchdog.sh
Created May 13, 2017 09:11
watchdog.sh
#!/bin/sh
while [ true ] ; do
CNT=`ps -ef|grep "gclient.py sync" |grep -v grep |wc -l`
echo "gclient:" $CNT
if [[ $CNT -lt 1 ]] ; then
echo "gclient exit"
--[[ config
root = "./"
listen = "127.0.0.1:8786"
redisaddr = "127.0.0.1:6379[1]"
dbfile = root .. "backup.db"
thread = 4
logger = nil
harbor = 1
//check whether the peer has close the socket connection
//netstat -antp check the rev message queue
struct pollfd pfd[1];
pfd[0].fd = socket_fd;
pfd[0].events = POLLRDHUP;
int ret = poll(pfd, 1, 0);
if (ret > 0) {
LG_DBG("poll detect RDHUP ret:%d", ret);
}
@cuiwm
cuiwm / .ssh_config_for_git
Created June 6, 2017 08:27
使用于github或者是局域网中git服务器
~$ cd ~/.ssh/
~$ touch config
在.ssh目录下创建一个config文件,输入如下内容:
Host github.com
User xxx@163.com (你注册github时的邮箱,这里使用注册的用户名也行)
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443
@cuiwm
cuiwm / calc_macro_args_count.h
Created June 7, 2017 04:32
如何计算macro宏参数的个数
from msgpack-c
# /* MSGPACK_PP_VARIADIC_SIZE */ 20 #
21 # if MSGPACK_PP_VARIADICS
22 # if MSGPACK_PP_VARIADICS_MSVC 23 # define MSGPACK_PP_VARIADIC_SIZE(...) MSGPACK_PP_CAT(MSGPACK_PP_VARIADIC_SIZE_I(__VA_ARGS__, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,),)
24 # else
25 # define MSGPACK_PP_VARIADIC_SIZE(...) MSGPACK_PP_VARIADIC_SIZE_I(__VA_ARGS__, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,)
26 # endif
27 # define MSGPACK_PP_VARIADIC_SIZE_I(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e
@cuiwm
cuiwm / print_string_iostream.cpp
Created June 7, 2017 07:35
print string with iostream cout
void print(std::string const& buf) {
| 63 for (std::string::const_iterator it = buf.begin(), end = buf.end();
| 64 it != end;
- 65 ++it) {
2 66 std::cout
2 67 << std::setw(2)
2 68 << std::hex
2 69 << std::setfill('0')
2 70 << (static_cast<int>(*it) & 0xff)
2 71 << ' ';
@cuiwm
cuiwm / choe_gdb_command.txt
Last active June 8, 2017 03:31
gdb useful command
from :https://blogs.oracle.com/ksplice/8-gdb-tricks-you-should-know
break WHERE if COND
(gdb) break context_switch if next == init_task
(gdb) command 1
Type commands for when breakpoint 1 is hit, one per line.
End with a line saying just "end".
>print addr
>print len
>print prot
>end
# no 'window' size, we can scroll
set height 0
set width 0
# allow pending breakpoints, we know what we're doing:
# > Function "foobar" not defined. Breakpoint 9 (foobar) pending.
# means that there is no "foobar" *currently loaded*, but maybe
# you know it will appear later
set breakpoint pending on