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

boost::tieでtupleを展開

C++

参考:http://www.gesource.jp/weblog/?p=1654前の http://d.hatena.ne.jp/shokai/20091231/1262248887 をboost::tieで受け取ってみた tupletest.cpp #include <iostream> #include <string> #include <boost/tuple/tuple.hpp> using namespace std; using namespace boost; // 多値を返す tuple<int, double, string> test_</int,></boost/tuple/tuple.hpp></string></iostream>…

boost::tupleで多値を受け取る

C++

簡単だった。もっと早く使ってれば良かった。画像処理は座標とかサイズを複数返したい時がよくあるから 関数宣言とmake_tupleの引数の数が違うとコンパイル時にエラーになる。intやdoubleは混ぜるとcastされる。tupletest.cpp #include <iostream> #include <string> #include <boost/tuple/tuple.hpp></boost/tuple/tuple.hpp></string></iostream>…

following数を取る

ruby -rubygems -e 'require "nokogiri"; require "open-uri"; require "kconv"; puts Nokogiri(open("http://twitter.com/shokai").read.toutf8).xpath("//span[@id=\"following_count\"]/text()").to_s'

avrdudeでavrマイコンにhexの書き込み

xtel-eclipseの中の jsc/jsc.jar talkticコンパイラ avrdude/bin/avrdude avrdude実行ファイル。mac portsでインストールできるavrdudeだと書き込みが怪しい。Ubuntu9.04のaptでインストールできるavrdudeはこっち avrdude/etc/avrdude.conf が重要。 java -…

stringから正規表現でマッチした箇所を抜き出す

C++

最初にソース文字列を入れて、次に正規表現を何度も試せる非常にインタラクティブかつシンプルなコード例regex_split.cpp #include <iostream> #include <boost/regex.hpp> #include <string> using namespace std; using namespace boost; int main(int argc, char* argv[]){ cout << "--input </string></boost/regex.hpp></iostream>…

stringのsplit

C++

boost::algorithm.splitを使う参考:Boost.String Algorithm - Faith and Brave - C++で遊ぼう #include <iostream> #include <vector> #include <string> #include <boost/algorithm/string.hpp> using namespace std; using namespace boost::algorithm; int main() { string s = "a,b.c,as/df"; vector<string> results; </string></boost/algorithm/string.hpp></string></vector></iostream>…

sayとgrowlで目覚ましワンライナー

Macのsayとgrowlでアラーム。これでもう電車乗り過ごさない。 ruby -rubygems -e 'sec=60*10; m="wakeup"; require "g"; start=Time.now; loop do if Time.now>start+sec; s="#{m} "+Time.now.strftime("%X"); puts s; g s; `say #{s} > /dev/null 2>&1`; en…

libgearman Macにソースからインストール

参考:ジョブキューサーバ Gearmand を PHP から使ってみた : tech.kayac.com - KAYAC engineers' blog sudo port install libevent ossp-uuidwget http://launchpad.net/gearmand/trunk/0.11/+download/gearmand-0.11.tar.gz tar -zxvf gearmand-0.11.tar.g…

BeagleBoardにemobileを接続する

最終的にLANを切るので、キーボードとディスプレイを接続して起動しよう 環境はBeagleBoard rev.BにUbuntu9.04。 ponコマンドを使えるようにする sudo apt-get install pppoe which pon which poffemobile D23HWを使う(CUIで) - 橋本詳解より /etc/ppp/pee…

VNCViewer

aptにtightvncがある sudo apt-get install xtightvncviewer which vncviewer vncviewer起動すると接続先のIPアドレスとパスワードをきかれる Mac版tightvncviewerより反応いい。

gearmand ソースからインストール

sudo apt-get install uuid-dev libevent-devwget http://launchpad.net/gearmand/trunk/0.11/+download/gearmand-0.11.tar.gz tar -zxvf gearmand-0.11.tar.gz cd gearmand-0.11/ ./configure --with-debug make sudo make install which gearmand/usr/bin/…

USBシリアル変換(FT232RLチップ)でシリアル通信する

ArduinoやGainerやmoxaで使ってるUSBシリアルチップのドライバが認識するようになってた(以前revBファーム+Ubuntu8.04でやった時はどうしても認識しなかった) Rubyから使ってみる。ruby-serialportインストール、シリアルポートを読む - 橋本詳解 の手順…

外付けHDD、USBメモリをマウント

最新版ファームウェア+Ubuntu9.04だと何もせずに認識してくれた。 マウントする mkdir ~/usbmem sudo mount /dev/sda1 /home/sho/usbmem マウント外す sudo umount /home/sho/usbmem起動時にマウントする /etc/fstab proc /proc proc defaults 0 0 /dev/mmcb…

emobile D23HWが認識しなくなったので再インストール

Mac

参考:D21HWの再設定方法 « printf.ishiro.com HDDを300GBから500GBにOSごと移し替えてから、emobileに接続できなくなった。モデムエラーとか接続失敗とか出る。Macはemobileのドライバ削除ツールが無いので手動で再インストールしなければならないらしい。 …

USBメモリを作業領域とswapにマウント

OS入ってるSDカードを何回も読み書きしててぶっ壊れた事から学んだ。 USBメモリにswapとかを置くようにした。オンボードのRAMが128MBしかないので、swapを700MBぐらい作っておいた。どれぐらいが適正なのか知らないが余ってるので多めに。 gpartedでUSBメモ…

U-Bootのアップグレード

kernel panicになってたのでいい機会だからボードのファームウェアをアップデートした。まっさらなSDカードを用意する。OSイメージいりのSDカードではなく新しいSDカードか、完全にフォーマットする。SDカード先頭に100MBぐらいのFAT32パーティションを作る…

WiFiを起動時に接続する

参考 http://hp.vector.co.jp/authors/VA008536/kurobox/wirelessap.html Ubuntu 9.10が調子悪かったので9.04にした。 /etc/network/interfaces を設定、ssidを指定してwlan0を起動できる auto lo iface lo inet loopback auto eth0 iface eth0 inet dhcp au…

WiFiを使う

rev.Bボードを最新のu-bootでファームウェアアップグレードし、Ubuntu9.10をGUIなしでインストールした状況。 http://elinux.org/BeagleBoardUbuntuNetwork#USB_Wifi PlanexのPCI MINI2というUSB WiFiを刺して sudo iwconfig wlan0 essid "ssid" sudo ifconf…

ランダムにsay

ruby -e 's="";rand(15).times do s+=[rand(26)+97].pack("c") end; `say #{s}`'ruby -e 's=Array.new(rand 15).map{|i|rand(25)+97}.pack("c*"); `say #{s}`'

gでgrowl

sudo gem install gruby -rubygems -e 'require "g"; g "test"'growl出た

ruby-serialportインストール、シリアルポートを読む

前にデバイスファイルを直接開いて読んだりした(http://d.hatena.ne.jp/shokai/20090716/1247733038)けど、閉じたり開いたり抜き差ししてるとたまにロックがかかってしまったりするのでおとなしくruby-serialportを使う。 最新版0.7はサンプルやドキュメント…

ruby-serialportで送受信

前:ruby-serialportインストール、シリアルポートを読む - 橋本詳解 ruby-serialterm.rb # -*- coding: utf-8 -*- require 'serialport' if ARGV.size < 1 puts 'ruby ruby-serialterm.rb /dev/tty/tty-usbdevice' exit 1 end sp = SerialPort.new(ARGV.shi…

texファイルの本文の行数を数える

ruby -e 'pattern=/.*(\.tex)$/; comment=/ *[%\\]/; sum=0; for i in 0..5 do Dir.glob("*/"*i+"*").delete_if{|n|!(n =~ pattern) or File::ftype(n) != "file"}.each{|f| sumf=0; n=open(f).read.split(/[\r\n]/).delete_if{|l|l =~ /[\\%]/}.each{|l| su…

shellのコマンドをtask登録してworkerに実行させる

別にGearmanでやる必要は無いし危険だしどのworkerが実行するかわからないから意味ないけど 別のマシンにshellのコマンドを実行させられる client側 #!/usr/bin/env ruby require 'rubygems' require 'gearman' c = Gearman::Client.new(['192.168.200.243:7…

Gearmanインストール、Rubyから使う

参考 http://d.hatena.ne.jp/okinaka/20090823/1251036470 sudo apt-get install gearman-server /etc/default/gearman-server を編集、trueにする ENABLED="true"sudo /etc/init.d/gearman-server start最近のバージョンのgearmanはport 4300で動くらしいが…

opencv-haartraining -data haarcascade_rightfront-hand -vec hand-front7207_36.vec -npos 7207 -bg bg.txt -nneg 3491 -nstages 30 -nsplits 2 -mem 1500 -weighttrimming 0.90 -mode ALL -w 36 -h 36 opencv-haartraining -data haarcascade_rightfront-…

漫画家

おとといの夢を思い出した。好きな漫画家が家に来て一緒に飯を食った。 俺は何を話していいかわからずアワアワしていた。ファンですと言っても大変そっけない態度でした・・

文字列中の()や「」や<>がペアになっていなかったら取り除く

木を作るか1文字ずつ読んでいくか考えたが、面倒だったので最初に区切り文字で配列に分割して左端から見ていくようにした。 今回気づいた事 配列の配列はjoinしてsplitすると1次元の配列になる Rubyで全角半角混じった文字列を1文字ずつ処理するの、面倒 aho…

tscreen

Mac

wget http://www.steve.org.uk/Software/tscreen/dist/tscreen-0.4.9.tar.gz tar -zxvf tscreen-0.4.9.tar.gz cd tscreen-0.4.9 ./configure --prefix=/usr/local make sudo make installhttp://hasumi.info/~h2/2009/11/11/tscreen%E3%81%AB%E7%A7%BB%E8%A1…

ディレクトリ下のファイルの行数を数えるワンライナー

俺が使う言語に全部マッチさせると場合 ruby -e 'pattern=/.*(\.as|\.js|\..+ml|\.cpp|\.c|\.cs|Makefile.*|\.rb|\.sh)$/; sum=0; for i in 0..10 do Dir.glob("*/"*i+"*").delete_if{|n|!(n =~ pattern) or File::ftype(n) != "file"}.each{|f| n=open(f).r…