Skip to content

Instantly share code, notes, and snippets.

View shi-yan's full-sized avatar
💭
keyboard smashing

Shi Yan shi-yan

💭
keyboard smashing
View GitHub Profile
@shi-yan
shi-yan / keepalive
Created September 17, 2014 23:36
Correct way to set tcp socket keepalive on Win, Mac and Linux. Verified with Wireshark.
void setTcpKeepalive(SOCKET &sockfd)
{
const uint32_t keepaliveIntervalSec = 10;
#ifdef _WIN32
tcp_keepalive keepaliveParams;
DWORD ret = 0;
keepaliveParams.onoff = 1;
keepaliveParams.keepaliveinterval = keepaliveParams.keepalivetime = keepaliveIntervalSec * 1000;
WSAIoctl(sockfd, SIO_KEEPALIVE_VALS, &keepaliveParams, sizeof(keepaliveParams), NULL, 0, &ret, NULL, NULL);
@shi-yan
shi-yan / protobuf_qt
Last active August 9, 2022 14:32
Build Protobuf files as a prebuild step of qmake (support protobuf in Qt)
#both protopath and protos need to use the relative path.
#otherwise you will see this protobuf compiler message:
#You must specify a --proto_path which encompasses this file. Note that the proto_path must be an exact prefix
#of the .proto file names -- protoc is too dumb to figure out when two paths
# (e.g. absolute and relative) are equivalent (it's harder than you think).
PROTOPATH += ../../../../common/protocols/protos #this is the folder contains *.proto
PROTOPATHS =
for(p, PROTOPATH):PROTOPATHS += --proto_path=$${p}
PROTOS += ../../../../common/protocols/protos/xxx.proto #the actual *.proto files need to be compiled.
@shi-yan
shi-yan / build_webrtc
Last active August 29, 2015 14:08
Build native webrtc project
The webrtc build instruction is very shitty in my opinion. It has way too much confusing information that is unrelated to webrtc.
here are the steps I went through to build it on ubuntu:
1. install tools:
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
$ export PATH=`pwd`/depot_tools:"$PATH"
2. sync code:
gclient config --name src http://webrtc.googlecode.com/svn/trunk
@shi-yan
shi-yan / sawp_keys
Created November 4, 2014 05:25
Swap the Ctrl and the Windows key under ubuntu
I'm so used to Mac key mapping that I want to use the windows key as the ctrl, and the ctrl as the windows key.
I found a very useful link here:
http://stackoverflow.com/questions/21845209/remap-ctrl-alt-super-keys-in-ubuntu-13-10
first run this to generate the keymap
xmodmap -pke > ~/.Xmodmap.
open .Xmodmap file, add these at the beginning:
clear control
@shi-yan
shi-yan / SYMOPT_LOAD_ANYTHING
Created December 3, 2014 23:55
Force loading debug symbols with windbg
Force loading debug symbols (for example, mismatched simbols) with windbg:
.symopt+0x40
This command enables SYMOPT_LOAD_ANYTHING option.
Details are here: http://seclib.blogspot.com/2005/07/force-windbg-to-load-symbols.html
@shi-yan
shi-yan / chromium_with_h264
Created March 27, 2015 21:51
build chromium with h264 codec
chromium/src$ export GYP_DEFINES="proprietary_codecs=1 ffmpeg_branding=Chrome"
chromium/src$ build/gyp_chromium
X: 1
T: Crunchy Crunchy Apple Chips
M: 4/4
L: 1/8
Q:1/4=180
K:D % 2 sharps
C:Stewie Yan
O:San Jose CA
N:Generated with AI
df df Af e2| \
@shi-yan
shi-yan / caffe_build
Created October 12, 2016 03:24
Build Caffe on Ubuntu 16 with Cuda 8
Building Caffe on Ubuntu 16 with Cuda 8.0 wasn't smooth for me.
I googled, many people saw the same problem. I want to briefly document what I did to build Caffe.
symptoms, you might see errors like this, this is because of gcc 5.
a new feature added to gcc5 called abi_tag will cause problems like this:
https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html
@shi-yan
shi-yan / tricks
Last active October 25, 2016 19:23
Useful tricks
check symbol:
http://stackoverflow.com/questions/34732/how-do-i-list-the-symbols-in-a-so-file
nm -g yourLib.so
nm -gC yourLib.so
debug dlopen
http://stackoverflow.com/questions/34415168/dlopen-returns-with-file-not-found-although-file-exist
export LD_DEBUG=all
let gdb break into a program with ctrl-c
@shi-yan
shi-yan / gist:6fa8aeea3d04f1b149f46ff725408d28
Last active January 14, 2017 21:46 — forked from giosakti/gist:3027026
[Git] Fetch & merge upstream/downstream repo
downstream github
git remote add <upstream>/<repo> ssh://git@bitbucket.org/<upstream>/<repo>.git
git fetch <upstream>/<repo>
git checkout master
git merge remotes/<upstream>/<repo>/master
sync submodules
git submodule update --init --recursive