「Command」を含む日記 RSS

はてなキーワード: Commandとは

2014-07-12

http://anond.hatelabo.jp/20140712160235

 なんか、最近家電もそうなんだけど、簡単に見せる事にがんばり過ぎて、かえって使いにくくなってる・・・気がする。ボタンの数は減って、見た目は優しくなったけど、やりたい事をやるためには何層もメニューを下っていかなきゃいけない。

 昔の家電は、ボタンは多くて、一見してうわーて思うんだけど、1機能ボタンで、やりたい事がすぐ出来た(と思う)。PCはいちおう使えてるけど、たくさんのボタンキーボード)があって、CtrlとかAltとかCommandがあるから、やりたい事が一発でできるし、キーの位置も変わらないから、1度憶えた事はずっと使える。

 でもタブレットとかスマホはのっぺりした1枚板で、キーとかボタンの位置と機能アプリによって変わってしまうみたいだし、憶える事が多すぎる・・・気がする。たぶん、子供とか、若い人みたいに柔軟性がある人には向いてるんだろうけど、はっきりいって高齢者を置き去りにしてると思う・・・

 銀行ATMとか、駅の券売機とかでまごついてるおじさんおばさんがいるけど、あの人達スマホとかタブレットは難しいだろうなぁ・・・そして私もその1人・・・

2014-06-06

Sublime2




optionを押しながら選択

→縦に選択できる。矩形選択(くけいせんたく)というらしい。


カーソルがある行でcommand + C

→その行全体をコピー。選択しなくてもいいので楽。




最近、このコマンドをよく使っている。おすすめ

2014-04-26

円城塔本の雑誌の連載「書籍化までn光年」で取り上げた本のリスト

http://anond.hatelabo.jp/20140421200127

書籍化まで7光年 (2009年)

  1. アンドルー・クルミー 『ミスター・ミー』    「『ミスター・ミー』とドップラー効果恋愛小説
  2. ポール・オースター 『幻影の書』    「オースター百%の『幻影の書』と本のスカート
  3. ピエールバイヤール 『読んでいない本について堂々と語る方法』    「読んでいない本を語る方法と「特性のない本」」
  4. ジョン・クロウリーエンジンサマー』    「言葉の"ずれ"と物騒な本」
  5. 浅暮三文ぽんこつ喜劇』    「ひよこサクラ実験小説
  6. シュボーンロバーツ 『多面体と宇宙の謎に迫った幾何学者』    「迷走と眩惑の理学タイトルの謎」
  7. David Flanagan 『プログラミング言語 Ruby』    「プログラミング言語小説屋」
  8. ジャック・ルーボー 『麗しのオルタンス』    「超絶馬鹿技巧小説『麗しのオルタンス』に隠された秘密
  9. ジャック・ルーボー 『麗しのオルタンス』    「数と音楽の秩序で作られた希代の小説
  10. ヒュー・ケナー 『機械という名の詩神』    「文学テクノロジー作家関係
  11. チャールズ・ストロス 『アッチェレランド』    「全編ボケ倒しのすごい奴」
  12. 多和田葉子ボルドーの義兄』    「『ボルドーの義兄』謎の276文字を追う」

書籍化まで6光年 (2010年)

  1. パウル・クレー新版 クレー日記』    「小説のような日記日記のような小説
  2. 中野美代子ザナドゥーへの道』    「多幸感に満ちた文字の連なり」
  3. ジャック・ルーボー 『麗しのオルタンス』    「『麗しのオルタンス』ジャック・ルーボーに直撃質問!」
  4. ミロラド・パヴィッチ 『帝都最後の恋』    「タロットにしたがって読むパヴィッチの本」
  5. ダンガードナーリスクあなたは騙される』    「現実小説よりハッピーなのだ!」
  6. ティーヴ・トルツ 『ぼくを創るすべての要素のほんの一部 』    「長い小説が書けない理由!?」
  7. 大野克嗣 『非線形世界』    「単純素朴なのになぜか伝わらない本」
  8. ジル・プライスバートデービス 『忘れられない脳』    「ジル・プライス忘却のない人生
  9. クラーク・アシュトン・スミス 『ゾティーク幻妖怪異譚』    「「そういう人」スミスが好き」
  10. スタニスワフ・レム 『泰平ヨンの航星日記』    「レムの欠番を埋めるのは」
  11. エミーリ・ロサーレスまぼろし王都』    「見えないものが見える瞬間」
  12. イヴィッド・レヴィット 『数式に憑かれたインド数学者』    「稀代の数学者架空伝記」

書籍化まで5光年 (2011年)

  1. ブノワ・デュトゥールトゥル 『幼女煙草』    「不穏さに満ち満ちた『幼女煙草』」
  2. スマイル・カダレ 『死者の軍隊将軍』    「不思議な国アルバニア戦争小説
  3. 高橋陽一郎 『変化をとらえる』    「数学教科書いろいろ」
  4. サイモン・シンエツァート・エルンスト代替医療トリック』    「代替医療に挑む議論の書」
  5. 辻原登 『闇の奥』    「辻原登は変である
  6. 柏野牧夫 『音のイリュージョン』    「聴覚だって騙される」
  7. マックス・ブルックスWORLD WAR Z』    「語り伝える書」
  8. ジェラルディン・ブルックスマーチ家の父』    「網目だらけ」
  9. グレゴリー・コクランヘンリー・ハー ペンディング 『一万年進化爆発』    「淡々進化中」
  10. イヴィッド・グラン 『ロスト・シティZ』    「見えない都市
  11. Federico Biancuzzi、Shane Warden 『言語設計者たちが考えること』    「言葉を作る人たち」
  12. A・R・ルリヤ 『偉大な記憶力の物語』    「無限記憶を持つ男」

書籍化まで4光年 (2012年)

  1. V・S・ラマチャンドラン、D・ロジャース=ラマチャンドラン 『知覚は幻』    「美の起源?」
  2. Charles Yu 『How to Live Safely in a Science Fictional Universe』(『SF的な宇宙安全に暮らすっていうこと』)    「ウーのくすぐり芸」
  3. マット・リドレー 『繁栄』    「人類は滅亡しない?」
  4. ウンベルト・エーコ 『バウドリーノ』    「エーコが好きだ!」
  5. Steven Bird、Ewan Klein、Edward Loper 『入門 自然言語処理』    「見えない辞書
  6. エットハミ・ムライ・アメド 『モロッコ食卓』    「信楽焼タジン鍋
  7. ピーター・ペジック 『青の物理学』    「青の見取り図
  8. クリストファーチャブリス、ダニエルシモンズ錯覚科学』    「見えないゴリラ
  9. 大沢文夫 『大沢流 手づくり統計力学』    「百円玉実験不思議
  10. トルケル・フランセーン 『ゲーデル定理――利用と誤用の不完全ガイド』    「ゲーデルさんごめんなさい」
  11. Mark Kac 『Kac 統計的独立性』    「数学者をつくる本」
  12. ロザリー・L・コリー 『パラドクシア・エピデミカ』    「矛盾と逆理の入門書

書籍化まで3光年 (2013年)

  1. レベッカスクルート 『不死細胞ヒーラ』    「ヘンリエッタ細胞
  2. ジョン・パウエル 『響きの科楽』    「宇宙人にあげたい本」
  3. 山田風太郎旅人 国定龍次』    「山田風太郎輪郭
  4. レニー・ソールズベリー、アリー・スジョ 『偽りの来歴』    「世界改竄
  5. Bruce A. Tate 『7つの言語つの世界』    「たくさんの言語
  6. 寺田尚樹 『紙でつくる1/100の世界』    「これは本です」
  7. アンソニー・ドーアメモリー・ウォール』    「非SF作家SF
  8. オリヴァー・サックス 『心の視力』    「サックスおじさんの症状」
  9. ダニエル・アラルコン 『ロスト・シティレディオ』    「読んでも未知の本」
  10. P・Gウッドハウスジーヴスとねこさらい』    「"ゆるさ"のシリーズ
  11. ヴィクトリアブレイスウェイト 『魚は痛みを感じるか』    「魚の痛みの判定基準
  12. イヴィッド・イーグルマン意識は傍観者である』    「傍観者法学

書籍化まで2光年 (2014年)

  1. ブライアンクリスチャン機械より人間らしくなれるか?』    「純正人間の奮闘記」
  2. Clifford A. Pickover 『The Math Book』    「数学的あれこれ250」
  3. トレヴァー・ノートン 『世にも奇妙な人体実験歴史』    「楽しい自己人体実験
  4. フリオリャマサーレス無声映画のシーン』    「幸せ本棚
  5. ジョセフ・オルーク折り紙のすうり』    「折り紙数学
  6. ニール マクレガー 『100のモノが語る世界歴史』    「大英博物館のモノ」
  7. 根上生也四次元が見えるようになる本』    「四次元練習
  8. トーマス・トウェイツ『ゼロからトースター作ってみた』    「トースターを作る男」
  9. ロベルトボラーニョ『2666』    「ボラーニョの奔流」
  10. ガイ・ドイッチャー『言語が違えば、世界も違って見えるわけ』    「言語世界の見え方」
  11. D・マンフォード、C・シリーズ、D・ライトインドラの真珠』    「空海フラクタル
  12. V・S・ラマチャンドラン『脳のなかの天使』    「九つの美の法則

書籍化まで1光年 (2015年)

  1. 川添愛『白と黒のとびら』    「数学小説の融合」
  2. リチャード・パワーズ幸福遺伝子』    「純文とSF
  3. ロン・カリージュニア神は死んだ』    「真正突破短編集」
  4. ラウディアハモンド『脳の中の時間旅行』    「素朴に語る時間の話」
  5. Franco Moretti『Distant Reading』    「遠くから見る世界文学
  6. Lev Manovich『Software Takes Command』    「新しい思考の道具」
  7. デイヴィッド・マークソン『これは小説ではない』    「小説ではない小説
  8. シャロンバーチュ マグレイン『異端統計学 ベイズ』    「紛糾する統計学
  9. 内村直之『古都がはぐくむ現代数学 京大理解析研につどう人びと』    「数学という営み」
  10. Stanisław Lem『Summa Technologiae』    「レムの『技術学大全』」
  11. M・G・ヴァッサンジ『ヴィクラム・ラルの狭間世界』    「言葉より速く」
  12. 語り手 姉崎等、聞き書き 片山龍峯『クマにあったらどうするか』    「クマにあったら」

書籍化まで○光年 (2016年)

  1. ピーター・H・ディアマンディス、スティーヴン・コトラー『楽観主義者未来予測』    「未来は本当に暗いのか」
  2. ジェシーケラーマン駄作』    「いない、いない、の本」
  3. キャサリン・ゴヴィエ 『北斎と応為』    「歴史小説の書き方」
  4. 横山悠太『吾輩ハ猫ニナル』    「色んな言葉が混ざる小説
  5. 佐久間保明監修、本庄千代編『しかけ絵本世界』    「四角な本の大革新
  6. エミリー・オスター『お医者さんは教えてくれない 妊娠出産常識ウソホント』    「経済学者出産育児論」
  7. クレイグ・モド『ぼくらの時代』    「オモチャ電子書籍
  8. Noam Nisan、Shimon Schocken『コンピュータシステム理論実装』    「コンピュータをつくる」
  9. マーティンガードナーガードナー数学パズルゲーム』    「人生を変える数学パズル
  10. ピーターメンデルサンド『本を読むときに何が起きているのか』    「「読む」を考えさせる本」
  11. 遠藤侑介『あなたの知らない超絶技巧プログラミング』    「プログラミングロマン
  12. ベン・H・ウィンタース世界の終わりの七日間』    「世界の終わりへ続く日々」

書籍化まで△光年 (2017年)

  1. 奥修『珪藻美術館』    「ぞわぞわ感の境界
  2. マークチャンバーランド『ひとけたの数に魅せられて』    「ひとけたの数を語る本」
  3. ピーター・ウォード、ジョゼフ・カーシュヴィンク『生物はなぜ誕生たか』    「地球が生まれから歴史
  4. ライナー・クニツィアダイスゲーム百科』    「機械が作るゲーム
  5. ウンベルト・エーコプラハ墓地』    「史上最大の偽書の成立秘話
  6. ユーディット・シャランスキー『奇妙な孤島の物語』    「紙に書かれた五〇の島の物語
  7. 高野秀行『謎のアジア納豆』    「納豆とはにかみ」
  8. ロビンダンバー人類進化の謎を解き明かす』    「友達は二百人できません」
  9. アンソニー・ドーア『すべての見えない光』    「ドーア言語兵器
  10. ティーヴン・ウィット『誰が音楽をタダにした?』    「変化する音楽生態系
  11. 鈴木真治『巨大数』    「書くことのできない数」
  12. コマヤスカン新幹線のたび 金沢から新函館北斗札幌へ』    「視点がひっくり返る絵本

書籍化まで□光年 (2018年)

  1. まつもとゆきひろまつもとゆきひろ 言語のしくみ』    「言語のつくり方」
  2. 原武史政治思想史』    「物から読み解く政治思想
  3. マリオ・レブレーロ『場所』    「どこまでも続く部屋」
  4. 横山茂雄『神の聖なる天使たち』    「ディーとケリーの奇妙な運命
  5. ルシオ・デ・ソウザ、 岡美穂子『大航海時代日本人奴隷』    「記録に残されなかった者たち」
  6. 倉谷滋『分節幻想 動物のボディプラン起源をめぐる科学思想史』    「「発生」をめぐる学問歴史
  7. イチカワヨウスケ『野菜だし』    「レシピと伝達」
  8. 古賀弘幸『文字と書の消息』    「文字歴史の広がり」
  9. 赤野工作『ザ・ビデオゲームウィズ・ノーネーム』    「2115年のゲームレビュー
  10. 本山尚義『全196ヵ国おうちで作れる世界レシピ』    「世界196ヵ国の家庭料理
  11. フレット・スメイヤーズ『カウンターパンチ 16世紀活字製作現代書体デザイン』    「美しい活字への道」
  12. ジェニファー・ダウドナ、サミュエルスターバーグ『CRISPR(クリスパー) 究極の遺伝子編集技術発見』    「遺伝子編集の新技術

2014-04-10

Windows8の使い勝手改善する。

ついにWindowsXPサポートが終了しました(挨拶)

で、Windows8使ってるわけだけど、少々使いづらいので、自分なりに使いやすいようしたTips備忘録もかねて少し書いてみる。

スタートメニューっぽいものを作る

  1. エクスプローラを開いてシステムドライブ適当なところに『田ミ』あるいは『田ミ スタート』という名前フォルダを作る。(最重要)
  2. このフォルダの中によく使うアプリケーションショートカットを作って放り込む。
  3. このフォルダタスクバーまでドラッグドロップする。
  4. タスクバーを右クリックし『タスクバーを固定する』のチェックを外す。
  5. タスクバーを右クリックし『タイトルの表示』にチェックを入れる。
  6. バーに追加したフォルダを一番左までドラッグ、表示幅を最小限になるように調整する。
  7. ツールバーの「田ミ」の隣の『≫』をクリックするとなんかスタートメニューっぽいものが表示される!

MSアップデートスタートメニューを復活させると先日発表したけどそれまでのつなぎとして。あるいは復活したメニューが期待した通りのものでなかった場合対処法として。

我々はすでに8.1のアップデートで一度MSに裏切られた。「コレジャナイ!」

win8スタートメニューを追加するソフトはいくつかあるけれど、この方法スタートメニューもどきを作る利点はOSの標準機能だけで実現できること。

セキュリティ/運用ポリシー的にソフトインストールが禁止されていてもこの方法なら可能かと。

作ったメニューさらに便利に使うための方法

作ったメニューwindowsシャットダウンと休止状態の機能を追加する。

フォルダを開いて右クリック → 「新規作成」 → 「ショートカット」 で「項目の場所入力してください」に以下を入力

dim objShell
set objShell = CreateObject("shell.application")
objshell.ShutdownWindows
set objShell = nothing

スクリプト類は直接メニューフォルダに置くのではなく、どこか別のフォルダに置いてショートカットを介すほうがいいかもしれない。そうすればショートカットに好きなアイコンを設定できる。

ショートカットファイル右クリック、「プロパティ」 → 「ショートカット」タブ → 「アイコンの変更」ボタン で変えてしまおう。設定にするのにちょうどよいシステムの主要なアイコンは %SystemRoot%\system32\SHELL32.dll にまとめて入っている。

あとは %USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\System Tools に「ファイル名を指定して実行」などの特殊ショートカットがあるので、これをコピーしてメニューに放り込む。

メニュープログラム一覧を追加する(上級者向け)

かつてのwindowsスタートメニューにあった「プログラムメニューに相当するフォルダwin8にも存在する。

\ProgramData\Microsoft\Windows\Start Menu\Programs

作ったメニューフォルダから上記フォルダシンボリックリンク(ショートカットは不可)を張ると「ブログラム」のサブメニューが実現できる。

起動時にスタート画面を飛ばしデスクトップを表示する

%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

上記フォルダテキストファイル新規作成して以下を書き込み「デスクトップの表示.scf」などの名前で保存。

[Shell] 
Command=2 
IconFile=explorer.exe,3 
[Taskbar] 
Command=ToggleDesktop

起動時いつものスタート画面が表示されるものの、しばらく待つといつものデスクトップ画面が表示される。

2014-04-09

オブジェクト指向 v.s. 関数型プログラミング

近年、関数型プログラミング重要はいろんなところで叫ばれています

Javaの最新バージョン関数型プログラミングに関する新機能が加わりました。

Rubyも昨今、関数型プログラミングへのサポートが手厚くなってきています

プログラミング教科書大手オライリーからJavascript関数型プログラミングを行うための解説書が発行されました。

関数型プログラミングへの注目度は高まってきています

おそらく、みなさんは既にオブジェクト指向が何か、を知っています

でも関数型プログラミングとは何か、胸を張って語れる人は、周りに見当たらないかと思います

実際、オブジェクト指向によってプログラミングする方法は、わかりやすい解説があちこちにある一方で、

関数型プログラミングとは何か、何が良いのか、ということについての、よいまとめは見つけることはできませんでした。

この記事を読む方の中で、「関数型プログラミングを取り入れるか・取り入れないか」で切実に悩んでいる人は、おそらくいないでしょう。

この記事はあまりかいところに立ち入りません。関数型プログラミングを使う側の立場に立って、利点や向き・不向き、それが導くスタイルを書きました。

みなさんは鳥のように飛んで、高い空から関数型プログラミングとは何か、何が良いのか、を見渡してください。

ふたつのアプローチ比較

オブジェクト指向アプローチは、名前をつけてプログラムを整理する

関数型プログラミングアプローチは、汎用部品でなんとかする

オブジェクト指向アプローチ

Googleが近年リリースした言語、Goには、”継承”を直接サポートする仕組みが無いことが話題になりました。

また、Mac OSXの基幹ライブラリCore Foundationは、ライブラリ自体C言語で書かれているにもかかわらず、その設計方針は明確にオブジェクト指向です。

継承クラスは、オブジェクト指向必須条件ではありません。

オブジェクト指向本質とは、何でしょうか。

その本質とは"名前をつけて対象を識別し、それを扱うこと"、にあります

最もプリミティブなオブジェクト指向対象は、ファイルハンドラです。あるファイルを開いて、読み込んで、あるいは書き込んで、ファイルを閉じる。

これらの処理をまとめたら、わかりやすいですよね?

対象に関する処理を、対象の周りにまとめる。これがオブジェクト指向の基礎的な理念です。

識別することとイコール比較できることは、とても良く似ています

イコールによる比較は、オブジェクト指向では鬼門であることが知られています

PointクラスインスタンスとColoredPointクラスイコール演算をどう決めればいいかに、正解はありません(詳しくは"effective java"をご参照ください)。

また名前をつけて識別する対象は、フワフワしていてはいけません。

たとえば、"軍人階級"をオブジェクトにしたとしましょう。"大佐"クラスのある兵士名前フィールドや、性別フィールドを持っているでしょう。

ところで彼が昇格したときに何が起こるでしょうか。

新たに"少将"クラスインスタンスが作られます。"大佐"クラスを破棄する前に、名前性別、その他沢山のデータを引き継がなくてはいけません。フィールドを増やしたい場合はその都度コード修正を加える必要があります(*)。

なるべくイコール比較を避けたい。対象不安定なものはいけない。では何に名前をつけて、識別するか。そこにオブジェクト指向技術者の熟練度が現れるのです。

関数型プログラミングアプローチ

一方、関数型プログラミングでは、特定の何かに名前をつけるより、極力、汎用部品でなんとかしようとしま

さな関数を、集めて撚り合わせて、新しい関数を作る。

関数自体リストなどのデータ構造に詰めることもよく行われます

実は、関数型プログラミングというのは本質を表していません。

その真の名は、"値指向プログラミング"です。

関数をはじめとして、リスト・ツリーのようなコンテナ手続きを抽象化したもの、回路を抽象化したもの

あらゆる対象を値として、合成し、ときに分解し、新しい値を作ります

変数という概念必要ありません。

変数適用する処理を作りあげることが、とても簡単だからです。

四則演算定義されたデータを詰めたデータ構造もまた、四則演算可能だったり。

値をイコール比較することも、なんのそのです。

誤解を恐れずに言うと、オブジェクト指向トップダウンなのに対し、関数型プログラミングボトムアップです。

関数型プログラミングの利点

読みやすい・理解やす

関数型プログラミングサポートする言語には、沢山の汎用部品定義されています

このような構造インターフェイスとして、様々なライブラリが組まれているので、

たとえばモナドを知っていれば、30分程度でパーサー(解析機)を理解することができて、

パーサーを理解できれば、JSONパーサー・ XMLパーサー・markdownパーサー・C++パーサー ... などを理解するのはとても容易です。

理解やすいこと。これが関数型プログラミングの大きな利点です。

追記:

また、汎用部品と型のお陰で、ライブラリドキュメントが圧倒的にひきやすい、というメリットも有ります

Haskellな人がPythonにトライした結果 - Togetterまとめ

書きやす

関数型プログラミングは「厳密な事前設計必要とするため、簡単なことをやるのにも時間が掛かる」。

よく誤解されていますが、これはウソです。

スクラッチプログラムするのは、非常に手軽です。

>> map (*2) [1,2,3]
[2,4,6]

邪魔な”儀式”や、"おまじない"のコードが徹底的に撤廃されているためです。

関数型プログラミングコードは、潔癖かつ濃密です。

たとえばC言語でint hoge(int x,int y)が定義されているときhoge(3)はなんの意味も持ちませんが(コンパイルコケますが)、関数型プログラミングでは意味があり、実際に有用です。

上の例では、「掛け算をする」(*)関数は、二引数関数ですが、それに引数を渡して作られた「2を掛ける」関数(*2)は、一引数関数になります

関数型プログラミングでは、「簡単なことは簡単にでき、複雑なことは複雑にできる。ただし、間違ったことは殆どできないか、全くできない」。

多くのバグは、コンパイルエラーとして検出されます

また、静的型付けの力によって、コード補完は非常に強力になっていますインテリセンスの比ではないです。

たとえば、関数中のある表記の型を任意に表示できます(GHC/TypedHoles - HaskellWiki)。

やがてやってくる未来には、プログラムテキストエディタで書くことは時代遅れになっているでしょう。

統合環境サポートで、バグミスの少ない、スムーズプログラミングができます

そしてその環境で動くプログラミング言語は、関数型プログラミングサポートした言語なのです。

いつ関数型プログラミング

以下の様な兆候を感じたら、あなたはそのプログラム関数型プログラミングで書くべきです。

一般に、オブジェクト同士の相互作用が複雑になるほど、オブジェクト指向では手に負えなくなっていきます

そういうときは、オブジェクトを直接扱わず、替わりにその"相互作用"を扱うことで、複雑さを軽減するアプローチ有効です。

それこそが関数型プログラミングアプローチです。

オブジェクト指向の利点

初心者にとっては読みやすい・理解やす

特にオブジェクト指向有効なのはプログラミング初心者がそのコードをいじるかもしれないときです。

関数型プログラミングは、強固さと柔軟さの代償として、高い学習コストを伴います

そのため、初学者にとってはハードルが高いのです。

扱う対象があまり複雑でない時は、書きやす

オブジェクト間の相互作用が複雑でなく、着目している(名前をつけている)概念が安定しているとき

そして、プログラムをいじる人たちの間で共通理解が図れているならば、オブジェクト指向が有利です。

関数型プログラミングの得意分野はなにか

数値計算

遅延評価という機能によって、レガシー言語で扱えなかった、巨大な数を扱うことができます

分数を扱うことができます虚数もです。

関数型プログラミングで書かれたプログラムは、正確さが要求される、金融関連の業界で使われています

テキスト処理

手続きとしてパーサーを記述できるので、テキスト処理プログラムはより理解やすく、メンテナンスやすものになります

関数型プログラミングを知らない人は、「正規表現おk」と言いますが、

彼の書いた複雑な正規表現は、半年後には(書いた本人でさえ)理解できなくなっていることでしょう。

並行処理

手続き一般を扱うことができるので、途中で割り込みのある手続きの表現も容易です。

関数型プログラミングサポートしていない言語ではコルーチン(ファイバー)などをつかってなんとかするしかありません。

さもなくば、非並行処理では普通に関数として記述できるところを、並行処理のために、Builder,Strategy,Command,Interpreterパターンを駆使して書き直すことになります

Javascript使いの方は、Deferredなどの構造を使うでしょう(http://qiita.com/KDKTN/items/4c6986049d204f0645d8)。

C++使いの方はBoostで頑張りましょう。破滅的に解りにくいコンパイルエラーメッセージと格闘してください。

レシピ

もう少し簡単な例をあげます

あなたは、あるレシピにしたがって、自動的料理を行うマシン制御プログラムを書いているとしましょう。

料理レシピは、"手続き"ですよね?たとえば、カレー

1. まず玉ねぎを炒める。

2. 飴色になったら、肉を加えて炒める。

3. 野菜を加える。

4. 水を加えて煮る。

5. スパイスを加える。

しかあなたはこの手続きを関数として表現できるでしょうか。

…できませんよね?何故ならば、各ステップの"間に"、マシンのロボアームの位置や動きを調整する処理が必要からです。

これをオブジェクト指向でやろうとすると、各ステップ副作用として、それらの処理を行うことになります

そうすると、マシンが二機に増えた時などの変更量は、絶望的なものになります

あるいは関数として表現するのを諦め、手順全体をDSL記述できるようにします。

このアプローチ関数型プログラミング的です。しか関数型プログラミングサポートした言語の助けなしでは、そのDSL記述するために沢山のユーティリティコードを書かなくてはならないでしょう。

オブジェクト指向アプローチでこの問題をエレガントに解こうとすると、クラス化の粒度を上げる事になります

野菜クラスフライパンクラス、ボイルクラスフライクラス、焼き加減クラス、アームクラス野菜の大きさクラス、切り方クラス、焼き方クラス、"焦げたよ"クラスetc...

こうすると早晩レシピプログラムコードから消え去ることになります。上記のたった5行は、依存性注入のオブジェクトグラフを構築するコードに取って代わることになります。そこには沢山の挙動制御オプションとして付記されているのです。

カレーなど、ある種のレシピ限定することで、見た目の理解やすさを得ることができますが、一方それは表現力を損なうことを意味します。

C言語などではマクロを使うこともできますが、それは結局、関数型プログラミングアプローチ意味するところと同じになります。すなわち、補助のために沢山のコードを書くことになるでしょう。

GUI

iOSのAppstoreアプリは、"無料"と書かれたボタンを押すと、それが"インストール"ボタンに変わり、それをもう一度押すと、ダウンロードの進捗を表すインジケータに変わり、それを押すとダウンロードキャンセルできます

このように、位置は同じなのに、ステートに依って見た目と機能が変わるボタンは複雑です。

これをオブジェクト指向で実現しようとすると、

1. 三つの異なるボタンを同じ位置に置くか

2. 同じボタンが三つの異なる機能を持つか

という下らない問題にぶつかります

一方関数型では、"機能"、"見た目"、"状態"、を独立に扱って、それらを合成してボタンを作るので、迷うことはありません。

「同じ位置にあるUIオブジェクトは、コード上で(インスタンスとして)独立して、他から干渉を受けない」

この条件が満たされているうちは、オブジェクト指向GUIを実現することに無理はありません。

しかし、携帯端末のような小さい画面で、多くの機能を達成するためには、UI要素はコンテキスト依存的に複雑になりがちです。

近年、PCのディスプレイの大きさは、頭打ちになってきました。

画素数は増えているのですが、MacにおけるRetinaのように、複数ピクセルひとつドットを表すようになってきています

これは、ひとつの画面に置かれるボタンなどのUI要素の数は、これから先の未来で増えることはない、ということを意味します。

したがって、未来GUIプログラミングは、注意深く機能ピックアップして制限するというデザイナー努力を脇におけば、

関数型プログラミングの力を頼るしか無いでしょう。

はじめよう、関数型プログラミング

まり

Haskell さいこうなのおおおおおおおおおおおおおおおおおお!! おしっこ漏れちゃうのおおおおおおおおおおおおおおおおおおおお(゜∀。)ワヒャヒャヒャヒャヒャヒャ

1. google:すごいHaskellたのしく学ぼう を注文する。

2. Download Haskell自分のPCに導入する。

3. コンソールghciと入力して、対話コンソールを立ち上げる。

4. 次の関数コンソールに打ち込んで、結果を見る。即値で書かれているところとかをいろいろ変更してみて、感動する。

take 4 $ map (*2) [1..]

5. ステップ1で買った教科書を読んで、学ぶ。


追記:

いかがでしたか

ちまたには、関数型プログラミングの利点は変数が無いことだ、とか、より安全から、とか、より速いから、などという妄言が満ち溢れています

オブジェクト指向関数型プログラミングは、水と油ではありません。プログラマ自分プログラムに最適なアプローチを選ぶことができます

一般にはあまり知られていないことですが、Haskellにもオブジェクト指向へのサポートがあるんです(Lensライブラリ、これを使用したサードパーティライブラリ最近増えてきています)。

この記事を読んだオブジェクト指向プログラマあなたが、少しでも関数型プログラミングに(そしてHaskell)興味を持ってくださって、ホームセンター大人用オシメのコーナーが大賑わいになれば幸いです。。

2014-03-06

仮想Ubuntu最小インストールからCを使えるようにする

とりあえずVirtualBoxインストール。ここで躓く人は話にならんので置いていく。

http://archive.ubuntu.com/ubuntu/dists/saucy/main/installer-i386/current/images/netboot/mini.iso

こいつをダウンロードする。インストールCDROMのイメージファイルだ。ウインドウ環境とかなくてCUIだけのやつ

VirtualVBoxで「新規」とする。

名前CUI Ubuntu(なんでもいい)

タイプ: Linux

バージョンUbuntu

こう打ったら「続ける」を押す

メモリは1024MBくらいでいいんじゃないの。大したことしないし

仮想ハードドライブは「作成する」フォーマットはVDIでよろしい

ストレージタイプは可変でも固定でもいいけど俺なら可変にするかな

で、8GB作成。Cをいじるなら十二分すぎる。2GBくらいでもいいよ

次。「設定」の「ストレージ」でIDEが空になってると思うからIDE」の部分を選択して「+」のついたアイコンを押す。丸い方ね。CDROMの代わりだから

OKを押したら「起動」をクリック

Ubuntuの画面が出ると思うから、矢印で「Install」を選んでエンター。言語選択になるからJapaneseね

キーボード初心者なら日本語キーボード使ってるだろうからそれに従う。不安なら、「2」の上が「@」になってればUSキーボード、「”」になってれば日本語キーボード

Ubuntuの画面に入ると抜けられなくなるから、抜ける時は「Alt」を押せばいい。多分。

MacだとCommandキーから

あとアーカイブミラーかいろいろ聞かれるけどデフォルトおk

そうこうしてるとインストールが始まるから数分眺めてればよろしい

本名とか聞かれるけどスルーでよい。ユーザー名は大事からよく使うものを。パスワードも一応堅牢ものにしようね

ホームディレクトリ暗号化しなくよろし。盗まれて困るようなもの作らないでしょ

その後英語タイムゾーンはAsia/Tokyoか?って聞いてくるのでYES(あるいは「はい」)

パーティションは全体を使うでおkディスクデフォルトで。

ディスクに変更を加えるか?」のデフォルトがNOなのでYESを押す

そうすると「ベースシステムインストールしています」と出るのでまた数分待つ。お茶でも入れよう

セキュリティアップデートについて聞かれるな……。手動でいいんじゃないの?うっかりさんは自動で。

でまた待たされるのでお茶で一杯のんで。

適用するプログラムの一覧とか出るけど、特にこれってのがなければ無視で。後から入れられるので。あ、G++があるかどうか確認せずに次いっちゃった。まあいいか

GRUBがどうのとか聞かれるけどVirtual環境マルチブートする意味ほとんどないのでそのままYES

システム時計UTCおk

そうこうしてるうちに「インストールおめでとう」みたいな感じになって最初の画面にもどるので

電源OFFで。構わん。OFFで。

「設定」の「ストレージ」でさっきのmini.isoを外す。選択して「ー」ボタンで外せるから

そこまでしたらもっかい起動してみて。

ubuntu login: _

みたいになったら成功

登録したユーザーパスワードを打ったらログインできる。できない人は打ち間違いかもしれないのでやりなおし。

ここで気づいたのだが、端末のフォント日本語対応してないので次のコマンドを打つ

export LANG=C

export LOCALE=C

この2つ。エラーがこなければ多分おk。で

sudo apt-get install g++

タイプするとg++がインストールされる。いろいろ聞かれるけど全部エンターでおk

お疲れ様

2014-02-15

Python無名関数っぽいUnixコマンド作った。

GitHubとかブログやってないからここに書いておく。

使い方

標準入力を使いまわしたいとき

... | fun x:: cmd1 x : cmd2 x : ... : cmdn x | ...

ただしcmdにはサブシェルパイプなどは使用できない。

標準入力をそのまま利用する場合と一行毎に処理する場合

一行毎に処理する場合はxargs -Iを利用する。

$ ls *txt
a.txt b.txt
$ cat a.txt
1
$ cat b.txt
2
$ ls *txt | fun x:: echo x : cat x
a.txt b.txt
1
2
$ ls *txt | xargs -Ix fun _:: echo x : cat x
a.txt
1
b.txt
2

コード(fun)

>と<はそれぞれ大小の不等号で置き換えてくださいな

#!/usr/bin/env python
import sys
from subprocess import *

def take_variable(var):
	# check the syntax of variable (http://www.gnu.org/software/bash/manual/bash.html)
	# variable ::= (_|[A-z])(_|[A-z]|[0-9])*
	# variable contained space
	if len(var.split()) > 1:
		raise Exception('fail: the variable contained space')
	# check head
	if not (var[0].isalpha() or var[0] == '_'):
		raise Exception('fail: the variable contained wrong character')
	# check the body of variable
	b = True
	i = 0
	for c in var[1:]:
		i += 1
		# is variable contained invalid character?
		if not (c.isalpha() or c.isdigit() or c == '_'):
			b = False
			break
	# no exception if thre are only spaces after variable
	if not b and not var[i:].isspace():
		raise Exception('fail: the variable contained wrong character')
	elif b:
		return var[0]
	else:
		return var[:i]

def parse(var_to_cmds):
	# check the position of '::'
	try:
		pos = var_to_cmds.index('::')
	except Exception:
		raise Exception('not exists "::"')
	var = var_to_cmds[:pos]
	cmd_str = var_to_cmds[pos+2:]
	# check the format of variable and commands
	if var ==  '':
		raise Exception('fail: no variable before "::"')
	elif cmd_str == '':
		raise Exception('fail: no commands after "::"')

	return (take_variable(var),cmd_str)


if __name__ == '__main__':
	# parse variable and commands
	try:
		var,cmd_str = parse(' '.join(sys.argv[1:]))
	except Exception, e:
		print >>sys.stderr, e
		sys.exit(1)

	# var -> val
	val = sys.stdin.read().replace('\n',' ')
	# mapping and split by ':' again
	commands = map(
			(lambda cmd: cmd.replace(' '+var+' ',' '+val+' ')),
			cmd_str.split(':'))

	# exec command
	for cmd in commands:
		try:
			# need split for remove spaces
			check_call(cmd.split())
		except Exception,e:
			# print >>sys.stderr, e
			sys.exit(1)

本当はfunじゃなくて\(バックスラッシュ)で、:: じゃなくて→にしたかったんだけど、シェルが置き換えちゃうからしかたない

シェルの改造は禁断の手段だし

2013-10-03

Linux Mint 15 (XFCE版) で wgetプロキシサーバを指定する

他の Linux 同様に、環境変数を読むようですね。

export http_proxy="http://プロキシサーバ名>:<ポート>"

export https_proxy="http://プロキシサーバ名>:<ポート>"

などと指定すればOKのようです。

sudo wget のように、スーパーユーザーで利用するときは、当然スーパーユーザー環境で動作するので、私は

su

スーパーユーザー根本的にシェルユーザーを切り替えて、sudo 切り替えなしで wget を利用しました。

すなわち suスーパーユーザーになってから export http_proxy=... を発行。sudo wget ... ではなくそのまま wget ...。

sudo export

は "command not found"。"export" は DOS の内部コマンドみたいなものなのでしょう。

以上のことは、インストール最初日本語化設定のときに使いました。

2013-05-28

Modern Masters

暇だったので現時点でサルベに載ってるカード価格調査をしてみた。

アンコモンとかはしらん。こうやって見ると意外と安いカードの多いことで...

~500(含カスレア)

50 Molten Disaster

50 Verdeloth the Ancient

50 Earwig Squad

120 Skeletal Vampire

149 Rude Awakening

150 Ryusei, the Falling Star(M)

200 Jugan, The Rising Star(M)

300 Angel's Grace

300 Stonehewer Giant

300 Meloku the Clouded Mirror

300 Countryside Crusher

300 Greater Gargadon

350 Dragonstorm

399 Death Cloud

400 Pyromancer's Swath

400 Jhoira of the Ghitu

400 Cold-Eyed Selkie

420 Oona, Queen of the Fae

450 City of Brass

473 Keiga, the Tide Star(M)

473 Squee, Goblin Nabob

498 Scion of Oona

計22枚(M=3) 神話抜きの平均=300,47円

1000

525 Adarkar Valkyrie

700 Divinity of Pride

700 Figure of Destiny

735 Grand Arbiter Augustin IV

750 Reveillark

800 Demigod of Revenge

800 Extirpate

800 Lotus Bloom

800 Yosei, the Morning Star(M)

890 Life from the Loam

10(1) 744,44円

1001~1500

1000 Gifts Ungiven

1000 Knight of the Reliquary

1000 Kataki, War's Wage

1050 Woodfall Primus

1100 Progenitus(M)

1100 Academy Ruins

1155 Sarkhan Vol(M)

1180 Ethersworn Canonist

1180 Blood Moon

1200 Tombstalker

1200 Summoner's Pact

1300 Maelstrom Pulse

1300 Kira, Great Glass-Spinner

1500 Bridge from Below

1500 Tooth and Nail

1500 Blinkmoth Nexus

計16(2) 1215,00円

1501~

1600 Kokusho, the Evening Star(M)

1600 Glimmervoid

1600 Aether Vial

1780 Pact of Negation

1800 Engineered Explosives

1800 Vedalken Shackles(M)

2200 Doubling Season

2400 Elspeth, Knight Errant(M)

2500 Cryptic Command

2700 Arcbound Ravager

2730 Sword of Light and Shadow(M)

2900 Kiki-Jiki, Mirror Breaker(M)

3680 Sword of Fire and Ice(M)

5670 Vendilion Clique(M)

6300 Dark Confidant(M)

12500 Tarmogoyf(M)

計16(9) 2025,71円

2013-05-19

以前フロッピーディスクはもう古い!こんなの見ても誰も分からん!とか言って

俺のかんがえるさいきょうの保存アイコン()をドヤ顔で見せるのが流行ったが、

じゃあお前の触っているMacBookcommandアイコンは一目で意味がわかんのかとふと思った。

2013-03-23

プロテクト強化後のもふったーも予想以上に酷かった件(追記あり)

ことのあらまし
  1. Twitterクライアントもふったーの作者「TweetDeckのconsumer secret簡単に抜ける、終わってる」(http://blog.livedoor.jp/blackwingcat/archives/1760823.html)
  2. 別の誰か「もふったーのconsumer secretも簡単に抜ける」(http://d.hatena.ne.jp/kusano_k/20130318/1363640368)
  3. もふったーの作者「プロテクト強化した」(http://blog.livedoor.jp/blackwingcat/archives/1762970.html)

プロテクトかけたアルゴリズムを実装したバージョン差し替え」たなんて言われると本当に「プロテクト」がかかっているのか確かめてみたくなるのが人情というもの。というわけで、プロテクト強化後のもふったー(v0.9.6b)からconsumer secretが抜けるか試してみた。結論から言うと、あっけなく取り出せた。以下に手順を記す。

手順

動作がよくわかっていないアプリケーションを解析して仕様を明らかにすることをリバースエンジニアリングと呼ぶ。ソフトウェアリバースエンジニアリングは基本的に対象を逆アセンブルしてひたすら読むことによって行う(その補助に1命令ずつ実行してレジスターやメモリーの様子を観察することもある)。しかし、よっぽど小規模なものでなければオブジェクトコード全体を逆アセンブルして最初から最後まで読むなんてのは不可能だ。人間の読速度には限界があるし、時間も有限だからだ。そして、詳しい動作を知りたい部分というのは全体のごく一部であることが多いので全逆アセンブリを読むのには非常に無駄が多い。

からリバースエンジニアリングはいかに詳らかにすべき動作を行っているコードを絞り込むか(=読むべき逆アセンブリを少なくするか)が重要になる。

この場合も同様だ。TwitterGUIクライアントを頭から読むのは到底無理なので、どうやって解析すべきコードの範囲を狭めるかを考えた。それにはOAuth認証においてconsumer secretがどのような役割を果たすのかを知る必要がある。

OAuth認証で、consumer secretはそのままサーバーに送信されたりはしない。signatureの生成にHMAC-SHA1が使われ、その鍵にconsumer secretが使われる。HMACは次のように算出される。

HMAC (K,m) = H ((K ⊕ opad) ∥ H ((K ⊕ ipad) ∥ m))

ここで

である

まずはこのあたりから攻めようと思った。SHA-1計算はいくつか特徴的な定数が使われるので、そこからSHA-1計算に使われているであろう関数444190を特定する。この関数エントリーポイントに中断点(ブレークポイント)を設定してOAuth認証をさせるべくもふったーの「ブラウザ認証ボタンを押す。狙い通り中断するので関数を抜けるまで実行する。関数401100の4012DAに出た。少し下を見るとこのようになっている。

CPU Disasm
Address   Hex dump          Command                                      Comments
00401311  |.  33F6          xor     esi, esi
00401313  |   8D8C24 A40000 /lea     ecx, [local.54]
0040131A  |.  394C24 14     |cmp     dword ptr ss:[local.90], ecx
0040131E  |.  75 0E         |jne     short 0040132E
00401320  |.  3BF5          |cmp     esi, ebp
00401322  |.  73 29         |jae     short 0040134D
00401324  |.  0FB68434 A400 |movzx   eax, byte ptr ss:[esi+esp+0A4]
0040132C  |.  EB 21         |jmp     short 0040134F
0040132E  |   3BF5          |cmp     esi, ebp
00401330  |.  73 1B         |jae     short 0040134D
00401332  |.  8B5424 18     |mov     edx, dword ptr ss:[local.89]
00401336  |.  52            |push    edx                                 ; /Arg1 =  [LOCAL.89]
00401337  |.  8D8C24 FC0000 |lea     ecx, [local.33]                     ; |
0040133E  |.  8BD6          |mov     edx, esi                            ; |
00401340  |.  E8 CB4D0000   |call    00406110                            ; \mofooter.00406110
00401345  |.  83C4 04       |add     esp, 4
00401348  |.  0FB6C0        |movzx   eax, al
0040134B  |.  EB 02         |jmp     short 0040134F
0040134D  |   33C0          |xor     eax, eax
0040134F  |   34 5C         |xor     al, 5C
00401351  |.  888434 B80000 |mov     byte ptr ss:[esi+esp+0B8], al
00401358  |.  83C6 01       |add     esi, 1
0040135B  |.  83FE 40       |cmp     esi, 40
0040135E  |.^ 72 B3         \jb      short 00401313
00401360  |.  895C24 3C     mov     dword ptr ss:[local.80], ebx
0040134F  |   34 5C         |xor     al, 5C

が注意を引く。もしかしてこれはopadとのxorではないか?

00401351  |.  888434 B80000 |mov     byte ptr ss:[esi+esp+0B8], al

xorした結果を格納している。

先ほどの中断点は無効化しこのループを抜けた地点である401360まで飛ばす。この時点でesp+0B8を見ると次のようになっている。

Hex dump
64 2E 16 64|37 04 32 6D|0F 0D 26 29|3A 37 1F 2F|
18 69 6E 6E|0D 25 29 33|11 34 29 69|12 36 24 1E|
05 16 33 6A|04 3B 0E 68|7A 5C 5C 5C|5C 5C 5C 5C|
5C 5C 5C 5C|5C 5C 5C 5C|5C 5C 5C 5C|5C 5C 5C 5C|

あとはこれと5Cとをxorすればconsumer secretが手に入る。終わり。

追伸

はてな増田スーパーpre記法で半角の<>が含まれていると投稿が出来ないのを早く直してください。

3/23 18:45追記

もふったーの作者から反応があった。「本気だったつもりのもふったーのデバッグ処理が残ってた」らしい(http://blog.livedoor.jp/blackwingcat/archives/1763951.html)。修正したとのことなので最新版(v0.9.6e)を見てみた。確かに若干変更されているが何の問題もない。SHA-1の呼び出しに中断点を設置して渡されているバイト列を見るだけ。

CPU Disasm
Address   Hex dump          Command                                  Comments
00401324  |.  8D4424 20     |lea     eax, [local.102]
00401328  |.  50            |push    eax                             ; /Arg1 = 
00401329  |.  E8 623A0400   |call    00444D90                        ; \mofooter.00444D90

ここでeaxが指すメモリーを見ると以下のようになっている。

01 23 45 67|89 AB CD EF|FE DC BA 98|76 54 32 10|
F0 E1 D2 C3|00 02 00 00|00 00 00 00|40 00 00 00|
40 4F 73 53|62 54 5C 7E|59 57 53 42|55 45 7A 57|
61 47 7A 5B|42 4F 7B 61|5D 66 5E 7A|42 7F 40 63|
79 66 05 55|79 4C 60 42|02 10 36 36|36 36 36 36|
36 36 36 36|36 36 36 36|36 36 36 36|36 36 36 36|

先頭32バイトゴミ無視して0x36とxorすればconsumer secretが得られる。

2013-03-13

サーバ初心者Webサービスを公開するうえで考えたこと

だって自作Webサービス公開しました

http://www.radiosonde.net/

これまで他の人に用意してもらったサーバ自分プログラムを動かしたことはありましたが

自分自身で一からサーバをセットアップしたことはほとんどなかったので、いろいろとハマりました。

作業を進める上で困ったり考えたりしたことを書いていきます

ちなみにサーバ自体はさくらのクラウドOSにはCentOSを使用しているので、それ前提のお話になります

SSHファイヤーウォールの設定

最初サーバを起動してから速やかにSSHファイヤーウォールの設定を変更しました。

はてブなんかでも定期的に話題になっているのでおなじみですね。

SSHポートを22以外の別のポートに変更する

rootによるリモートログインを禁止する

パスワードログインを禁止し、鍵認証有効にする

・念のためrootパスワードを潰しておく

SSHHTTP(S)など、どうしても公開しなければならないポート以外は遮断する

SSHポートについてIP制限が行えるならば尚良い

さらっと書きましたが、設定をミスって自分自身もログインできなくなり、何度かOSの再インストールを繰り返しています

から気付いた事ですが、さくらのクラウドではクラウド管理画面のリモートスクリーン経由でローカルログインできるので

別にOSインストールしなくてもiptablesの設定を変更できたんですよね...

逆に言うといくらファイヤーウォールとSSHを設定しても管理画面にパスワードログイン環境が残ってしまうので

パスワード管理には引き続きしっかり気を使う必要がある。ということでもあります


Webアプリの動作が重い

httpd,php,mySQL,memcachedなど必要サービスインストール、設定し

作成したWebアプリプログラムを乗せて動かしてみました。が、動作が重いような...

開発環境ではさくさく動いていたのに、本番環境ではどのページ遷移ももっさりしています

abで計測してみたところ、開発環境のおよそ2分の1のスコアとなってしまいました。

開発環境が仮想2コアのメモリ1Gだったのに対し、本番環境が仮想1コアのメモリ2G

CPUの性能について半減しているのでそのせいかな、と思いつつ設定を見なおしていたところ

特に使っていないと思われたipv6を停止した途端にパフォーマンス改善されました。

ページ遷移に伴うもっさり感が解消され、abの計測結果も開発環境と遜色ない結果が出ています

デフォルト有効になっていたipv6の影響により余計な処理が走っていたのかもしれません。


サーバから送信したメール迷惑メールと判定される

パフォーマンス改善に喜んだのも束の間、会員登録などの処理でWebアプリからメールを送信したところ、Gmail宛のメールがことごとく迷惑メールと判定されるという事案が発生。

spfの設定を行なうメールの内容について吟味するなどの回避策を試してみましたが一向に改善されません。

試しにHotMailexciteメールアカウントに送信したところ、そちらではそもそもメールを受け付けてもらえずエラーコードが返って来る始末。

困り果てていたところ、エラーの内容からサーバIPがspamhousにスパム送信元として登録されていることが判明しました。

postfixホスト名の設定がデフォルトで「localhost.localdomain」などとなっており、それをそのまま使っていたためにGmailスパム送信元として通報してしまったようです。

設定を修正し、spamhousに解除依頼を提出。事なきを得ました。


KVSの変更

クラウドを利用すれば、サーバを停止することなく簡単な設定でスケールできるようになる。

と、自分勝手に思い込んでいたせいなのですが、消えては困るデータの一部をmemcachedに保存する実装を行なっていました。

実際のところさくらのクラウドではサーバを完全に停止しなければプラン変更を実施できないし

そもそもサーバが落ちたらどうするんだよ。ということで、急遽KVSを変更する必要に迫られました。

速度の低下が気にかかったため、いくつかの候補を実際に動かし

phpスクリプトから1万件のデータ読み書きを行うという形でmemcached比較してみたところ次のような結果に。

サービス1万件書込1万件読込
memcached 2.55秒 2.30秒
handlersocket 21.23 2.71秒
InnoDB20.23 5.10
kyotoTycoon 8.22秒 7.72秒

さすがに読み書きそれぞれmemcachedが最速ですが、読み出しについてはhandlersocketも負けていません。mySQLから普通にSELECTしてもmemcachedの2倍程度の時間しかからないという結果が意外でした。

しかしながら書き込みのほうではhandlersocketもmemcached10倍近くの時間がかかっており、少々速度的な影響が気になってきますmemcachedの倍のパフォーマンスを記録したという記事を見たことがあるので、設定、チューニングについて生かしきれていない部分があるのかもしれないとも思いましたが、知識が不足しているところで無理をすると問題が発生した時に対処できないと考え、候補から除外することとしました。

結局、今回の用途では読み込み処理より書き込み処理のほうが圧倒的に多いことも考慮し、kyotoTycoonを採用しました。実際の利用箇所に組み込んでabで計測してみたところ、だいたい30%程度のパフォーマンス低下にとどまっており、これなら許容範囲かと考えています

mySQLレプリケーションが止まる

実行系と参照系に分ける形でmySQLレプリケーションを行なっていたのですが、度々レプリケーションが停止する現象が発生しました。

一部のテーブルについて肥大する可能性が考えられたため、参照系に接続するプログラムで使わないテーブルをレプリケーションから除外していたのが原因です。

例えばtabelAをレプリケーションし、tableXをレプリケーションしないという設定にしたうえで

実行系でINSERT INTO `tableA` SELECT `value` FROM `tableX`などといったクエリを発行すると、参照系にtableXが無いためエラーが発生して止まってしまます

レプリケーションするテーブルを限定する場合プログラム側でも注意を払わないと危険です。当たり前ですが。

サーバ監視にmonitを使用

監視といえばcactinagios定番なのかもしれませんが、設定が複雑そうで尻込みし、monitを使用することにしました。

簡単な設定でloadaverageやメモリHDDの使用量をチェックできるほか

httpdmysqldなどといったサービスプロセス監視し、もし落ちていたら自動で起動してくれるので助かります

Webアプリの秘匿

パスワード保護を行うとしても、サイト全体の管理画面など自分しか使わないプログラムWeb晒しておきたくない。

というわけで、一部のWebアプリを秘匿する設定を行いました。

管理画面のWebアプリを9999番など閉じているポートに設置した上で、SSHを利用したトンネルを掘ります。といっても

ssh -t -L 9999:localhost:9999 user@xxx.xxx.xxx.xxx

上記のようなコマンド管理画面のWebアプリを置いたサーバログインするだけです。

ブラウザアドレス欄にhttp://localhost:9999/と打ち込めば、接続が開いている間のみアクセス可能になる感じですね。

サーバログインできる人でなければ実行できないことなので、気分的にある程度安心します。

SSHログバックアップ

自動ログバックアップを行いたいと考えたのですが、パスワード無しの鍵でログインして転送する形には抵抗がありました。

調べてみたところ、authorized_keysに公開鍵を記入する際の設定で、その鍵でできることを制限するという手段があるようでした。

具体的には、authorized_keysに

no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command="some commands" ssh-rsa AAAAB3NzaC1yc2EAAA...

などとして公開鍵を追加しておくと、その鍵でログインした直後にcommand=""の部分で設定したコマンドを実行して接続を終了する挙動となり

接続フォワードもできなくなるため、パスワード無しでも鍵の流出に関するリスクを最低限に留めることができるというわけです。

commandの実行結果は標準出力から受け取ることができるので、例えばcommand=""の部分にファイルの内容を表示する処理を設定していたとすれば

ssh -i .ssh/no_password_key user@xxx.xxx.xxx.xxx > /path/to/file

などとしてログインの結果をファイルに書き込むだけで、簡単にファイル転送が実現できます


まとめ

他にも大小さまざまな問題に行きあたりましたが、忘れてしまったor書ききれないのでここまでとします。

たった1つのサイトを公開するにしても問題というのは尽きないものだと実感させられました。

今は基本的な情報だけでなく、ちょっと突っ込んだ内容でも検索で解決していけるので嬉しいですね。手がかりを残してくれた先達に感謝することしきりです。

現状ではひとまずの見切りを付けて公開していますが、より堅牢で負荷に強いサーバとなるよう、随時チューニングを行なっていこうと考えています

最後

作ったWebサービスについて少し書きます

サイト名は「Radiosonde」

個人サイトや小規模な商業サイトなどプロモーションにあまりお金をかけられないサイトを主な対象とした、無料で出稿できる広告ネットワークサービスです。

既存サービスで近いのは「あわせて読みたい」や「zenback」、各社提供RSS相互リンクサービスなどになるでしょうか。

広告としての体裁がある分、それらより若干積極的な性質になるのではと考えています

現時点ではサービス本体のプロモーションに苦心するという本末転倒のものの状況でありますが、もしよろしければ見ていただけると嬉しいです。

2012-12-12

日本以外どこも「ミサイル」なんて言葉はまったく使ってない?

http://www.wired.com/dangerroom/2012/12/nork-problems/

“North American Aerospace Defense Command officials acknowledged today that U.S. missile warning systems detected and tracked the launch of a North Korean missile at 7:49 p.m. EST,” noted the statement. “The missile was tracked on a southerly azimuth. Initial indications are that the first stage fell into the Yellow Sea. The second stage was assessed to fall into the Philippine Sea. Initial indications are that the missile deployed an object that appeared to achieve orbit. At no time was the missile or the resultant debris a threat to North America.

まったく使ってないわけじゃないみたいよ。

2012-02-23

The file '/etc/passwd' exists on the system, but it is not present in the rkhunter.dat file.

FreeBSD security run output (cron@/usr/local/etc/periodic/security/415.rkhunter)

Running rkhunter...

Warning: The file '/etc/passwd' exists on the system, but it is not present in the rkhunter.dat file.

http://permalink.gmane.org/gmane.comp.security.rkhunter.user/2584

the cron job running RKH uses a PATH which includes /etc and as such RKH sees /etc/passwd as a command (and so to be checked).

But when the user runs 'rkhunter --propupd' his PATH doesn't include /etc and so /etc/passwd is not recorded in the rkhunter.dat file.

You could try adding:

USER_FILEPROP_FILES_DIRS="/etc/passwd"

to your config file. RKH should then always see the file regardless of the PATH.

# rkhunter --propupd
[ Rootkit Hunter version 1.3.8 ]
File updated: searched for 167 files, found 115
# rkhunter --propupd /etc/passwd
Filename is not in the "rkhunter.dat" file: /etc/passwd
# env PATH=${PATH}:/etc rkhunter --propupd /etc/passwd
Filename is not in the "rkhunter.dat" file: /etc/passwd
# env PATH=${PATH}:/etc rkhunter --propupd
[ Rootkit Hunter version 1.3.8 ]
File updated: searched for 167 files, found 116
# env PATH=${PATH}:/etc rkhunter --propupd /etc/passwd
[ Rootkit Hunter version 1.3.8 ]
File updated: searched for 167 files, found 1 of 116
# rkhunter --propupd /etc/passwd
[ Rootkit Hunter version 1.3.8 ]
File updated: searched for 167 files, found 0 of 115
# rkhunter --propupd /etc/passwd
Filename is not in the "rkhunter.dat" file: /etc/passwd
# rkhunter --propupd
[ Rootkit Hunter version 1.3.8 ]
File updated: searched for 167 files, found 115
# echo 'USER_FILEPROP_FILES_DIRS="/etc/passwd"' >> /usr/local/etc/rkhunter.conf
# rkhunter --propupd /etc/passwd
Filename is not in the "rkhunter.dat" file: /etc/passwd
# env PATH=${PATH}:/etc rkhunter --propupd /etc/passwd
Filename is not in the "rkhunter.dat" file: /etc/passwd
# rkhunter --propupd
[ Rootkit Hunter version 1.3.8 ]
File updated: searched for 167 files, found 116
pen4# rkhunter --propupd /etc/passwd
[ Rootkit Hunter version 1.3.8 ]
File updated: searched for 167 files, found 1 of 116

2011-12-29

Portable electronic equipment battery technology

1, about the trickle charge, rapid charging and stable battery charging algorithm

According to the energy requirements of the final application, a battery may contain up to 4 lithium ion or lithium polymer battery core, its configuration will have a variety of change, at the same time with a mainstream power adapter: direct adapter, USB interface or car charger. Remove the core quantity, core configuration or power adapter type difference, the battery has the same charge characteristics. So they charge algorithm. Lithium ion and li-ion polymer battery best charging algorithm can divided into three phases: trickle charge, rapid charging and stable charge.

trickle charge. For depth discharge core to charge. When core voltage in less than about 2.8 V, use a constant 0.1 C of the current charging for it.

fast charging. Core voltage trickle charge more than the threshold, improve the charging current rapid charging. Fast charging current should be lower than 1.0 C.

stable voltage. In the fast charging process, once the core 4.2 V voltage, stable voltage phase began. This is through the minimum charge current or timer or of the two joint to interrupt charge. When the minimum current below about 0.07 C, can interrupt charge. The timer is to rely on a default to trigger the timer interrupt.

Advanced battery charger with additional security function normally. For example, if the core temperature exceeds the given window, usually 0 ℃-45 ℃, charge will be suspended.

Remove some very low-end equipment, now on the market/li-ion polymer lithium ion battery solutions are integrated with the outer components or, in accordance with the characteristics of the charging to charge, this is not just to get better effect charge, but also for safety.

lithium ion/polymer battery charge is an example of applications-double input 1.2 A lithium battery charger LTC4097

LTC4097 can be used to exchange adapter or USB power supply for single quarter/polymer lithium ion battery. Figure 1 for double input 1.2 A lithium battery charger LTC4097 schemes. It USES constant current/constant voltage algorithm charging, from exchange adapter power charge, programmable filling up to 1.2 electric current A, and with USB power can be as high as 1 A, at the same time, automatic detection in each input voltage whether there. This device also provide USB the current limit. Applications include PDA, MP3 players, digital camera, light portable medical and test equipment and big color cellular phone. The performance characteristics: no external micro controller charging termination; The input power automatic detection and choice; Through the resistance from the exchange of charging adapter input can be as high as 1.2 A programming charge current; The resistance of programmable USB charging current is up to 1 A; 100% or 20% USB charging current set; The input power output and existing bias NTC (VNTC) pin as a 120 mA drive ability; NTC thermistors input (NTC) pin for temperature qualified charged; Pre-settings battery voltage with floating plus or minus 0.6% accuracy; Thermal regulation maximize charge rate and free hot air LTC4097 can be used to exchange adapter or USB power supply for single quarter/polymer lithium ion battery. The use of constant current/constant voltage algorithm charging, from exchange adapter power charge, programmable filling up to 1.2 electric current A, and with USB power can be as high as 1 A, at the same time, automatic detection in each input voltage whether there. This device also provide USB the current limit. Applications include PDA, MP3 players, digital camera, light portable medical and test equipment and big color cellular phone.

2, lithium ion/polymer battery scheme

Lithium ion/polymer battery charge scheme for different number of core, core configuration, and power types are different. At present mainly have three main charging scheme: linear, Buck (step-down) switch and SEPIC (booster and step-down) switch.

2.1 linear scheme

When the input voltage in big with the charger with sufficient clearance of core after opening voltage, it is linear scheme, especially 1.0 C fast charging current than 1 A big too much. For example, MP3 players usually only one core, capacity from 700 to 1500 mAh differ, full charge voltage is open 4.2 V. MP3 player power is usually the AC/DC adapter or USB interface, the output is the rule of 5 V; At this time, the linear scheme is the most simple, most charger of the efficiency of the scheme. Figure 2 shows for lithium ion/polymer battery solution linear scheme, basic structure and linear voltage neat device.

linear scheme charger application examples-double input Li + charger and intelligent power source selector MAX8677A

MAX8677A is double input USB/AC adapter linear charger, built-in Smart Power Selector, used for rechargeable single quarter by Li + batteries portable devices. The charger integration of the battery and the external power source and load switch charging all the power switch, so that no external MOSFET. MAX8677A ideal used in portable devices, such as smart phones, PDA, portable media players, GPS navigation equipment, digital camera, and digital cameras.

MAX8677A can work in independent USB and the power input AC adapter or two input either one of the input. When connecting external power supply, intelligent power source selector allows the system not connect battery or can and depth discharge battery connection. Intelligent power source selector will automatically switch to the battery system load, use the system did not use the input power supply parts for battery, make full use of limited USB and adapter power supply input. All the needed electric current detection circuit, including the integration of the power switch, all integration in the piece. DC input current highest limit can be adjusted to 2 A and DC and USB input all can support 100 mA, 500 mA, and USB hung mode. Charge current can be adjusted to as high as 1.5 A, thus support wide range of battery capacitive. Other features include MAX8677A thermal regulation, over-voltage protection, charging status and fault output, power supply good surveillance, battery thermistors surveillance, and charging timer. MAX8677A using save a space, hot enhanced, 4 mm x 4 mm, 24 of the pins TQFN encapsulation, regulations, work in exceptional temperature range (40 ~ + 85 ℃).

2.2 Buck (step-down) switch scheme

When A 1.0 C of the charging current more than 1 A, or the input voltage of the core than with high voltage open many, Buck or step-down plan is A better choice. For example, based on the hard drive in the PMP, often use single core lithium ion battery, the full of open is 4.2 V voltage, capacity from 1200 to 2400 mAh range. And now PMP is usually use the car kit to charge, its output voltage in a 9 V to 16 between V. In the input voltage and battery voltage is the voltage difference between high (minimum 4.8 V) will make linear scheme lowers efficiency. This kind of low efficiency, plus more than 1.2 A 1 C fast charging electric current, have serious heat dissipation problems. To avoid this kind of situation, will the Buck scheme. Figure 3 for lithium ion/polymer battery charger scheme Buck diagram, basic structure with Buck (step-down) switching voltage regulators completely the same.

2.3 SEPIC (booster and step-down) switch scheme

In some use of three or four lithium ion/polymer core series equipments, charger of the input voltage is not always greater than the battery voltage. For example, laptop computers use 3 core lithium ion battery, full charge voltage is open 12.6 V (4.2 V x3), capacity is 1800 mAh to 3600 mAh from. Power supply input or output voltage is 1 6 V AC/DC adapter, or is car kit, the output voltage in a 9 V to 16 between V. Apparently, the linear and Buck solutions are not for this group of batteries. This is about to use SEPIC scheme, it can in the output voltage is higher than when the battery voltage, can be in the output voltage less than when the battery.

3, and power detection algorithm is proposed

Many portable products use voltage measurements to estimate the remaining battery power, but the battery voltage and surplus power relationship but will with the discharge rate, temperature and battery aging degree of change, make this kind of method can top 50% margin of error. The market for longer to use product demand unceasingly strengthens, so the system design personnel need more accurate solution. Use capacity check plan come to measure battery or consumption of electricity, will be in a wide range of application power to provide more accurate estimate of the battery power.

3.1 power detection algorithm is one of the examples of application, function complete list, double the battery portable battery application design

power detection principle. Good capacity check plan at least to have battery voltage, temperature and battery electric current, measuring method; A micro 9 a; And a set of and the verification of the punishment power detection algorithm is proposed. Bq2650x and bq27x00 is full capacity check program function, with a measuring voltage and temperature of the digital converter (ADC) and a measuring electric current and charging sensor the asp. These capacity check plan also has a microprocessor, is responsible for the implementation of the Texas instruments power detection algorithm is proposed. The algorithm can compensate the lithium ion battery life.low self-discharge, aging, the temperature and discharge rate, and other factors. Chip embedded microprocessor as host system processor save these calculation burden. Capacity check program can provide remaining power state information, bq27x00 series products also offer surplus can Run Time (Run Time to Empty) host may at any Time to capacity check plan these information query, then LED indicator light through or displays will inform the user battery. Capacity check meter is very easy to use, the system processor need only configuration 12 C or HDQ communication drive can.

The battery circuit description. Figure 4 (a) can be used for identification of IC functions with typical application circuit batteries. According to the use of IC testing program is different, the battery needs to have at least three to four outside the terminal.

VCC and BAT pins will even to the battery voltage, so that for, C power and the battery voltage measurement. The battery is connected a grounding resistance smaller detection resistors, let capacity check meter high impedance SRP and SRN input can monitor sensor resistance on both ends of the voltage. Through testing the current flows through a resistor can be used to judge the battery or release the amount of electricity. Designers choose detection resistance value must be considered when resistance on both ends of the voltage can't more than 100 mV, low resistance may be more hours in current errors. Circuit board layout must ensure that SRP and SRN to testing from as close as possible to the connection of the resistor sensor resistance end; In other words, they should be the Kelvin attachment.

HDQ pin need external and resistors, this resistance should be located the host or the main application, such capacity check plan to the battery and portable devices when sleep function enable connection broken. Advice and resistance choose 10 k Ω.

battery identification. A low cost WeiMao batteries are getting more and more serious, these cells may not contain OEM requirements of security protection circuit. So, genuine battery may contain figure 4 (a) shows the appraisal circuit. When to identify the battery, the host to contain IC (bq26150, the function is cyclic redundancy check (CRC)) issued the battery packs a ask value (challenge), the CRC will contain battery according to this inquiry value and, in the building of the IC in CRC polynomial calculation the CRC value. CRC is based on the host of command and IC secret in the query of the definition of the CRC polynomial completed, the host in CRC values calculated with the calculation result of well battery comparison to identify the appraisal success.

Once the battery through the appraisal, bq26150 will issue commands to ensure that the host and quantity test plan of material lines between normal communication. When the battery connection interruption or to connect, the whole the identification process will be repeated again.

double the battery application. Figure 4 (b) for use bq26500 support double the typical application of lithium ion battery circuit. In order to support more battery, and this circuit is adding a adjustable regulators. Capacity check millions of BAT pin and the bottom of a battery anode linked to complete the variable voltage measurement of the battery.

Host to be able to read capacity check plan of variable voltage measurement battery, to make sure the end of discharging threshold and charging terminate threshold. As for the remaining state power (RemainingStateofCapacity), do not need to read can use directly.

The above bq2650x and bq27x00 etc capacity check plan provides the battery manufacturer a simple to use options, this scheme L [just measuring battery voltage to be precise, so these capacity check plan can be applied to various battery framework, and can support the battery identification and double the battery application '

3.2 power detection algorithm is an example of applications another, can apply to all kinds of general voltmeter new IC.

Today's many manufacturers can provide a variety of voltmeter IC,, the user can choose the suitable function device, to optimize the product price. Use voltmeter measurement of storage battery parameters, the separate architecture allows users in the host custom power measurement algorithm within. Eliminating embedded processor battery cost. On this to Dallase semicconductor company called cases of DS2762 chip for typical analysis. A new separate voltmeter IC, its structure see chart 5 (a) below.

DS2762 application characteristics

DS2762 is a single quarter of lithium battery voltmeter and protection circuit, integrated into a tiny 2.46 mm x 2.74 mm inversion of packaging. Due to internal integration for power detection of high precise resistance, this device is very save a space. It is the small size and incomparable high level of integration, for mobile phone battery and other similar handheld products, such as PDA, etc, are all very ideal. Integrated protection circuit continuously monitoring the battery voltage, over voltage and flow fault (charging or discharge period). Different from the independent protection IC, DS2762 allow main processor surveillance/control protection FET conduction state, such, can DS2762 through the protection of the power system and the control circuit implementation. DS2762 can also charge a battery consumption has depth, when the battery voltage within three V, provide a limit of the charging current recovery path.

DS2762 accurate monitoring battery current, voltage and temperature, the dynamic range and resolution of common satisfy any mobile communication product testing standards. The measurement of current for internally generated when the integral, realize the power measurement. Through the real-time, continuous automatic disorders correct, the precision of power measurement can be increased. The built-in measuring resistance due to eliminate manufacturing process and temperature and cause resistance change, further improve the precision of the voltmeter. Important data stored in 32 bytes, can add the lock EEPROM; 16 bytes of SRAM are used to keep dynamic data. And DS2762 all communication all through the 1-Wire, more communication interface node, minimize the battery and the connection to the host. Its main features for; Single quarter of lithium battery protector; High precision current (power measurement), voltage and temperature measurement; Optional integrated 25 m Ω measuring resistance, each DS2762 after fine-tuning alone; 0 V battery restore charge; 32 bytes can lock EEPROM, 16 bytes SRAM, 64 a ROM;

1-Wire, node, digital communication interface; Support more battery power management, and through the protection system control FET power; Dormancy mode power supply current only 2 µ A (most); Work mode power supply current for 90 µ A (most); 2.46 mm x 2.74 mm inversion of packaging or 16 feet SSOP package led, and both are can choose with or without detection resistance; After has with e

2011-09-21

[][]

ソフトバージョンアップなどの際に

インストール先を変更した場合の関連付けの変更方法です

1.レジストリエディタを起動する

2.HKEY_CLASSES_ROOT\Applications\[実行ファイル名]\shell\open\command

3.(規定)の値にプログラムパスがあるので修正する

注意 Applicationsですapplicationという似た名前があるので混同しないように!

2011-04-02

play on tumblr 動いてる?

via http://coderepos.org/share/browser/lang/javascript/userscripts/playontumblr.user.js?rev=38679 | text post image open : http://gyazo.com/0722c749cb50c704d4e9923bdd6b6fce.png -> http://gyazo.com/e8f082af69a038e0ea58775c2cec7ad5.png — Gist

最新はこれでいいんですか?

誰も話題にしてないので俺だけかな

reblogcount しか動いてなかったので自力で直そうと頑張ってみたが、

よくわからないのでぐっちゃぐちゃになってしまった

プログラミング素人ですすみません

一応動画再生画像の拡大2種の3つに関しては動くようにできた

likeは使ってないのでとくに見てませんすみません

ここがわからない
if (img[n].style.display != 'none') {
  click($X('./a', img[n])[0]);
  return stdin;
}
else{
  click($X('./preceding-sibling::a[1]', img[n])[0]);
  return stdin;
}

および

if (mov[n].style.display != 'none') {
  click($X('.//a', mov[n])[0]);
  return stdin;
}

これは何をしてるんでしょうか?

したままだとどうもうまくいかなかったので丸ごと削ってしまった

クリックすべき要素を直接XPath指定、にしたんだけどマズイ?

以下patchです

@include に www.tumblr.com/queue* も勝手に足してしまいました

どなたかまともにしてくださいm(__)m

--- 20101127_play_on_tumblr.user.js
+++ 20110402_play_on_tumblr.user.js
@@ -6,6 +6,7 @@
 // @include        http://www.tumblr.com/show/*
 // @include        http://www.tumblr.com/tumblelog/*
 // @include        http://www.tumblr.com/tagged/*
+// @include        http://www.tumblr.com/queue*
 // ==/UserScript==
 
 (function() {
@@ -43,25 +44,15 @@
         command: function(stdin) {
           try {
             if (!stdin.length) stdin = execute('current-node');
-            var img = $X('.//div[starts-with(@id, "highres_photo")]', stdin[0]);
+            var img = $X('.//img[contains(@id, "thumbnail_photo_")]', stdin[0]);
             for (var n = 0; n < img.length; n++) {
-              if (img[n].style.display != 'none') {
-                click($X('./a', img[n])[0]);
-                return stdin;
+                click(img[n]);
               }
-              else{
-                click($X('./preceding-sibling::a[1]', img[n])[0]);
-                return stdin;
-              }
-            }
-            var mov = $X('.//div[contains(@id,"watch_") and .//a]', stdin[0]);
+            var mov = $X('.//img[contains(@id,"video_thumbnail_")]', stdin[0]);
             for (var n = 0; n < mov.length; n++) {
-              if (mov[n].style.display != 'none') {
-                click($X('.//a', mov[n])[0]);
-                return stdin;
+                click(mov[n]);
               }
-            }
-            var timg = $X('.//img[contains(@src,"tumblr.com/tumblr_")]|.//img[@class="inline_external_image"]', stdin[0]);
+            var timg = $X('.//img[contains(@class, "inline_external_image")]', stdin[0]);
             for (var n = 0; n < timg.length; n++) {
               click(timg[n]);
             }

2009-04-30

[]

9.0.4入れてみた

解像度が800*600になっちゃう・・・

sudo displayconfig-gtk

sudo dpkg-reconfigure xserver-xorg

どっちもcommand not foundって、どうすりゃいいんじゃ!?八方塞がりッスよ・・・

2009-03-11

[][][][][][]

Deploy Merb, Sinatra, or any Rack App to Heroku

http://blog.heroku.com/archives/2009/3/5/32_deploy_merb_sinatra_or_any_rack_app_to_heroku/

http://heroku.com/pages/quickstart

http://heroku.com/docs

http://heroku.com/

HerokuをGit経由で使ってみる

http://d.hatena.ne.jp/aki-s-119/20081110/1226335713

http://github.com/guides/using-git-and-github-for-the-windows-for-newbies

Windows から Git を使う方法

http://d.hatena.ne.jp/kusakari/20080715/1216091060

msysgit - Google Code

http://code.google.com/p/msysgit/

PuTTYssh2プロトコルを使ってssh接続

http://net-newbie.com/putty.html

>heroku help
=== General Commands

 help                         # show this usage

 list                         # list your apps
 create [<name&gt;]              # create a new app

 keys                         # show your user's public keys
 keys:add [<path to keyfile&gt;] # add a public key
 keys:remove <keyname&gt;        # remove a key by name (user@host)
 keys:clear                   # remove all keys

=== App Commands (execute inside a checkout directory)

 info                         # show app info, like web url and git repo
 open                         # open the app in a web browser
 rename <newname&gt;             # rename the app

 sharing:add <email&gt;          # add a collaborator
 sharing:remove <email&gt;       # remove a collaborator

 domains:add <domain&gt;         # add a custom domain name
 domains:remove <domain&gt;      # remove a custom domain name
 domains:clear                # remove all custom domains

 rake <command&gt;               # remotely execute a rake command
 console <command&gt;            # remotely execute a single console command
 console                      # start an interactive console to the remote

 restart                      # restart app servers
 logs                         # fetch recent log output for debugging
 logs:cron                    # fetch cron log output

 bundles                      # list bundles for the app
 bundles:capture [<bundle&gt;]   # capture a bundle of the app's code and dat
 bundles:download             # download most recent app bundle as a tarba
 bundles:download <bundle&gt;    # download the named bundle
 bundles:animate <bundle&gt;     # animate a bundle into a new app
 bundles:destroy <bundle&gt;     # destroy the named bundle

 destroy                      # destroy the app permanently

=== Example story:

 rails myapp
 cd myapp
 (...make edits...)
 git init
 git add .
 git commit -m "my new app"
 heroku create myapp
 git remote add heroku git@heroku.com:myapp.git
 git push heroku master

2008-10-18

http://anond.hatelabo.jp/20081018072817 の続きだよ

これでおしまいだよ

elisp

sangels.el
(require 'cl)				; for cl-seq

(defvar sangels-movies-dir nil)
(defvar sangels-player "c:/Program Files/GRETECH/GomPlayer/GOM.exe")
(defvar sangels-sort-by 'sangels-sort-by-rate)
(defvar sangels-rate-file "~/.emacs.d/.sangels/rate")
(defvar sangels-buffer "*sangels*")
(defvar sangels-thumbnail "00_thumbnail.jpg")
(defvar sangels-m3u "00_movies.m3u")
(defface sangels-name '((t (:family "fixed" :weight bold :height 3.0)))
  "")
(defface sangels-rate '((t (:family "fixed" :weight bold :height 1.5)))
  "")
(defvar sangels-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map "n" 'next-line)
    (define-key map "p" 'previous-line)
    (define-key map (kbd "RET") 'sangels-select)
    (define-key map (kbd "SPC") 'sangels-select)
    (define-key map "q" 'sangels-quit)
    (define-key map "+" 'sangels-rate-plus)
    (define-key map "-" 'sangels-rate-minus)
    map))
(defvar sangels-mode-hook nil)
(defvar sangels-highlight-overlay nil)
(defvar sangels-rate-alist nil)

(defconst sangels-rate-max 6)

(defun sangels-insert-movies ()
  (save-excursion
    (let* ((inhibit-read-only t)
           (files (remove-if-not
                   (lambda (x)
                     (and (not (member (file-name-nondirectory x) '("." "..")))
                          (file-directory-p x)
                          (member sangels-thumbnail (directory-files x))))
                   (directory-files sangels-movies-dir t)))
           (ids (mapcar 'file-name-nondirectory files)))
      (erase-buffer)
      (setq ids (sangels-sort-ids ids))
      (dolist (id ids)
        (let ((file (expand-file-name id sangels-movies-dir))
              (pos (point)))
          (insert-image-file (expand-file-name sangels-thumbnail file))
          (end-of-line)
          (insert (propertize (format "%-15s " id)
                              'face 'sangels-name))
          (sangels-insert-rate id)
          (insert "\n")
          (put-text-property pos (point) 'sangels-id id))))))

(defun sangels-sort-by-name (a b)
  (string< a b))

(defun sangels-sort-by-rate (a b)
  (or (> (sangels-rate a) (sangels-rate b))
      (sangels-sort-by-name a b)))

(defun sangels-sort-ids (ids)
  (sort ids
        (or sangels-sort-by
            'sangels-sort-by-name)))
(defun sangels-insert-rate (id)
  (let ((rate (sangels-rate id)))
    (insert (propertize (concat
                         (make-string rate ?★)
                         (make-string (- sangels-rate-max rate) ?☆))
                        'sangels-rate t
                        'face 'sangels-rate))))

(defun sangels-current-id ()
  (get-text-property (point) 'sangels-id))

(defun sangels-play-movie (movie)
  (let ((explicit-shell-file-name "cmdproxy")
        (shell-file-name "cmdproxy"))
    (apply
     'call-process-shell-command
     "start" nil "*tmp*" nil
     (mapcar (lambda (x) (concat "\"" x "\""))
             (list sangels-player
                   (unix-to-dos-filename movie))))))

(defun sangels-select ()
  (interactive)
  (let ((id (sangels-current-id)))
    (when id
      (sangels-play-movie (expand-file-name
                           sangels-m3u
                           (expand-file-name id sangels-movies-dir))))))

(defun sangels-quit ()
  (interactive)
  (kill-buffer sangels-buffer))

(defun sangels-rate (id)
  (or (cdr (assoc id sangels-rate-alist)) (/ sangels-rate-max 2)))

(defun sangels-rate-save ()
  (interactive)
  (let ((dir (file-name-directory sangels-rate-file)))
    (unless (file-exists-p dir)
      (make-directory dir t)))
  (with-temp-file sangels-rate-file
    (insert (pp-to-string sangels-rate-alist))))

(defun sangels-rate-load ()
  (interactive)
  (when (file-exists-p sangels-rate-file)
    (with-temp-buffer
      (insert-file-contents sangels-rate-file)
      (goto-char (point-min))
      (setq sangels-rate-alist (read (current-buffer))))))

(defun sangels-rate-plus (&amp;optional n)
  (interactive "p")
  (setq n (or n 1))
  (let* ((id (sangels-current-id))
         (cell (assoc id sangels-rate-alist)))
    (unless cell
      (setq cell (cons id (sangels-rate id)))
      (setq sangels-rate-alist (cons cell sangels-rate-alist)))
    (setcdr cell (+ (cdr cell) n))
    (save-excursion
      (let ((inhibit-read-only t))
        (beginning-of-line)
        (goto-char (next-single-property-change (point) 'sangels-rate))
        (delete-region (point)
                       (next-single-property-change (point) 'sangels-rate))
        (sangels-insert-rate id)))
    (sangels-rate-save)))

(defun sangels-rate-minus (&amp;optional n)
  (interactive "p")
  (setq n (or n -1))
  (sangels-rate-plus (- n)))

(defun sangels-post-command-hook ()
  (save-excursion
    (move-overlay
     sangels-highlight-overlay
     (progn
       (move-beginning-of-line 1)
       (point))
     (progn
       (move-end-of-line 1)
       (forward-line)
       (point))
     (current-buffer))))

(defun sangels-mode ()
  (interactive)
  (kill-all-local-variables)
  (use-local-map sangels-mode-map)
  (setq sangels-highlight-overlay (make-overlay 0 0))
  (overlay-put sangels-highlight-overlay 'face 'highlight)
  (overlay-put sangels-highlight-overlay 'evaporate t)
  (make-local-variable 'post-command-hook)
  (add-hook 'post-command-hook 'sangels-post-command-hook nil t)
  (setq major-mode 'sangels-mode)
  (setq mode-name "Sangels")
  (run-mode-hooks 'sangels-mode-hook)
  (set-buffer-modified-p nil)
  (setq buffer-read-only t))

(defun sangels (&amp;optional arg)
  (interactive "P")
  (when (or arg (not sangels-movies-dir))
    (setq sangels-movies-dir (read-directory-name "movies dir: ")))
  (sangels-rate-load)
  (switch-to-buffer (get-buffer-create sangels-buffer))
  (sangels-insert-movies)
  (sangels-mode))

(provide 'sangels)

2008-10-12

[][]Grass

Table of Contents: ||||||

オープンソースソフトウェアGISOpen Source software and GISOpen Source software and GIS 1 (6)
オープンソース概念Open Source concept1 (2)
オープンソースGISとしてのGRASSGRASS as an Open Source GIS3 (2)
ノースカロライナサンプルデータセットThe North Carolina sample data set 5 (1)
この本の読み方How to read this book5 (2)
GIS概念GIS conceptsGIS concepts 7 (14)
一般的なGIS原理General GIS principles 7 (6)
地理空間データモデルGeospatial data models 7 (4)
GISデータシステムの構成Organization of GIS data and system11 (2)
機能functionality
地図投影法と座標系Map projections and coordinate systems 13 (8)
地図投影原理Map projection principles13 (3)
一般的な座標系とdatumsCommon coordinate systems and datums 16 (5)
GRASSをはじめようGetting started with GRASSGetting started with GRASS 21 (32)
第一歩First steps21 (16)
GRASSダウンロードインストールDownload and install GRASS 21 (2)
データベースコマンド構造Database and command structure 23 (3)
GRASS6のためのグラフィカルユーザインタフェイス: Graphical User Interfaces for GRASS 6: 26 (1)
QGISgis.mQGIS and gis.m
ノースカロライナを用いてGRASSを開始Starting GRASS with the North Carolina 27 (3)
データセットdata set
GRASSデータディスプレイ3D可視化GRASS data display and 3D visualization30 (4)
プロジェクトデータ管理Project data management34 (3)
新しいプロジェクトGRASSを開始Starting GRASS with a new project37 (7)
aのための座標系の定義Defining the coordinate system for a 40 (4)
新しいプロジェクトnew project
空間投影されていないxy座標系Non-georeferenced xy coordinate system 44 (1)
座標系の変換Coordinate system transformations44 (9)
座標系のリストCoordinate lists 45 (2)
ラスタベクトル地図投影Projection of raster and vector maps 47 (1)
GDAL/OGRツールで、再投影Reprojecting with GDAL/OGR tools 48 (5)
GRASSデータモデルデータの交換GRASS data models and data exchange53 (30)
ラスタデータRaster data54 (16)
GRASS2Dの、3DラスタデータモデルGRASS 2D and 3D raster data models 54 (2)
領域の統合と境界Managing regions and boundaries raster map resolution
ジオコードされたラスタデータインポートImport of georeferenced raster data58 (8)
スキャンされた歴史地図インポートとジオコーディングImport and geocoding of a scanned66 (3)
ラスタデータエクスポートRaster data export 69 (1)
ベクトルデータVector data70 (13)
GRASSベクトルデータモデルGRASS vector data model70 (3)
ベクトルデータインポートImport of vector data73 (5)
xy CAD描画のための座標変換Coordinate transformation for xy CAD drawings 78 (2)
ベクトルデータエクスポートExport of vector data80 (3)
ラスタデータを使うWorking with raster data 83 (86)
ラスタ地図を表示、管理Viewing and managing raster maps 83 (22)
ラスタデータの表示と、カラーテーブルの割り当てDisplaying raster data and assigning a color table 83 (3)
ラスタ地図に関するメタデータを管理Managing metadata of raster maps 86 (2)
ラスタ地図クエリプロファイルRaster map queries and profiles88 (2)
ラスタ地図統計Raster map statistics90 (1)
ラスタ地図ズームと、部分集合の生成Zooming and generating subsets from91 (1)
簡単なラスタ地図の生成Generating simple raster maps92 (2)
再分類と再スケーリングReclassification and rescaling of94 (3)
ラスタ地図raster maps
ラスタ地図タイプの記録と値の置換Recoding of raster map types and value replacements 97 (2)
カテゴリベルの割り当てAssigning category labels99 (4)
マスキングとノーデータ値の取り扱いMasking and handling of no-data values 103(2)
ラスタ地図の計算Raster map algebra 105(10)
整数と浮動小数点データInteger and floating point data107(1)
基本的な計算Basic calculations 108(1)
“if"状態を使うWorking with ``if'' conditions109(1)
r.mapcalcのNULL値の取り扱いHandling of NULL values in r.mapcalc 110(1)
r.mapcalcでMASKを作成Creating a MASK with r.mapcalc 111(1)
特別なグラフ演算子Special graph operators112(1)
相対的座標での近傍演算Neighborhood operations with relative coordinates113(2)
ラスタデータの変換と内挿Raster data transformation and interpolation 115(11)
離散的ラスタデータ自動ベクトルAutomated vectorization of discrete raster data115(3)
連続フィールドの等値線の描画を生成Generating isolines representing continuous fields 118(1)
ラスタデータのリサンプリングと内挿Resampling and interpolation of raster data 119(5)
ラスタ地図オーバーレイマージOverlaying and merging raster maps 124(2)
ラスタデータの空間分析Spatial analysis with raster data126(29)
近傍分析とクロスカテゴリー統計Neighborhood analysis and cross-category statistics126(7)
ラスタフィーチャのバッファリングBuffering of raster features 133(2)
コストサーフェイスCost surfaces135(5)
地勢と分水界分析Terrain and watershed analysis 140(13)
ランドスケープ構造解析Landscape structure analysis 153(2)
ランドスケーププロセスモデリングLandscape process modeling 155(11)
文学的、地下水モデルHydrologic and groundwater modeling155(3)
浸食と宣誓証言モデルErosion and deposition modeling158(8)
ラスタベースモデルと解析に関するまとめFinal note on raster-based modeling and analysis166(1)
ボクセルデータを使うWorking with voxel data166(3)
ベクトルデータを使うWorking with vector data 169(94)
地図の表示とメタデータ管理Map viewing and metadata management169(4)
ベクトル地図を表示Displaying vector maps 169(3)
ベクトル地図メタデータ維持Vector map metadata maintenance172(1)
ベクトル地図属性管理とSQLサポートVector map attribute management and SQL support173(14)
GRASS6でのSQLサポートSQL support in GRASS 6 174(7)
サンプルSQLクエリ属性変更Sample SQL queries and attribute modifications 181(4)
地図再分類Map reclassification 185(1)
複数の属性があるベクトル地図Vector map with multiple attribute tables: layers 186(1)
ベクトルデータデジタルDigitizing vector data 187(5)
位相データデジタル化の一般原理General principles for digitizing topological data187(2)
GRASSでの対話的なデジタイジンInteractive digitizing in GRASS189(3)
ベクトル地図クエリ統計Vector map queries and statistics192(4)
地図クエリMap queries192(2)
ベクトルオブジェクトに基づくラスタ地図統計Raster map statistics based on vector objects194(2)
ポイントベクトル地図統計Point vector map statistics196(1)
幾何学操作Geometry operations196(20)
位相的な操作Topological operations 197(6)
バッファリングBuffering203(1)
フィーチャの抽出と境界のディゾルブFeature extraction and boundary dissolving204(1)
ベクトル地図を修理Patching vector maps 205(1)
ベクトル地図インターセクディングとクリッピングIntersecting and clipping vector maps206(3)
ベクトル幾何の変換と3Dベクトルの作成Transforming vector geometry and creating 3D vectors 209(2)
点からのコンベックスハルとトライアンギュレーションConvex hull and triangulation from points 211(1)
同じ位置の掘り出し物の複数のポイントFind multiple points in same location212(2)
一般的な多角形境界の長さLength of common polygon boundaries214(2)
ベクトルネットワーク分析Vector network analysis216(11)
ネットワーク分析Network analysis 216(5)
直線的な参照システム(LRS)Linear reference system (LRS)221(6)
ラスタへのベクトルデータ変化Vector data transformations to raster227(3)
空間的な内挿と近似Spatial interpolation and approximation230(19)
内挿方法を選択Selecting an interpolation method230(5)
RSTによる内挿と近似Interpolation and approximation with RST 235(2)
RSTパラメタの調整: テンションスムージングTuning the RST parameters: tension and smoothing 237(4)
RSTの精度を評価Estimating RST accuracy241(3)
セグメント化処理Segmented processing 244(3)
RSTとのトポグラフィー分析Topographic analysis with RST247(2)
ライダーポイントクラウドデータを使うWorking with lidar point cloud data249(8)
ボリュームに基づくは内挿Volume based interpolation 257(6)
3番目の変数の追加: 高度のある降水量Adding third variable: precipitation with elevation 258(3)
ボリュームとボリューム-時間内挿Volume and volume-temporal interpolation 261(1)
地球統計学とスプライGeostatistics and splines262(1)

2008-07-18

vimperator最高

ほんとにもう最高。

楽したい人間+ハマり性な人間には、こーゆーカスタマイズがしがし出来るツールが最高なのよ。

オレ流ブラウザ環境整備できるのももうタマラン。

エディタならvimemacsでもいいけど、あんまり詳しくない。

他のツールはカスタマイズ性で見劣りする。

こだわりのない人間にはどんなツールでもオッケーなんだろうね。

オレはこだわるところはこだわる。

ちょっとした不便に気づかないか気づいても甘受してしまうような人間と、今はクリアできなくともなんとか今後の課題にしたいと考える人間。

そこの違いだね。

どっちが得かというのはわからんけどね。

優劣とか損得の問題じゃなく、ただオレはそういう人種だってこと。


追記

ブクマありがとう

vimperatorrcねえ。特筆すべき点はないけど、あえて一部抜粋すれば、こんな感じ。

inoremap <C-1> <Esc>1gt
inoremap <C-2> <Esc>2gt
inoremap <C-3> <Esc>3gt
inoremap <C-4> <Esc>4gt
inoremap <C-5> <Esc>5gt
inoremap <C-6> <Esc>6gt
inoremap <C-7> <Esc>7gt
inoremap <C-8> <Esc>8gt
inoremap <C-9> <Esc>9gt
noremap <BS> H
noremap <S-BS> L
noremap ,b <Esc>:bmarks -tags=
noremap u :o<Space> " ldrc+ldrでoで:open出来ない問題を解決
" wildoptions=auto時に一瞬補完が表示されてウザいmapがある - Dis Communication - 符号無し
" http://unsigned.g.hatena.ne.jp/Trapezoid/20080620/1213961754
javascript <<EOM
[
    [',a',':dialog addbookmark'],
    [',c',':viewSBMComments -t h'],
    [',C',':viewSBMComments -t hdl'],
    [',d',':pindownload'],
    [',ld',':set ldrc'],
    [',p',':mb clear-pin'],
    [',q',':toggleldrc'],
    [',R',':so ~/_vimperatorrc'], 
    [',r',':res'],
    [',v',':!vim ~/_vimperatorrc'], 
    ['\\s',':scrapbook'],
    ['\\S',':scrap'],
    ['\\f',':firebug'],
    ['\\d',':dialog downloads'],
    ['\\p',':tabopen chrome://browser/content/places/places.xul'],
    ['!',':set invum'],
    ['B',':ls!'],
    ['\\a',':addons'],
    ['\\e',':errorconsole'],
    ['\\F',':firebugwindow'],
    ['\\d',':dialog downloads'],
    ['\\g',':oepnGMpanel'],
    ['\\G',':toggleGM'],
    ['e',':note'],
    ['<F11>',':fullscreen'],
    ['\\P',':placesnewwin'],
    ['\\H',':historynewwin'],
    ['<C-j>',':togglebookmarksidebar'],
    ['<C-k>',':togglehistorysidebar'],
    ['<C-l>',':addtoldr'],
    ['<C-S-Right>',':removerighttabs'],
    ['<C-S-Tab>',':previousfirebugtab'],
    [',o',':openselectedlinks'],
    [',3',':copy titleAndURL'],
    [',ig',':imageGet'],
    [',io',':imageOpen'],
    ['w',':submit'],
    [',lo',':logout'],
    // nicontroller.js
    [',ni',':nicoinfo'],
    [',np',':nicopause'],
    [',nm',':nicomute'],
    [',nv',':nicommentvisible'],
    [',nz',':nicosize'],
    [',ns',':nicoseek'],
].forEach(function([key,command]){
    liberator.mappings.addUserMap([liberator.modes.NORMAL], [key], "User defined mapping",
        function () { liberator.execute(command); }, {rhs: key, noremap: true});
});
EOM

javascript <<EOM
[
    ['<C-j>',':togglebookmarksidebar'],
    ['<C-k>',':togglehistorysidebar'],
].forEach(function([key,command]){
    liberator.mappings.addUserMap([liberator.modes.INSERT], [key], "User defined mapping",
        function () { liberator.execute(command); }, {rhs: key, noremap: true});
});
EOM
javascript <<EOM
// nicontroller.js plugin
// [N]-
// N 秒前にシークする。
// 指定なしの場合 10 秒前。
liberator.mappings.addUserMap(
    [liberator.modes.NORMAL],
    ['-'],
    'seek by count backward',
    function(count) {
        if(count === -1) count = 10;
        liberator.execute(':nicoseek! ' + '-' + count);
    },
    { flags: liberator.Mappings.flags.COUNT }
);

// [N]+
// N 秒後にシークする。
// 指定なしの場合 10 秒後。
liberator.mappings.addUserMap(
    [liberator.modes.NORMAL],
    ['+'],
    'seek by count forward',
    function(count) {
        if(count === -1) count = 10;
        liberator.execute(':nicoseek! ' + count);
    },
    { flags: liberator.Mappings.flags.COUNT }
);
EOM

Vimperatorで;bでリンクを新しいバックグラウンドのタブに開くようにする。

http://anond.hatelabo.jp/20080709195527

も俺の仕業なんだけど、これvimperator本体に実装してくれないかな。

気になる点・これからの課題

窓の杜 - 【NEWSFirefox 3のスマートロケーションバーに対応した「XUL/Migemo

http://www.forest.impress.co.jp/article/2008/07/07/xulmigemo0105.html

余談

Index of /

http://vimperator.driftaway.org/

に上がるのはたいてい朝の07:30になっているので、いつからかチェックするのが朝の習慣になった。

2008-04-17

VistaHTML エディタを変更するまで

今回の Windows では関連付けが関連付けしか出来なくなるなどカスタマイズ周辺機能の劣化が甚大この上なく、レジストリを直接変更する他に手がないらしい。

ですので、 regedit で HKEY_CLASSES_ROOT\htmlfile\shell\Edit\command の既定値を編集。 "full path" "%1" で、full path部分にはエディタのフルパスを書くとよいですね。

また、 Ver7 にもなってソース表示エディタに notepad を採用しているブラウザ改善する為にも、インターネットオプションHTML エディタを変更します。

該当するレジストリキーが無いなどの理由(推測)でなぜか変更されない場合は HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\View Source Editor\Editor Name の既定値を "full path" にします。よかったですね。

2008-03-27

マウスの人はショートカットキーどうするの?

右利きで左マウスっていう人時々いるけど、ショートカットキーはどうしているんだろう。

左手でCtrl(MacならCommand)とA,Z,X,C,V,S,F辺りのコンビネーションを使うから、

マウスはとてもやってられない。

いちいち右クリックとかメニューバーからやるのは面倒。

まあ、右手で打てなくもないかもしれないけど、

それなら携帯電話左手で使えばいい。

ポテトチップスだって左手で食べれる。(PCの前で食べるのはおすすめできないが)

ログイン ユーザー登録
ようこそ ゲスト さん