2013-02-01

配置SublimeClang

在mac下开始cocos2d-x的程序,用不惯xcode。于是尝试用sublime+sublimeclang,sublimeclang要配置一下让clang能够找到头文件:

"options":
[
  "-DTARGET_OS_IPHONE",
    "-isystem", "$COCOS2DX_ROOT/cocos2d-x/cocos2dx",
    "-isystem", "$COCOS2DX_ROOT/cocos2d-x/cocos2dx/include",
    "-isystem", "$COCOS2DX_ROOT/cocos2d-x/cocos2dx/platform/ios",
    "-isystem", "$COCOS2DX_ROOT/cocos2d-x/cocos2dx/platform/third_party/ios",
    "-F", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks",
    "-I", "$COCOS2DX_ROOT/cocos2d-x/cocos2dx/kazmath/include",
    "-I", "$COCOS2DX_ROOT/cocos2d-x/CocosDenshion/include",
    "-isystem", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk"

]

2013-01-11

mac中使用rz,sz

我用的是iterm2,使用

brew install lrzsz
安装后,再按https://github.com/mmastrac/iterm2-zmodem 配置好iterm2-send-zmodem.sh , iterm2-recv-zmodem.sh这两个脚本就可以了。

2012-05-03

使用sublime text开发golang

最近有点空了,开始看看golang,已经1.0,感觉比较成熟了。然后正好在用sublime text,这个编辑器有一个不错的插件用来开发go:GoSublime。使用gosublime需要安装diff,否则保存时格式化会出错。

** GsFmt: File x.go contains errors **
diff可以到http://gnuwin32.sourceforge.net/packages/diffutils.htm下载。
另外我在windows上开发,但换行用的unix的(\n),结果格式化时又有错了:
** GsFmt: Could not patch the buffer: Contextual match failed **
这是插件的thatcher.py中对换行符没有处理,将38行的
px = re.compile(r'^([+][+][+]|[-][-][-]|[ ]|[@][@]|[+]|[-])(.*)$', re.MULTILINE)
改成
px = re.compile(r'^([+][+][+]|[-][-][-]|[ ]|[@][@]|[+]|[-])(.*?)\r?$', re.MULTILINE)
就可以了。

2012-04-13

安装gevent的错误

今天安装gevent 0.13.7,build的时候报错:


python2.6 setup.py build
running build
running build_py
running build_ext
building 'gevent.core' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/python/include/python2.6 -c gevent/core.c -o build/temp.linux-x86_64-2.6/gevent/core.o
gevent/core.c: In function ‘__pyx_pf_6gevent_4core_6reinit’:
gevent/core.c:5812: warning: implicit declaration of function ‘event_reinit’
gevent/core.c: In function ‘__pyx_pf_6gevent_4core_6buffer_1__len__’:
gevent/core.c:7159: warning: implicit declaration of function ‘EVBUFFER_LENGTH’
gevent/core.c: In function ‘__pyx_pf_6gevent_4core_6buffer_6read’:
gevent/core.c:7545: warning: implicit declaration of function ‘EVBUFFER_DATA’
gevent/core.c:7545: warning: cast to pointer from integer of different size
gevent/core.c:7591: warning: implicit declaration of function ‘evbuffer_drain’
gevent/core.c: In function ‘__pyx_pf_6gevent_4core_6buffer_7readline’:
gevent/core.c:7849: warning: cast to pointer from integer of different size
gevent/core.c: In function ‘__pyx_pf_6gevent_4core_6buffer_9write’:
gevent/core.c:8222: warning: implicit declaration of function ‘evbuffer_add’
gevent/core.c: In function ‘__pyx_pf_6gevent_4core_17http_request_base_6get_input_headers’:
gevent/core.c:9286: error: dereferencing pointer to incomplete type
gevent/core.c:9319: error: dereferencing pointer to incomplete type
gevent/core.c:9328: error: dereferencing pointer to incomplete type
gevent/core.c:9396: error: dereferencing pointer to incomplete type
gevent/core.c: In function ‘__pyx_pf_6gevent_4core_12http_request_3send_reply’:
gevent/core.c:12091: warning: implicit declaration of function ‘evbuffer_new’
gevent/core.c:12091: warning: assignment makes pointer from integer without a cast
gevent/core.c:12124: warning: implicit declaration of function ‘evbuffer_free’
gevent/core.c: In function ‘__pyx_pf_6gevent_4core_12http_request_5send_reply_chunk’:
gevent/core.c:12388: warning: assignment makes pointer from integer without a cast
gevent/core.c: In function ‘__pyx_f_6gevent_4core_report_internal_error’:
gevent/core.c:15376: warning: assignment makes pointer from integer without a cast
error: command 'gcc' failed with exit status 1

用的libevent是1.4.13。后来删掉yum暗组航的libevent,编译安装新的版本1.4.14b,就能成功build了。

2011-11-15

将matplotlib画的图拷贝到剪贴板

matplotlib画完的图没有copy的功能,于是组合了网上找到的几个函数,执行之后将figure中的图复制到剪贴板。


import matplotlib.pyplot as plt
from cStringIO import StringIO
import win32clipboard
from PIL import Image


def send_to_clipboard(clip_type, data):
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(clip_type, data)
win32clipboard.CloseClipboard()

def save_figure(f, file, w, h):
if not f:
f = plt.gcf()
dpi = f.get_dpi()
f.set_figwidth(w / dpi)
f.set_figheight(h /dpi)
f.savefig(file)

def copy_figure(w=600, h=400, fig=None):
file = StringIO()
save_figure(fig, file, w, h)
file.seek(0)
image = Image.open(file)
output = StringIO()
image.convert("RGB").save(output, "BMP")
data = output.getvalue()[14:]
output.close()
send_to_clipboard(win32clipboard.CF_DIB, data)