Skip to content

Instantly share code, notes, and snippets.

View g10guang's full-sized avatar
🤑
Running On My Way

Liu XiGuang g10guang

🤑
Running On My Way
View GitHub Profile
@g10guang
g10guang / filco.shell
Created April 27, 2018 09:12
My Filco keyboard shell script to remap the key.
#!/bin/bash
setxkbmap -option caps:none
xmodmap -e "keycode 66 = End NoSymbol End NoSymbol End"
xmodmap -e "keycode 112 = BackSpace BackSpace BackSpace BackSpace"
@g10guang
g10guang / curl_check_ssl_version.cpp
Created August 14, 2018 10:58
Check ssl version libcurl use.
#include <iostream>
#include "curl/curl.h"
int main() {
curl_version_info_data* ver = curl_version_info(CURLVERSION_NOW);
std::cout << ver->ssl_version << std::endl;
return 0;
}
@g10guang
g10guang / multithread_http1_1_server.py
Last active August 20, 2018 11:55
Python3 HTTP/1.1 multithread server
from http.server import HTTPServer, BaseHTTPRequestHandler
from socketserver import ThreadingMixIn
class Handler(BaseHTTPRequestHandler):
protocol_version = 'HTTP/1.1'
def do_GET(self):
rsp = b'GET'
self.send_response(200)
self.send_header('Content-Length', len(rsp))
@g10guang
g10guang / beijing_time.md
Last active January 6, 2019 06:34
Python unix time and strftime convert
import time
from datetime import datetime
import pytz

In [14]: t = datetime.fromtimestamp(1546751128, pytz.timezone('Asia/Shanghai')).strftime('%Y-%m-%d %H:%M:%S')
In [15]: t
Out[15]: '2019-01-06 13:05:28'

show diff between edit file and disk file

:w !diff % -
@g10guang
g10guang / Frequency linux command.md
Last active February 14, 2019 12:11
Frequency linux command

find command with exclude

find -name "*.js" -not -path "./directory/*" -not -path "*thrift_gen/*"

remove duplicate column:

awk '!seen[$0]++' filename
@g10guang
g10guang / Google protobuf installation on Mac.md
Last active August 13, 2019 08:01 — forked from rajkrrsingh/Google protobuf installation on Mac
Steps to Install google protobuf on Mac
wget https://github.com/google/protobuf/releases/download/v2.5.0/protobuf-2.5.0.tar.bz2
tar xvf protobuf-2.5.0.tar.bz2
cd protobuf-2.5.0
./configure CC=clang CXX=clang++ CXXFLAGS='-std=c++11 -stdlib=libc++ -O3 -g' LDFLAGS='-stdlib=libc++' LIBS="-lc++ -lc++abi"
make -j 4 
sudo make install
protoc --version
@g10guang
g10guang / vm.py
Created September 16, 2019 05:31
A stupid virtual machine.
import enum
class Instruction(enum.Enum):
HLT = 0
ADD = 1
POP = 2
PSH = 3
SET = 4
Get = 5
JMP = 6
@g10guang
g10guang / derivce.cpp
Created September 23, 2019 12:19
Cpp virtual function testcase
#include <iostream>
using namespace std;
class Base1 {
public:
virtual void f() { cout << "Base1:f" << endl;}
virtual void g() { cout << "Base1::g" << endl;}
};
@g10guang
g10guang / typo.py
Last active September 24, 2019 11:50
Correct typo according to http://norvig.com/spell-correct.html
#%%
letter = 'abcdefghijklmnopqrstuvwxyz'
import requests, re, collections
# fetch the big.txt to calculate every words probability.
big_text = requests.get("http://norvig.com/big.txt").text
#use regex to match all words and then count their frequency
statistic = collections.Counter(re.findall("\w+", big_text))