NVI的应用-虚函数模板
我们有时候需要把一个模板函数实现为虚函数,但是C++不支持模板虚函数(至少目前是),所以需要一些方法绕过去。以下是郁白师兄提供的解决方案,确实比较巧妙,之前没想过NVI(NonVirtual Interface)能解决这个问题。
class IAllocator
{
public:
virtual ~IAllocator() {};
virtual void *alloc(const int64_t size) = 0;
};
template <class T>
class TAllocator : public IAllocator
{
public:
TAllocator(T &allocator) : allocator_(...
github/gitcafe pages域名设置
A纪录和CNAME
裸域名只能绑定 DNS 的 A 记录,不能绑定 CNAME 记录。也就是说你不能把裸域设定为另外域名的别名。很多时候这对管理不是很方便,特别是使用第三方托管服务的时候。如果第三方迁移服务器导致 IP 地址变更,你必须自己去更改 DNS 的 A 记录。引用自参考文献1
gitcafe pages 域名配置
example.com. 1684 IN A 117.79.146.98
www.example.com. 3581 IN CNAME example.gitcafe.com.
example.gitcafe.com. 560 IN A 117.79.146.98
gitcafe文档说:
如果你想绑定 www 子域名, 你需要将此 w...
关于一个配置项的设计
有个需求需要配置每张表的备份SQL语句,我开始想实现如下的效果:
struct TableBackupSQL
{
uint64_t table_id_;
const char* sql_;
const char * table_name_;
TableBackupSQL()
{
sql_ = NULL;
table_name_ = NULL;
table_id_ = OB_INVALID_ID;
}
TableBackupSQL(uint64_t table_id, const char* table_name, const char* sql)
{
sql_ = sql;
table_name_ = table...
同步github上的项目到gitcafe
github固然好,只是国内访问有点慢。为了提高博客访问速度我决定把github上托管的博客同步到gitcafe上。最好能在DNS那里做CDN,但是貌似没有免费的服务。那直接指向gitcafe好了,反正没有什么国外访问的需求。简单记一下过程。
gitcafe自己有导入的功能,但是貌似不是很好用。而且不够智能。所以我们先建立一个跟用户名一样的目录。gitcafe只允许这种方式的Html页面生成。并且只渲染gitcafe-pages分支。
我们修改source分支.git/config加入
[remote "cafe"]
url = [email protected]:xxx/xxx.git
fetch = +refs/heads/*:refs/remotes/cafe/*
...
git远程分支和refs文件详解
最近同时同步博客到github和gitcafe上,遇到一些问题,我们分如下几个方面来分析一下:
推送远程分支到同一个服务器
比如首先建立git服务器,顺便clone出两个副本
mkdir server
cd server
git init --bare
cd ..
git clone server git1
git clone server git2
目前git branch是空的。我们提交一点东西建立master分支。
cd git1
touch a.txt
git add .
git commit -m "init"
git push origin master
现在git branch -a 显示:
* master
remotes/origin/maste...
一个关于宏的问题
写了一段代码,我想实现宏里面拼接一个变量然后取得这个变量的值的效果,但是没有成功:
#define OB_FIRST_ROOT_TABLE_TID 21
#define OB_INVALID_ID INT_MAX
const char* OB_FIRST_ROOT_TABLE_TABLE_NAME = "__first_root_table";
struct TableBackupSQL
{
uint64_t table_id_;
const char* sql_;
const char * table_name_;
TableBackupSQL()
{
sql_ = NULL;
table_name_ = NULL;
table_i...
octopress代码着色
markdown有自己支持的代码模块,但是想支持着色,就需要单独对代码进行parse和加上css。octopress支持自己的代码语法,但是比较麻烦,并且是本地渲染,对不同语言需要指定。
所以还是js渲染比较方便一点,我们可以用google code prettify进行着色,在markdown里面只要对代码加入缩进(tab或者四个空格)。服务端引入如下js:
<link href="/javascripts/google-code-prettify/prettify.css" media="screen, projection" rel="stylesheet" type="text/css">
<script type="text/javascript" sr...
506 post articles, 64 pages.