Skip to content

Instantly share code, notes, and snippets.

@mawenbao
mawenbao / xhrFetchImg.js
Last active October 12, 2016 05:58
Fetch remote image with xhr
var url = 'https://static.mawenbao.com/images/cartoon/%E7%BB%88%E6%9C%AB%E7%9A%84%E4%BC%8A%E6%B3%BD%E5%A1%94.jpg';
var xhr = new XMLHttpRequest();
xhr.open('GET', url, false);
if (xhr.overrideMimeType) xhr.overrideMimeType('text/plain; charset=x-user-defined');
xhr.setRequestHeader("Content-Type", "application/octet-stream");
var txt = '';
function handle() {
if (this.readyState != null && (this.readyState < 3 || this.status != 200)) {
return
@mawenbao
mawenbao / merge-mmseg-dict.py
Last active August 29, 2015 14:06
合并两个mmseg词典
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# @author: mawenbao@hotmail.com
# @date: 2014-09-03
'''
将两个libmmseg中文词典合并为一个。
'''
import argparse
@mawenbao
mawenbao / extract-sougou-dict.py
Created September 4, 2014 05:27
从搜狗词库提取词组
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# @author: mawenbao@hotmail.com
# @date: 2014-09-03
# @depends: python2.7+
'''
从搜狗词库中提取中文词组
参考[这篇文章](http://blog.csdn.net/zhangzhenhu/article/details/7014271)中的代码实现。
@mawenbao
mawenbao / call_stack_example.txt
Last active August 29, 2015 14:00
part of the command `objdump -dS a.out -j .text` output with some comments, a.out is compiled from call_stack_example.cpp
int foo2(int a, long b, int c, int d, int e, int f, int g, int i) {
push %rbp // 将caller的%rbp入栈
mov %rsp,%rbp // 初始化callee的%rbp
mov %edi,-0x4(%rbp) // a: mem[R[rbp]-0x4] = R[edi]
// 暂存寄存器的值,使其可以被重用,使用-O选项可以优化掉这部分代码
mov %rsi,-0x10(%rbp) // b
mov %edx,-0x8(%rbp) // c
mov %ecx,-0x14(%rbp) // d
mov %r8d,-0x18(%rbp) // e
mov %r9d,-0x1c(%rbp) // f
@mawenbao
mawenbao / call_stack_example.cpp
Last active August 29, 2015 14:00
Simple example code for cpp call stack
int foo2(int a, long b, int c, int d, int e, int f, int g, int i) {
return a + b;
}
int foo(int &a, long b) {
int m = 1;
int o[3] = {0x1, 0x2, 0x3};
return foo2(0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x9);
}
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# @author: mawenbao@hotmail.com
# @date: 2014.04.25
# @desc: parse backtrace output
import re
import os
import sys
import subprocess
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
void print_stack_frames(int signum) {
int j, nptrs;
#define SIZE 100
void *buffer[100];
@mawenbao
mawenbao / Makefile
Created February 26, 2014 05:16
googletest simple example
# Makefile for gtest examples
GOOGLE_TEST_LIB = gtest
GOOGLE_TEST_INCLUDE = /usr/local/include
G++ = g++
G++_FLAGS = -c -Wall -I $(GOOGLE_TEST_INCLUDE)
LD_FLAGS = -L /usr/local/lib -l $(GOOGLE_TEST_LIB) -l pthread
OBJECTS = main.o string-compare.o
@mawenbao
mawenbao / pelicanconf.py
Last active August 29, 2015 13:56
My pelican configuration.
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals
import datetime
AUTHOR = u'Ma Wenbao'
SITENAME = u'MWB日常笔记'
SITEURL = 'http://blog.atime.me'
#SITEURL = 'http://localhost:8000'