Skip to content

Instantly share code, notes, and snippets.

@yangacer
yangacer / evreq.c
Created May 2, 2011 13:33
Send request via evhttp (1.4)
void onCompleted(evhttp_request *req, void* arg)
{
fprintf(stderr, "Request completed\n");
fwrite(req->input_buffer->buffer, 1, req->input_buffer->off, stderr);
fprintf(stderr, "\n");
}
int main(int argc, char **argv)
{
char const *address = argv[1];
@yangacer
yangacer / extract_link.cpp
Created June 26, 2011 15:07
Extract link from HTML using RE2
@yangacer
yangacer / icu-detect.cpp
Created July 6, 2011 14:11
ICU charset detection
// compile with g++ icu-detect.cpp -I /usr/local/include -L /usr/local/lib -licuuc -licudata -licui18n
#include <cstdio>
#include <string>
#include <cassert>
#include "unicode/ucsdet.h"
#include "unicode/uclean.h"
int main(int argc, char **argv)
{
using namespace std;
@yangacer
yangacer / icu_converter.cpp
Created July 7, 2011 07:39
ICU converter for GB to UTF8
/****************
* Acer Yang, GAIS Laboratory, Univ. CCU, Taiwan.
*
* g++ -I/usr/local/include -L/usr/local/lib unicode-convert.cpp -licui18n -o uconv
* ./uconv input file charset_name
*
********/
#include "unicode/ucnv.h"
@yangacer
yangacer / gprof2callgraph_abbr.sh
Created August 5, 2011 16:39
generate program profile with callgraph
#!/bin/sh
# Dependencies:
# 1. gprof
# 2. gprof2dot
# 3. c++filt
# 4. dot (/usr/ports/x11-fonts/urwfonts)
help="profcg.sh executable output"
@yangacer
yangacer / newline_array_src.cpp
Created August 16, 2011 17:33
boost iostreams newline filter and array source
/**
* FreeBSD 8.2
* g++ -I /usr/local/include newline_array_src.cpp
**/
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/newline.hpp>
#include <boost/iostreams/device/array.hpp>
#include <string>
#include <cstring>
@yangacer
yangacer / hash_map.cpp
Created October 21, 2011 12:26
hash_map shapshot
int main()
{
using namespace std;
using namespace BDB;
using BDB::Structure::HashMap;
Config conf;
conf.beg = 1;
conf.end = 10;
conf.root_dir = argv[1];
@yangacer
yangacer / cppdebug.cpp
Created November 28, 2011 14:10
C++ debug util
#include <iostream>
#define CERR std::cerr << __FILE__ << ":" << \
std::dec << __LINE__ << ":" <<__FUNCTION__ << "() : "
@yangacer
yangacer / gcc_exclude_clang.h
Created August 11, 2012 15:01
Detect gcc (exclude clang)
#if defined(__GNUC__) && !defined(__clang__)
#define GNUC_EXCLUDE_CLANG
#else
#undef GNUC_EXCLUDE_CLANG
#endif
@yangacer
yangacer / gcc_demangling.hpp
Created August 11, 2012 15:05
gcc demangling
#include <typeinfo>
#include <memory>
#ifdef __GNUC__
#include <cxxabi.h>
template<typename T>
struct getname
{
std::string operator()()