rabbitfoot530's diary

読んだ本と、プログラムに関することのメモです。好きな言語は、C++, Python, Golang, TypeScript。数学・物理・学習理論も好きです。

2012-01-01から1年間の記事一覧

Cross origin requests are only supported for HTTP

Flaskで別のページのデータをXHRで読もうとしたら、エラー。 Cross origin requests are only supported for HTTP ご覧の通り、Google Chromeは、エラーだしてきます。なので、routeのところに、pathを追加してやって解決!

スペルチェック

aspellを使う // mac sudo port install aspell aspell-dict-en // linux sudo aptitude install aspell aspell-dict-en echo "lang en_US" >> ~/.aspell.conf 後は、~/.emacsに下記を書いて、簡単呼び出し (global-set-key "\M-j" 'ispell)

ValueError: unknown locale: UTF-8

Terminal > Preferences... > Settings > AdvancedSet local environment variables on startup

boost::mutex

boost::threadでmutexロックを使うsync.hpp #include <boost/thread.hpp> #include <boost/thread/condition.hpp> class Sync { private: static boost::mutex _thread_mutex; static boost::condition _thread_cond; public: static int do(); }; sync.cpp #include "sync.hpp" boost::mutex Sync::_thread</boost/thread/condition.hpp></boost/thread.hpp>…

boost::condition

boost::conditionは #include <boost/thread.hpp> // <-- こっちじゃない #include <boost/thread/condition.hpp> // <-- こっちをincludeしないとダメ</boost/thread/condition.hpp></boost/thread.hpp>

MacのPythonのバージョンの変更方法

port selectってコマンドでできるみたい。 インストールされてるpythonリスト port select --list python 現在のpythonのバージョン port select --show python pythonのバージョン変更(python3.2に変更の例) sudo port select --set python python32

has_key() is deprecated in

has_key()は、文字通り廃止予定みたいなので、inを使う。has_keyとの違いは、順序ぐらい? a = {'a': 1} if a.has_key('a'): print 'True' if 'a' in a: print 'True'

web2pyインストールから起動まで

インストール sudo pip install web2py アプリケーション作成 w2p_apps このまま、起動すると、tkがないっていわれるので、インストールしてない場合は、tkをインストールする。 sudo aptitude install python-tk 起動 w2p_run

emacs-for-pythonの\C-oについて

emacs-for-pythonを設定すると、\C-oがopen-next-lineという関数のデフォルトのキーバインドに設定されてしまう。これは、elscreenのprefixを\C-oに割り当てている人にとっては困る。。。特に、open-next-lineの関数を使わないのなら、epy-editing.elの中の…

EmacsでPythonを楽に設定する方法

EmacsのPythonの設定は、いろいろあってどれがいいのが、どの組み合わせがちゃんと動くのかが、複雑なので、それをお手軽に済ませるかつ、使いやすい環境を構築するには、emacs-for-pythonを使うhttp://gabrielelanaro.github.com/emacs-for-python/ (load-f…

ac-clear-variable-every-10-minutes ERROR

ac-clear-variable-every-10-minutes ERROR このエラーがemacs --debug-initででたら、auto-completeのファイルを削除してみる。

boost::unordered_mapコンパイルエラー

デバッグプリント用にdefineでpを宣言してたら、unordered_mapの#includeのところでエラーがでた。 /usr/include/boost/unordered/detail/allocator_helpers.hpp: In member function ‘boost::unordered_detail::allocator_array_constructor<Allocator>::pointer boost</allocator>…

_SC_OPEN_MAX: 最大ファイル数

c c++

1プロセス中の最大オープンファイル数 #include <sys/resource.h> int main() { Print::p(sysconf(_SC_OPEN_MAX)); }</sys/resource.h>

structからclassへ書き換え

c++ c

Cのソースにある、structをクラスへ書き換える。 関数ポインタ使ってると、下記のようにすればいい。 typedef int (*handler_t)(int fd, void* arg); typedef int (*destructor_t)(void* arg); typedef struct context { void* arg; handler_t handler; dest…

libevent使用時のコンパイルエラー

c c++

libeventを使ったコードをコンパイルするときに下記のエラーがでました。 error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory ただ単にリンクがたりてないだけ。/usr/local/libにファイ…

boost::function

要は、関数ポインタね♪ #include <boost/function.hpp> int add(int a, int b) { return a + b; } int sub(int a, int b) { return a - b; } int main() { boost::function<int (int, int)> f = add; Print::p(f(1, 2)); f = sub; Print::p(f(1, 2)); }</int></boost/function.hpp>

templateのヘッダ

C++

tepmlateを書くときは、ヘッダに実装も書かないといけない。けど、宣言が書いてあるヘッダに、実装が書いてあるヘッダを別ファイルとしてincludeすれば、実装と宣言を分けることができる。inc_header.hpp #include "imp_header.hpp" template <typename T> void(T m); te</typename>…