2012-04-01から1ヶ月間の記事一覧
ユークリッドの互除法が読んでる本で出てきたので、軽く実装。 def euclid(a, b): numerator = max(a, b) denominator = min(a, b) if numerator == 0 or denominator == 0: return None times = numerator / denominator remainder = numerator - denominat…
ifconfigで表示されるIPアドレスの情報をc/c++から取得するコード #include <ifaddrs.h> struct ifaddrs* ifaddr; if (0 != getifaddrs(&ifaddr)) { return 1; } char addrstr[INET_ADDRSTRLEN]; while (ifaddr != NULL) { if (ifaddr->ifa_addr->sa_family == AF_INET)</ifaddrs.h>…
ソースしかないzabbix2.0.0.rc2からdebianパッケージを作る手順 まずは、ソースのダウンロード http://prdownloads.sourceforge.net/zabbix/zabbix-2.0.0rc2.tar.gz?download 必要なパッケージのインストール sudo aptitude install dh-make devscripts debh…
C++でJSONを扱いたい便利なライブラリ。picojson.hを使用させてもらいます。 #include "picojson.h" picojson::object o; o.insert(std::make_pair("key", picojson::value(std::string("VALUE")))); std::cout << o["key"].get<std::string>() << std::endl; picojson::v</std::string>…
snprintfとかつかってたのを、お手軽にやる! #include <boost/format.hpp> boost::format fmt("%s,%s"); fmt % "Hello!" % "World!"; std::cout << fmt.str() << std::endl;</boost/format.hpp>
boost::threadにfuncを指定して、funcからの戻り値を取得。funcには、引数を渡すために、bindする。 int return_func(std::string a, std::string b) { retrun 0; } boost::packaged_task<int> pt(boost::bind(return_func, "a", "b")); boost::unique_future<int> uf </int></int>…
key, valueをpairで格納しておいて、それを取り出すときは、tieでひとまとめにしてとりだす。 #include <boost/container/vector.hpp> #include <boost/tuple/tuple.hpp> boost::container::vector<std::string, std::string> v; std::string key, value; BOOST_FOREACH(boost::tie(key, value), v) { std::cout << key << value << std::en</std::string,></boost/tuple/tuple.hpp></boost/container/vector.hpp>…
空白をstd::stringから削除。 std::string str = " ab "; boost::trim(str); 文字指定する場合は std::string str = " ab "; boost::trim_if(str, boost::is_any_of(" "));
wait処理をしたいとき、sleepでやってもいいけど、boostでやるなら、下記のよう。 #include <boost/thread.hpp> #include <boost/date_time/posix_time/posix_time.hpp> while (true) { boost::this_thread::sleep(boost::posix_time::milliseconds(1000); std::cout << "hi" << std::endl; }</boost/date_time/posix_time/posix_time.hpp></boost/thread.hpp>
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)
Terminal > Preferences... > Settings > AdvancedSet local environment variables on startup
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は #include <boost/thread.hpp> // <-- こっちじゃない #include <boost/thread/condition.hpp> // <-- こっちをincludeしないとダメ</boost/thread/condition.hpp></boost/thread.hpp>
port selectってコマンドでできるみたい。 インストールされてるpythonリスト port select --list python 現在のpythonのバージョン port select --show python pythonのバージョン変更(python3.2に変更の例) sudo port select --set python python32
has_key()は、文字通り廃止予定みたいなので、inを使う。has_keyとの違いは、順序ぐらい? a = {'a': 1} if a.has_key('a'): print 'True' if 'a' in a: print 'True'
インストール sudo pip install web2py アプリケーション作成 w2p_apps このまま、起動すると、tkがないっていわれるので、インストールしてない場合は、tkをインストールする。 sudo aptitude install python-tk 起動 w2p_run
emacs-for-pythonを設定すると、\C-oがopen-next-lineという関数のデフォルトのキーバインドに設定されてしまう。これは、elscreenのprefixを\C-oに割り当てている人にとっては困る。。。特に、open-next-lineの関数を使わないのなら、epy-editing.elの中の…
EmacsのPythonの設定は、いろいろあってどれがいいのが、どの組み合わせがちゃんと動くのかが、複雑なので、それをお手軽に済ませるかつ、使いやすい環境を構築するには、emacs-for-pythonを使うhttp://gabrielelanaro.github.com/emacs-for-python/ (load-f…
ac-clear-variable-every-10-minutes ERROR このエラーがemacs --debug-initででたら、auto-completeのファイルを削除してみる。