Kinopyo Blog

プログラマとしてRuby, Rails, iPhone, iPad,Macなどなどと向き合う日々のログポース

Archive for 18:49

作業効率:Eclipseをフルスクリーンして効率をあげよう!

2010年11月30日

http://code.google.com/p/eclipse-fullscreen/からzipファイルダウンロードしてEclipseのフォルダに解凍する形でインストールできます。

ショットカットキーはCTRL + ALT + Zです。覚えておきましょう!

Eclipse fullscreen plugin

Photoshopで画像の座標を取得

2010年11月29日

仕事の事情であるPSDファイルにある画像の座標の情報が必要になって調べました。詳しく説明すると例えば背景が100×100のサイズで、その上に張り付いた違うレイヤーの画像の座標のことです。

ショットカットキーはCTRL+Tです。

メニューで「編集」->「自由変形」にすれば、レイヤーの4隅と中心座標の取得、数値入力による座標移動等ができます。

こんな感じです。メニューバーに表示してます。

coordinate

参考サイト:

http://questionbox.jp.msn.com/qa5718320.html

Chrome Extension: Flickr Upload右クリックで画像をアップロード

Webページの画像を右クリックで簡単にFlickrにアップロードできるChromeエクステンションです。

もしタイトルやタグなども編集できればもっどいいですけどね。

Flickr Upload Extensionをダウンロード

Chrome extension:Flickr Upload

Chrome extension: Flickr Upload

SpringでH2 Databaseを使う(HSQL、Derby)

Springのコンテキストファイルにjdbc:embedded-databaseタグで

type=”H2″でbeanを登録します。

jdbc:scriptタグで初期化時に実行したいSQLファイルを指定できます。

Sprintって、本当に便利ですね。

<jdbc:embedded-database id="dataSource" type="H2">
	<jdbc:script location="classpath:schema.sql"/>
	<jdbc:script location="classpath:test-data.sql"/>
</jdbc:embedded-database>

ちなみにjdbcのnamespaceの登録も忘れずに。

xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc

http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">

H2以外でもHSQL、Derbyがサポートされています。

Macのターミナルを活用

ターミナルの起動

ターミナルはApplication/Utilitiesフォルダにあります。

CTRL+Spaceで直接Terminalを叩いても直接開けますので、

とても便利でずっとこれを使ってます。

基本コマンド

ls
(Windowsのdirコマンドと同じ役割)list files and directories
cd
change directory
mkdir
create a new directory
cp
copy files or directories
mv
move (rename) files or directories
rm
remove files or directories

便利なコマンド

  • pwd

今のディレクトリのパスを返します。”/Users/(yourusername)”のような

  • open

Finderでダブルクリックと同じ効果です。アプリを開くに使います。

  • ~

波記号はHomeディレクトリのショートカットです。

例えばcd ~で叩くとデフォルトで”/Users/(yourusername)”ディレクトリに行きます。

ジョブコントロール

  • ps -ax

これはActivity Monitorのコマンドバージョンと理解していいでしょう。

現在アクティブなアプリのリストを表示します。

よくgrepコマンドと組み合わせて使います。

ps -ax | grep http
ps -ax | grep mysql
  • kill

ps -axの一番目の列はプロセスのIDの列です。

あるプロセスを強制的に終了させたい場合はID指定で”kill”できます。

kill xxx

上記の”xxx”はプロセスのIDです。

またアプリの名前がわかった場合はkillallコマンドが使えます。

killall Dock

大文字小文字は区別しますので、気おつけてください。

JavaScript: カンマ区切りで数値をフォーマットする


/**
 * 数値を日本円表現にフォーマット。
 * 例:12345 -> 123,45
 *
 */
num2Currency = function(obj){

	// 画面項目の値
	var str=obj.value;
	var num = new String(str).replace(/,/g/"");
	while(num != (num =num.replace(/^(-?\d+)(\d{3})/,"$1,$2")));
	obj.value = num;

}

/**
 * 日本円表現を数値にフォーマット。
 * 例:123,45 -> 12345
 *
 */
currency2Num = function(obj){

	var str=obj.value;
	var num = str.replace(/,/g,"");
	obj.value = num;
}

[更新]MacでRuby on Rails開発:環境構築から

MacにはデフォルトでRubyが入ってそうです。

ターミナルを開いてrails -vを叩いたらバージョン情報が出てきました。

ruby 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0]

そしてRubyだけじゃなくRailsも入ってましてびっくりしました。

すごいですねMacは。。。

て、railsのバージョンもrails -vで確認できますが、

デフォルトのバージョンは古いそうで下記のコマンドでアップグレードできます。

sudo gem update rails

するとこんなログ情報が出ます。

Updating installed gems
Updating rails
WARNING:  Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
	  /usr/bin aren't both writable.
WARNING:  You don't have /Users/zolo/.gem/ruby/1.8/bin in your PATH,
	  gem executables will not run.
Successfully installed activesupport-2.3.8
Successfully installed activerecord-2.3.8
Successfully installed rack-1.1.0
Successfully installed actionpack-2.3.8
Successfully installed actionmailer-2.3.8
Successfully installed activeresource-2.3.8
Successfully installed rails-2.3.8
Gems updated: activesupport, activerecord, rack, actionpack, actionmailer, activeresource, rails
Installing ri documentation for activesupport-2.3.8...
Installing ri documentation for activerecord-2.3.8...
Installing ri documentation for rack-1.1.0...
Installing ri documentation for actionpack-2.3.8...
Installing ri documentation for actionmailer-2.3.8...
Installing ri documentation for activeresource-2.3.8...
Installing ri documentation for rails-2.3.8...
Installing RDoc documentation for activesupport-2.3.8...
Installing RDoc documentation for activerecord-2.3.8...
Installing RDoc documentation for rack-1.1.0...
Installing RDoc documentation for actionpack-2.3.8...
Installing RDoc documentation for actionmailer-2.3.8...
Installing RDoc documentation for activeresource-2.3.8...
Installing RDoc documentation for rails-2.3.8...

多少時間がかかります。

これでMacでのRuby開発の準備は完了です。

更新

gem update railsにsudoを付けないとこんなエラーが出るかも


WARNING:  Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
	  /usr/bin aren't both writable.
WARNING:  You don't have /Users/paku-k/.gem/ruby/1.8/bin in your PATH,
	  gem executables will not run.
ERROR:  Error installing rails:
	bundler requires RubyGems version >= 1.3.6

ターミナルコマンド:sudo

環境構築の記事でよく目にすると思いますが

このsudoコマンド。

気になってて調べてみたんです。

sudo is a Terminal command used to execute a command as another user, by default, the root user.

あるコマンドを別のユーザとして実行する、デフォルトではルートユーザ、だそうです。

例えばルートユーザとしてあるアプリを実行したい時は:

sudo open ....

Windowsにmemcacheをインストール、PHPの設定

2010年11月26日

My環境

XAMPP1.7.3 + WinXP

ダウンロードはこちら

memcache側の設定

memcacheのインストール手順
  1. http://code.jellycan.com/memcached/よりmemcached 1.2.6 => win32 binaryバージョンのファイルをダウンロード
  2. zipファイルを適当な場所(例えばc:\memcached)に解凍
  3. コマンドプロンプトから下記コマンドを叩く、Windowsサービスとしてインストール。これで今度Windowsが起動すると自動でmemcacheサーバが起動してくれる。

c:\memcached.exe -d install
memcacheの起動(初回のみ)

コマンドプロンプト


c:\memcached\memcached.exe -d start

php側

php.iniの設定

XAMPPのパス/php/php.iniを編集:下記コードを追加


extension = php_memcache.dll

ここはLinux環境と違い拡張子が.soではなく.dll。

php_memcache.dllのダウンロード

http://downloads.php.net/pierre/から’memcache’を検索して正しいバージョンのファイルをダウンロード。

そしてxampp/php/extに入れる。


ここで問題!正しいバージョンはなんなのか?間違ってダウンロードすると後でApacheサーバを立ち上がるときエラーが出るよ。私の環境だとphp_memcache-cvs-20090703-5.3-VC6-x86.zipのファイルが正しいけど、今時点で上記URLには載せていない。結構ググって見ても結局古い結果で、しょうがなく友人からそのファイル貰った。。。ここにアップしたので、必要な方はダウンロードしてください。ウイルススキャンしてね。。

php_memcache-cvs-20090703-5.3-VC6-x86

動作確認

xamppでapacheサーバを起動、下記内容をphpファイルと保存してサーバのDocumentパス(デフォルトではXAMPP/htdocs)に置く。


connect("localhost",11211); // try 127.0.0.1 instead of localhost

                                           // if it is not working 

    echo "Server's version: " . $memcache->getVersion() . "\n";

    // we will create an array which will be stored in cache serialized

    $testArray = array('horse', 'cow', 'pig');

    $tmp       = serialize($testArray);

    $memcache->add("key", $tmp, 30);

    echo "Data from the cache:\n";

    print_r(unserialize($memcache->get("key")));

?>

おまけ:memcacheメモリの調整

Memcached, by default, loads with 64mb of memory for it’s use which is low for most applications. To change this to something else, navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached Server in your registry, find the ImagePath entry and change it to look something like this:

“C:\memcached\memcached.exe” -d runservice -m 512

参考

http://www.codeforest.net/how-to-install-memcached-on-windows-machine

http://pureform.wordpress.com/2008/01/10/installing-memcache-on-windows-for-php/

今週(10/25~10/31)新たに知ったもの

2010年11月01日

Compass

A Sass-based CSS Meta-Framework that allows you to mix and match any of the following CSS frameworks:

Compass Core

Blueprint

960

Susy

YUI

New frameworks and extensions are tracked on the wiki as they are created.

Other frameworks can be added relatively easily. Create your own!

http://github.com/chriseppstein/compass/tree#readme

http://compass-style.org/docs/

Rails Rumble

The Rails Rumble is an annual 48 hour web application development competition in which teams of skilled web application developers get one weekend to design, develop, and deploy the best web property that they can, using the power of Ruby and Rails.

http://railsrumble.com/

Monospaced font

A monospaced font, also called a fixed-pitch or non-proportional font, is a font whose letters and characters each occupy the same amount of horizontal space.[1] This contrasts to variable-width fonts, where the letters differ in size to one another.

The first monospaced typefaces were designed for typewriters, which could only move the same distance forward with each letter typed. This also meant that monospaced fonts need not be typeset like variable width fonts and were, arguably, easier to deal with.

http://en.wikipedia.org/wiki/Monospaced_font