http://rdc.taobao.com/blog/cs/?cat=11
整理過版本
http://storage.it168.com/a2009/1013/757/000000757579_all.shtml
裡面用蠻淺顯的例子描述如何從關聯式變成非關聯的過程…
http://rdc.taobao.com/blog/cs/?cat=11
整理過版本
http://storage.it168.com/a2009/1013/757/000000757579_all.shtml
裡面用蠻淺顯的例子描述如何從關聯式變成非關聯的過程…
在 linux 更新成 Python 2.7 後進入他 shell 以後發現,按上下鍵想要查尋歷史紀錄竟然只出現 ^[[A ,這些符號…感覺有點糟糕…
找了許多才發現原來是少安裝一個函式庫,不曉得是 readline 還是 ncureses ,管他的都裝…= =
ncureses 是一個提供在文字介面操作的 API 函式庫。應該跟文字介面上下左右事件監控有關。
yum install ncurses yum install ncurses-devel easy_install readline
ncurses 似乎還蠻有趣的,linux kernel menu config 好像就是用他寫的…
網路[3]上看到一個範例可以跑跑看…
#include <curses.h>
#include <stdlib.h>
#define ENTER 10
#define ESCAPE 27
void init_curses()
{
initscr();
start_color();
init_pair(1,COLOR_WHITE,COLOR_BLUE);
init_pair(2,COLOR_BLUE,COLOR_WHITE);
init_pair(3,COLOR_RED,COLOR_WHITE);
curs_set(0);
noecho();
keypad(stdscr,TRUE);
}
void draw_menubar(WINDOW *menubar)
{
wbkgd(menubar,COLOR_PAIR(2));
waddstr(menubar,"Menu1");
wattron(menubar,COLOR_PAIR(3));
waddstr(menubar,"(F1)");
wattroff(menubar,COLOR_PAIR(3));
wmove(menubar,0,20);
waddstr(menubar,"Menu2");
wattron(menubar,COLOR_PAIR(3));
waddstr(menubar,"(F2)");
wattroff(menubar,COLOR_PAIR(3));
}
WINDOW **draw_menu(int start_col)
{
int i;
WINDOW **items;
items=(WINDOW **)malloc(9*sizeof(WINDOW *));
items[0]=newwin(10,19,1,start_col);
wbkgd(items[0],COLOR_PAIR(2));
box(items[0],ACS_VLINE,ACS_HLINE);
items[1]=subwin(items[0],1,17,2,start_col+1);
items[2]=subwin(items[0],1,17,3,start_col+1);
items[3]=subwin(items[0],1,17,4,start_col+1);
items[4]=subwin(items[0],1,17,5,start_col+1);
items[5]=subwin(items[0],1,17,6,start_col+1);
items[6]=subwin(items[0],1,17,7,start_col+1);
items[7]=subwin(items[0],1,17,8,start_col+1);
items[8]=subwin(items[0],1,17,9,start_col+1);
for (i=1;i<9;i++)
wprintw(items[i],"Item%d",i);
wbkgd(items[1],COLOR_PAIR(1));
wrefresh(items[0]);
return items;
}
void delete_menu(WINDOW **items,int count)
{
int i;
for (i=0;i<count;i++)
delwin(items[i]);
free(items);
}
int scroll_menu(WINDOW **items,int count,int menu_start_col)
{
int key;
int selected=0;
while (1) {
key=getch();
if (key==KEY_DOWN || key==KEY_UP) {
wbkgd(items[selected+1],COLOR_PAIR(2));
wnoutrefresh(items[selected+1]);
if (key==KEY_DOWN) {
selected=(selected+1) % count;
} else {
selected=(selected+count-1) % count;
}
wbkgd(items[selected+1],COLOR_PAIR(1));
wnoutrefresh(items[selected+1]);
doupdate();
} else if (key==KEY_LEFT || key==KEY_RIGHT) {
delete_menu(items,count+1);
touchwin(stdscr);
refresh();
items=draw_menu(20-menu_start_col);
return scroll_menu(items,8,20-menu_start_col);
} else if (key==ESCAPE) {
return -1;
} else if (key==ENTER) {
return selected;
}
}
}
int main()
{
int key;
WINDOW *menubar,*messagebar;
init_curses();
bkgd(COLOR_PAIR(1));
menubar=subwin(stdscr,1,80,0,0);
messagebar=subwin(stdscr,1,79,23,1);
draw_menubar(menubar);
move(2,1);
printw("Press F1 or F2 to open the menus. ");
printw("ESC quits.");
refresh();
do {
int selected_item;
WINDOW **menu_items;
key=getch();
werase(messagebar);
wrefresh(messagebar);
if (key==KEY_F(1)) {
menu_items=draw_menu(0);
selected_item=scroll_menu(menu_items,8,0);
delete_menu(menu_items,9);
if (selected_item<0)
wprintw(messagebar,"You haven't selected any item.");
else
wprintw(messagebar,
"You have selected menu item %d.",selected_item+1);
touchwin(stdscr);
refresh();
} else if (key==KEY_F(2)) {
menu_items=draw_menu(20);
selected_item=scroll_menu(menu_items,8,20);
delete_menu(menu_items,9);
if (selected_item<0)
wprintw(messagebar,"You haven't selected any item.");
else
wprintw(messagebar,
"You have selected menu item %d.",selected_item+1);
touchwin(stdscr);
refresh();
}
} while (key!=ESCAPE);
delwin(menubar);
delwin(messagebar);
endwin();
return 0;
}
參考資源:
一個完整簡潔有力的學習專案,twissandra 用 django 與 cassandra 實作 twitter 最簡單重要的功能,有網頁介面。
此專案展示了 cassandra 資料模型的設計以及 API 的使用,又能大略學習 django 的簡單使用,安裝與運作又十分容易,
後端 API 是採用 high level api pycassa ,原先是 Thrift ,而透過 pycassa 做中介層,幫忙做一些控管讓資料存取更順暢。
資料來源
C++ 擴充函式庫。
Source http://sourceforge.net/projects/boost/files/boost/1.46.1/
$ ./bootstrap.sh $ ./bjam "-sTOOLS=gcc" "--includedir=/usr/include" "--libdir=/usr/lib/boost" install #如果有需要可以另外再 with 幾個 component #--with-filesystem --with-program_options --with-regex --with-serialization --with-system --with-thread $ g++ test.cpp -L/usr/lib/boost
//example
#include <boost/thread/thread.hpp>
#include <iostream>
void helloworld() {
std::cout << "Hello World!" << std::endl;
}
void main() {
boost::thread thrd(&helloworld);
thrd.join();
}
參考資源:
很久以前的一篇文章…庫存一下…
官方網站 http://www.aditus.nu/jpgraph/
使用2.2版 官方連結 http://hem.bredband.net/jpgraph2/jpgraph-2.2.tar.gz
src/jpgraph.php 內
6256行左右有 $txt = $this->langconv->Convert($txt,$this->font_family);
似乎是將簡體中文轉成 utf-8 而我網站內使用的是 utf-8 而且我用的是繁體中文,所以註解掉這行。
63行部份有定義字型的位置,我網站內使用的是Linux 而我又不是伺服器管理者動不到原先字型的目錄,所以將字型之置換於 jpgraph 安裝目錄下所以改成這樣。
if (!defined('TTF_DIR')) {
if (strstr( PHP_OS, 'WIN') ) {
$sroot = getenv('SystemRoot');
if( empty($sroot) ) {
$t = new ErrMsgText();
$msg = $t->Get(12,$file,$lineno);
die($msg);
}
else {
DEFINE('TTF_DIR', $sroot.'/fonts/'); //windows下的位置
}
} else {
DEFINE('TTF_DIR','/home/mlwmlw/www/jpgraph/'); //unix下的位置
}
}
JPG-CONFIG.INC
此檔控制一部分字型的選擇,內有此行定義繁體中文字型的字體
//JPG-CONFIG.INC
DEFINE('CHINESE_TTF_FONT','simhei.ttf');
可使用 FF_CHINESE aka FF_BIG5 不過這似乎此檔不是關鍵定義字型的部份,在網路上找到的文件選中文程式中設定都是 FF_SIMSUN,FS_BOLE
接著看 jpgraph_ttf.inc.php 注意此文件內的設定字體陣列,發現了 jpGraph 定義字型的關鍵程式,
我們要改的部份240行
//jpgraph_ttf.inc.php /* Chinese fonts */ FF_SIMSUN => array(FS_NORMAL =>'simsun.ttc', FS_BOLD =>'simhei.ttf', FS_ITALIC =>'', FS_BOLDITALIC =>'' ), FF_CHINESE => array(FS_NORMAL =>CHINESE_TTF_FONT, FS_BOLD =>'DFFN_M9.TTC', FS_ITALIC =>'', FS_BOLDITALIC =>'' ),
字型規則
FF_*** 選擇主要類別,FS 選擇字型,每個FF定義了每個字型的對應屬性,我將 CHINESE 內的 NORMAL 與 BOLD 放置了兩個我需要的字體,
之後程式在 SET_FONT 時就看要那個字體就應對著選擇 FF_CHINESE,[FS_NOMAL OR FS_BOLD]。
這樣在跑應該就能有中文了。