最近はScrapboxを主に使っています。 Scrapboxで作成日付をタグに入れて新規ページ作成する方法 - organize-ideas - Scrapbox Scrapboxで文章オンリーのページを作った際に余白を有効活用する - organize-ideas - Scrapbox 前々からそろそろはてなダイアリーはobsoleteなのでどこへ移行しようかなと考えていたのですが、はてなブログ、Qiita、Mediumなどと比べて、Scrapboxは割とグッと来ています。
今日質問されて、以前Twitterで書いたのを思い出して、そして検索性が悪くて見つけ出すのに苦労した。こちらに転載しておく。詳細は気が向いたときに埋める。 オプション引数の評価タイミング Rubyではオプション引数は関数が呼ばれるたびに評価される。 def foo() print "foo!" end def bar(x=foo()) end bar #=> foo! と出力される bar #=> foo! bar #=> foo! Pythonでは関数の定義時に1回だけ評価される。 def foo(): print "foo!" def bar(x=foo()): pass #=> foo!と出力される bar() #=> 何も出力されない bar() 「引数が省略されたら今の日時」みたいな毎回評価したい場合はデフォルト値をNoneにしておいて「Noneだったら=省略されていたら」のif
セキュリティ・ミニキャンプ in 横浜に講師として参加しています。坂井さんのバイナリカルタ、バイナリカレンダーが面白かったので、自分でも変換スクリプトを作ってみました。 バイナリカルタ: http://kozos.jp/binary-karuta/ バイナリカレンダー: http://kozos.jp/binary-calendar/ 僕の書いたスクリプト: https://github.com/nishio/binary_color このスクリプト自身をこのスクリプトで変換したものがこれ。 おおよそ赤(可読領域)で構成されていて、ところどころに改行の緑(制御コード領域)がある。ちなみに暗い赤が多い領域は0〜255をRGBの色に変換しているコードで、数値や記号が他のコードより多いわけですね。 このスクリプトをコンパイルしたPythonのバイトコードがこちら。 左下がりの斜めがよく出現してい
Rubyの文字列はエンコード情報を持っているという話。 struct RString { struct RBasic basic; union { struct { long len; char *ptr; union { long capa; VALUE shared; } aux; } heap; char ary[RSTRING_EMBED_LEN_MAX + 1]; } as; }; あれ?持ってないぞ? と思ったら int rb_enc_get_index(VALUE obj) { ... case T_STRING: case T_REGEXP: i = ENCODING_GET_INLINED(obj); if (i == ENCODING_INLINE_MAX) { VALUE iv; iv = rb_ivar_get(obj, rb_id_encoding()); i =
先日、こんな問題を見かけたのだけども、JavaのGCにはあまり詳しくないので答えがわからなかった。 OutOfMemoryErrorが発生しました。(中略)ヒープメモリは足りているようです。原因として何が考えられますか? http://d.hatena.ne.jp/iad_otomamay/20130318/1363596244 なんでだろうなぁと思っていたところid:moriyoshiが「Permanent領域があふれたんじゃないの」と一言。「Permanent領域」で検索してみると、なるほど、そういうことなのかー。 というわけで早速それを再現させるコードを書いてみた。ヒープの大部分ががら空きなのにPermanent領域だけ99%になっているのがわかるかと思う。 Exception in thread "main" [Full GC [Tenured: 515K->515K(56896K
Haskellって、変数に束縛されている値が「評価されている」と「されていない」の状態を持っていて、それがグローバルにあちこちから共有されているから「どれくらいの計算量で終わるか」みたいな議論になるとイメージが掴めなくて困っていた。確認する方法があればいいのになぁ、でも、ないんだろうなぁと、諦めていたが、GHCiである程度できることがわかった。面白いじゃんこれ。 まずこんなソースコードを用意してみる。これは「リストを結合した時点で前半のリストは評価されるのか否か」を実験するためのコード。以前議論になったときに、僕の主張としては「前半を評価しないでも『xsの先頭1個と「xsの残りとysを結合したもの」のcons』を返せば良い。きっとその実装になってるだろう」というものだったのだけど、今までは挙動を観察する方法を知らなかったので議論止まりだった。 xs = [1, 2, 3] ys = [4,
Running Lean ―実践リーンスタートアップ刊行記念の著者アッシュ・マウリャ氏 来日特別セミナーに行ってきた。 Running Lean ―実践リーンスタートアップは、日本語版が出ることは知らなくて、著者のブログを読んでレバレッジメモを書いたりしていた: リーンキャンバス:レバレッジメモ 参加して結構学べることがあった。僕は社内で使っているグループウェア(kintone)をハックして、リーンキャンバスを手軽に描いたり他の人と共有したりできるようにしてる。でもって、いくつか描いたり人に見せたりもしていたのだけども、描いた後どうするのかがよくわからなかった。 (kintone上に作ったリーンキャンバス) リーンキャンパスを描いた後は「このなかで一番リスク(不確実性)の高いのはどれか」を考え、そのリスクを減らすためのサイクルを回す。「解決に値する課題はあるのか」や「誰かに必要とされるもの
先日こんな実験をして、大量のオブジェクトを作った時にはそのオブジェクトが持っている__dict__の1048バイトが無視できなくなってくることを確認した: Pythonでメモリ消費量のプロファイルを取る 今日はその解決編。先日のコードに1行書き足してみよう。__slots__で始まる行がそれだ。 from guppy import hpy h = hpy() N = 100000 class Hoge(object): __slots__ = ['x', 'y', 'z', 'a', 'b', 'c'] def __init__(self): self.x = 1 self.y = 1 self.z = 1 self.a = 1 self.b = 1 self.c = 1 x = [Hoge() for x in range(N)] print h.heap() これによって、変更前ではH
昨日Pythonでメモリを食い過ぎた時に見直すポイントを書いたが、使ったツールの説明を忘れていた。 Guppy-PE: A Python Programming Environmentを使うとこんな感じの出力が得られる。 Partition of a set of 2330379 objects. Total size = 355901024 bytes. Index Count % Size % Cumulative % Kind (class / dict of class) 0 447287 19 125240360 35 125240360 35 dict of __main__.Node 1 53016 2 85891008 24 211131368 59 dict (no owner) 2 467204 20 66360776 19 277492144 78 str 3 457
前回「Rackhubを試してみた日記」でPython製の自前サーバを起動した際に、Rackhubは8000番のポートとかを塞いであるので自前サーバを80番で動くようにするために色々苦労してたら「それnginxでリバースプロキシすればいいよ」と教えてもらった。 「Rackhub: あなたのための、クラウド上のlocalhost」ということで、普段自分がlocalhostをどう使っているかなーと考えると、80番ポートってあんまり使わない。コマンドラインでpython -mSimpleHTTPServerって叩いて8000番でディレクトリの中身を一時的に晒したり、Flaskの開発サーバでプロトタイプを作って5000番で社内公開したり。だからそういうのが簡単にできるようにしたい。 まずはnginxを起動する。よくわかってないのだけども、sudo nginxで起動した。 ブラウザでアクセスしてみる。
作りたいもの: プログラミング言語のコア概念を学ぶサイト、その2の続編。 ブラウザの上で対話的にLISPのコードを実行できるサイトを作りました。 http://nhiro.org/learn_language/LISP-on-browser.html 現状ではまだ説明が足りないから、LISPをまだまったく知らない人がこのサイトを見て理解できるようになるかというと、そうではない。 TODO サンプルコードを1歩ずつ学べる粒度で用意する ツリーのリアルタイム可視化のコードとくっつける see 構文木を可視化するサイトを作った コードリーディングのための解説を書く 関連記事 ブラウザ上で演算子の優先順位と結合性を学ぶ
ユースケース1 作業をお願いしていた人からファイルがメールで送られてくる。自分のほうで進めてた作業を一旦脇にどけておいて、二人が共通の底本にしているファイルをもらったファイルで上書き、自分の作業をマージしよう、としたらおい文字コード変えてんじゃねえよ! $ git add foo $ git commit -m "working" $ git tag mine $ git reset HEAD^ (ファイル上書き) $ git merge mine →改行コードが変わっていて盛大にコンフリクト.git/MERGE_HEADを削除して、fooをgit checkout HEAD^ fooしたが、もうちょっとスマートな方法があるのかな? ユースケース2 マージしてみたら相手方の修正が数行に1行書き換えてるものだったことが原因なのかなんなのかオートマージに失敗して大量のコンフリクトメッセージが突
ちょっと2倍のサイズに拡大したいファイルが5つくらいあったんだけど、簡単。 f$ ls *.png iPad_FREE_config.png iPad_about.png iPad_config.png iPhone_FREE_config.png iPhone_about.png iPhone_config.png f$ mkdir out f$ for i in *.png; do; echo $i; done iPad_FREE_config.png iPad_about.png iPad_config.png iPhone_FREE_config.png iPhone_about.png iPhone_config.png f$ for i in *.png; do; convert -resize 200% $i out/$i; done
増井さんの作りたいものリストを作ろうというスライドを見て「確かに『いつかやる』リストに入れてるだけじゃ発展しないから、公開しても問題ないものは公開したらいいなぁ」と思ったので早速やってみました。3つ目。 JavaScriptのコードの質を保つためのガードレール JavaScriptは柔らかい言語で、typoとか変数名の変え忘れが実行時までエラーにならない。しかもしれっとundefinedとかになって、そのままHTMLやSVGのpath文字列に埋め込まれてたりしてデバッグにコストが掛かってしまう。人間は間違える生き物だから、間違いをなくすことはできない。だから間違えた時になるべく早く気づけるようにする仕組みが必要だ。 Google Closure CompilerはJavaScriptのソースコードを静的に検証してエラーを報告してくれる。であれば自分がソースコードを編集している時にバックグラ
増井さんの作りたいものリストを作ろうというスライドを見て「確かに『いつかやる』リストに入れてるだけじゃ発展しないから、公開しても問題ないものは公開したらいいなぁ」と思ったので早速やってみました。2つ目。 1歩ずつミッションをクリアすることでGitの使い方を覚えられるゲーム なんちゃらVille系のゲームはどうして人の心をとらえるのか? 「小さい粒度のミッションが提示されて、それを達成すると次のミッションが表示される仕組み」は、頻繁に「達成感」という報酬を与えることで人の心をとらえるのだろうか? そういえば僕が昔書いた、対話的インタプリタで1歩ずつ操作しながらPythonを覚えるコンテンツも評判が良かったなぁ。だったらgitの使い方も、1歩ずつ対話的にミッションをクリアしながら学べるようにしたら面白いんじゃないか? 学習ユーザのユースケース 実は既にgithubにおいてあったりする。一応遊べ
言語女子会: undefとnullは両方必要?の続編です。 varは必要なの? とあるプログラミング言語が集う女子会にて: Python: JavaScriptちゃんってさ、なんでvarだらけなの? JavaScript: えっ、変? Python: varなんかいらなくない?私ぜんぜん持ってないよ? JavaScript: えー、じゃあ変数をどうやって宣言するの? Python: 宣言っていうか…「x = 1」みたいな代入文があれば変数xが必要なのって自明じゃない?宣言とか必要? Ruby: 必要ないよね。っていうか変数宣言とか古臭くない? JavaScript: そうかなー。 Python: 少しダサイかも。ほら断舎離ブームだし要らないものは捨てなきゃ! JavaScript: 要らないかなぁ、変数宣言。Pythonちゃんは関数がネストしているときに外側のスコープの変数に代入するのって
昨年行われたセキュリティ&プログラミングキャンプ2011で中学生〜大学生を対象として行った講義「テストとデバッグ」の発表資料を公開します。 テストとデバッグ View more presentations from nishio
バージョン管理とかgitとかが「おおげさでめんどくさいもの」だと思う人は多い。でも、それは生産性向上のチャンスを逃していると思う。特に業務として多人数で開発している人たちの「変更前にはまずトピックブランチ」というやり方が、それはそれでよい方法なんだけど、いかにもめんどくさそうで尻込みさせてしまうのではないか。 先日の日曜日に、テキトーなgitの使い方をして、とても役に立ったのでユースケースとして報告しておこう。ただし、若干特殊な環境なのでここでやった方法が直接そのまま皆さんの所で使えるとは限らないが。 まず環境の説明。プロジェクトは「次の日曜日、新感覚シューティングゲームを展示します」で紹介している、テーブル型ディスプレイで動くシューティングゲーム。メインは @tokoroten で、ソースコードをバリバリ変更している。土曜日にとりあえず動くところまでは行った。改善点は山積みだ。使える時間
[[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(aMethod:) userInfo:aInfo repeats:NO] fire] ってやった時に呼ばれるaMethodの引数はNSTimerのインスタンスだが [NSThread detachNewThreadSelector:@selector(aMethod:) toTarget:self withObject:aInfo]; ってやった時のaMethodの引数はaInfo自体。 なのでNSTimerの時には例えばaInfoがNSDictionaryなら NSDictionary* info = [timer userInfo]; とかやる。 あとNSTimerはあくまでメインスレッドの中で「あとでイベントを発生させる」ってスケジ
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く