More Related Content Similar to ホームディレクトリに埋もれた便利なコードをさがせ! Similar to ホームディレクトリに埋もれた便利なコードをさがせ! (20) More from Yohei Fushii (6) ホームディレクトリに埋もれた便利なコードをさがせ!9. 最近のYAPCでの活動
❖ 2010年 LT
• ページャ実装マニアックス
‣ 108のページャ実装を紹介
❖ 2011年 LT
• Enhance Anime Watching
with Programming
‣ アニメ試聴支援ツールを紹介
9
16. > ls ~/bin
ab.rb* gita* pod2pdf*
check_config.sh* gitolite@ repo*
cpan-chm.pl* hakobe-pmsetup* reposh.rb*
cpan-tags.sh* hatena-tags* ri*
cpan-update.sh* icssh.scpt screen*
cron_minicpan.sh* icssh.sh* subl@
efm_perl.pl* irb* testrb*
fork.sh* lingr-ircd.pl* time_bell.rb*
forwarding.sh* list_config.pl todo_progress.rb*
gistp@ memo* touch_pm*
git-branch-recent* memo.rb* tov*
git-grep-submodule* myd.sh* ts*
git-hatena@ notify.rb* twitter2ircd.pl*
git-hatenana* pb_client.pl* update-chrome.sh*
git-rebase-recover* pb_server.pl* vimwhich*
git-review* pcd* yappo-pmsetup*
git_lazy_add.sh* pmsetup*
雑多なコードの巣窟
17. 1 use strict;
2 use warnings;
3
4 use Text::Xslate;
5
6 my $xslate = Text::Xslate->new(
7 module => ['Text::Xslate::Bridge::TT2'],
8 syntax => 'TTerse',
9 );
10
11 my $params = {
12 values => [qw(1 2 3 4 5 6 7)],
13 };
14
15 print $xslate->render_string(<<"TMPL_END", $params);
16
17 [% FOREACH val IN values %]
18 [% val %]
19 [% END # FOREACH val IN values %]
20
21 TMPL_END
18. 1 use strict;
2 use warnings;
3
4 my $words = [" ", """, """];
5
6 print "1" if scalar grep { /[^"s]/ } @$words == 0;
7 print "2" if scalar( grep { /[^"s]/ } @$words) == 0;
8
9 __END__
10 2 しか表示されない
19. 1 #!/bin/sh
2 CPUS=
`cat /proc/cpuinfo | grep -E '^processor' | wc -l`
3 SERVERS=
`grep StartServers /etc/httpd/conf/httpd.conf | cut -d' ' -
4 CLIENTS=
`grep Clients /etc/httpd/conf/httpd.conf | cut -d' ' -f2`
5 RAM=`free -m | grep '^Mem' | awk '{printf $2}'`
6
7 echo $CPUS $SERVERS $CLIENTS $RAM
38. Guita
❖ gist clone
• コードスニペットの共有ツール
• みんな大好き安心のPerl製
• gitリポジトリとして利用可能
• fork
• syntax highlighting
38
44. プログラムからのGit
❖ libgit2
• http://libgit2.github.com/
• Cで書かれたGit操作ライブラリ
• available as bindings for all
major scripting languages
Ruby/Objective-C/Python/.Net/PHP/
Lua/Delphi/node.js/go/Erlang/parrot
44
45. PerlからのGit
❖ Git.pm
• gitに付属してる
• CPANモジュールじゃない
❖ Git::Class/Git::Wrapper
• interactiveなコマンドが使えない
❖ Git::Repository
• APIがシンプルで割り切ってる
see: http://search.cpan.org/ book/Git-Repository-1.25/lib/Git/
Repository.pm#OTHER_PERL_GIT_WRAPPERS
45
46. Git::Repository
1 use Git::Repository;
2
3 # リポジトリの指定
4 my $git;
5 $git = Git::Repository->new(
6 git_dif => '/path/to/.git' );
7 $git = Git::Repository->new(
8 work_tree => '/path/to/working_copy' );
9
18
46
47. Git::Repository
10 # コマンドの実行
11 my $status = $git->run('status');
12 my @diff = $git->run('diff', 'HEAD^...HEAD');
13
14 # コマンドの実行時に入出力を制御
15 my $cmd = $git->command('add', '-p', '-u');
16 $cmd->stdout;
17 $cmd->stdin;
18
47
61. ホームディレクトリに
埋もれた
便利なコードをさがせ!
Guita
https://github.com/hakobe/Guita
63. 社内にgistが欲しかったので作りはじめてどうや
ら動くようにはなったところで、社内に
GitHubEnterprise導入の流れ。そういえば、君、
git関係のこといろいろやっていたよねという話に
なりまして、あれよあれよという間に導入係に...
64. ホームディレクトリに
埋もれた
便利なコードをさがせ!
Guita
https://github.com/hakobe/Guita