Skip to content

Instantly share code, notes, and snippets.

View fseasy's full-sized avatar
🍉
seize-the-moment

Wei Xu fseasy

🍉
seize-the-moment
  • surreal
  • Toronto
  • 14:27 (UTC -04:00)
View GitHub Profile
# -*- coding: utf-8 -*-
"""when not package style, use sys path to easily append
"""
import sys
import pathlib
import contextlib
def _rel2abs(rel_path):
_dir_abs_path = pathlib.Path(__file__).absolute().parent
@fseasy
fseasy / add2handler4root_logger.py
Created December 9, 2017 12:20
为root logger添加两个handler,同时输出到屏幕和文件!
#!/usr/bin/env python
# -*- coding: gb18030 -*-
import logging
def test_logging():
"""test logging
add 2 handler for root logger!
"""
# config
@fseasy
fseasy / naive_shell_interface.py
Created December 2, 2017 12:39
在python中使用shell命令,包括同步、异步调用,支持with语句,哈哈
#!/usr/bin/env python2
# -*- coding: gb18030 -*-
"""
naive shell interface
"""
import subprocess
import logging
import multiprocessing
@fseasy
fseasy / is_line_num_equal.sh
Created September 1, 2017 11:44
判断各个文件行数是否一致!!! 非常重要,因为这个问题接连出了两个BUG!!
!/bin/sh
function is_line_num_equal()
{
if [ $# -eq 0 ];then
return 0
fi
line_cnt="`wc -l $1 | awk -F" " '{print $1}'`"
shift
while [ $# -ne 0 ]; do
@fseasy
fseasy / rpc.md
Created February 3, 2017 03:08
RPC框架

发现

今天无聊看了下微信PC端的文件,主要是想看UI是如何实现的。在文件列表里,竟然看到了 protobuf ,真是大吃一惊啊。然后又看到了qb_core.dll, 我想这个大概跟UI有关,于是搜索了下,发现原来是 QQBrowder 的组件。那么GUI似乎就很明显了——基于HTML + 浏览器核心的实现,类似Electron.

试着搜索了下实现,发现了一篇文章: 微信开源C/C++ RPC框架PhxRPC 于是了解到了这个名词。

是什么

@fseasy
fseasy / md5sum.py
Created January 16, 2017 11:53
md5sum a file.
# http://stackoverflow.com/questions/3431825/generating-an-md5-checksum-of-a-file
import hashlib
def md5sum(filename, blocksize=65536):
hash = hashlib.md5()
with open(filename, "rb") as f:
for block in iter(lambda: f.read(blocksize), b""):
hash.update(block)
return hash.hexdigest()
@fseasy
fseasy / rm.sh
Created December 22, 2016 06:37
将系统的rm命令重命名为move
# change `rm` to `move`
mkdir -p ~/.trash
alias rm=trash
alias r=trash
alias rl='ls ~/.trash'
alias ur=undelfile
undelfile()
{
mv -i ~/.trash/\$@ ./
# change it's name to .tmux.conf
#
# author : Xu Xiaodong <[email protected]>
# modified : 2015 May 10
#
#-- base settings --#
set -g default-terminal "screen-256color"
set -g display-time 3000
set -g escape-time 0
@fseasy
fseasy / segment_tree_recursively.cpp
Created August 20, 2016 08:05
segment tree 递归构建版
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class SumSegmentTree
{
public:
SumSegmentTree(const vector<int> &rawData)
@fseasy
fseasy / findMinForSortedArrayWithDuplicates.cpp
Created August 6, 2016 07:24
在包含重复值的旋转数组中找最小值。
class Solution {
public:
int findMin(vector<int>& nums) {
if(nums.size() == 0){ return 0; }
int low = 0,
high = nums.size() - 1;
while(low < high)
{
int mid = low + (high - low) / 2 ;
if(nums[mid] < nums[high])