さくら VPS で VNC が起動しない場合
久しぶりに VPS の OS をインストールしようとしたら、VNC が起動しなかった。
原因を調べてみたところ、どれも Java のバージョンが 6 から 7 に上がったことが原因だという古い記事ばかりだった。
最終的には、Java 7 でも VNC が起動したのだが、念のため備忘録として残しておく。
Windows ならばコントロールパネル、Mac OS X ならば System Preference から「Java コントロールパネル」を開く。
「Java コントロールパネル」を開いたら、「セキュリティ」タブを選択し、「サイト・リストの編集」を開き「https://secure.sakura.ad.jp/」を登録すれば、VNC が起動するようになる。
Parallel::ForkManager のサンプル
#!/usr/bin/env perl use strict; use warnings; use Getopt::Long; use Parallel::ForkManager; GetOptions( 'h|help' => \my $help, 'p|process=i' => \my $process, 'verbose' => \my $verbose, ) or pod2usage(); pod2usage() if $help; my $pm = Parallel::ForkManager->new($process || 1); my $result = {}; # 子プロセスが終了する際に呼ばれるサブルーチンを定義する # これは親プロセスから呼ばる $pm->run_on_finish( sub { my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $data) = @_; if (defined $data) { $result->{$pid} = $$data; } } ); for my $id (0..10) { my $pid = $pm->start and next; # write codes to do something; $pm->finish(0, \"finished $id"); } $pm->wait_all_children; use Data::Dumper; warn Dumper($result);
Coro で WWW::Mechanize を使ってみる
#!/usr/bin/env perl use strict; use warnings; use Coro; use Coro::LWP; use Data::Dumper; use WWW::Mechanize; my @coros = (); my @urls = qw|https://twitter.com/ https://www.pinterest.com/ http://www.apple.com/|; foreach my $url (@urls) { push @coros, async { my $mech = WWW::Mechanize->new; printf("Loaded: %s\n", $url); my $res = $mech->get($url); printf("Got %s title is %s\n", $url, $mech->title); }; } $_->join for @coros;
実行時の出力例。出力順は実行の度に異なる。
Loaded: https://twitter.com/ Loaded: https://www.pinterest.com/ Loaded: http://www.apple.com/ Got http://www.apple.com/ title is Apple Got https://twitter.com/ title is Twitter Got https://www.pinterest.com/ title is Pinterest
実際に利用する場合は、エラー処理をどう実装するか考えておく必要がある。
Perl で Redis を操作する簡単なサンプル
#!/usr/bin/env perl use strict; use warnings; use Redis; my $redis_host = '127.0.0.1'; my $redis_port = 6379; my $redis = Redis->new(server => sprintf('%s:%d', $redis_host, $redis_port)); # Use UNIX domain socket # my $redis = Redis->new(sock => '/path/to/socket'); $redis->set(tokyo => 13); $redis->set(kanagawa => 14); if ($redis->exists('saitama')) { # something to do } else { warn 'Not found the key.'; } print $redis->get('tokyo'); #=> 13
Windows 版 Redis を入手する
Windwos 版 Redis は Redis 公式サイトでは配布されていない。
Microsoft Open Tech group が Windows 版のバイナリを開発しているとのこと。運用に適しているとは言い難いけれども、開発するために稼働させるには必要十分とのこと。
The Redis project does not directly support Windows, however the Microsoft Open Tech group develops and maintains an experimental Windows port targeting Win32/64. Currently the port is not production quality but can be used for development purposes on Windows environments. We look forward for collaborating with the authors of this efforts but currently we will not merge the Windows port to the main code base.
http://redis.io/download
MSOpenTech / redis から redis > bin > release と辿り、[View Raw]のリンクをクリックして、ZIP圧縮されたバイナリを取得する。
Windows で Memcached を使う
Memcache の公式サイトには Windows 版のバイナリがないため、ユーザーが作成したバイナリファイルを利用するのが手っ取り早い。
しかし、検索をしてみると情報が古いものばかりで、memcachedd 1.2.6 の情報ばかりだった。現在の最新版は 1.4.14 で探してみると、下記のサイトで最新版が配布されているのを見つけた。
- memcached on Windows
- 32bit版: http://s3.amazonaws.com/downloads.northscale.com/memcached-win32-1.4.4-14.zip
- 64bit版: http://s3.amazonaws.com/downloads.northscale.com/memcached-win64-1.4.4-14.zip
上記のバージョンよりも古くなるが、1.4.x 版を下記のサイトで見つけた。
上記のサイトで配布されているバージョンは、1.4.5 が最新版になるが、次のサイトで(古い)やりかたで memcached をサービスとして登録できないと書かれていた。
rem PC起動時に立ち上がるようにする memcached.exe -d install rem memcachedデーモンを起ち上げておく memcached.exe -d start
サービスとして登録できない件については、
Recently, I was working on memcached with windows machine. Memcached is built for linux platform. It's latest stable version is 1.4.15. But we haven't found the compatible windows binary file for the latest version. I have found binary for memcache 1.4.5, but it was providing errors while installing with the command:
http://newdailyblog.blogspot.jp/2013/05/installing-memcached-144-on-windows.html
memcache.exe -d install
It hung up on the window. I googled and found that '-d' option is no longer supported.
と書かれているように、コマンドのオプションが廃止されたようだ。
Compass のアンチョコ
# 変更を監視して、保存する度にコンパイルする % compass watch sass/screen.scss >>> Compass is polling for changes. Press Ctrl-C to Stop. # 一行に圧縮 % compass watch --output-style compressed sass/screen.scss