2010年11月29日 #design #photoshop #ui

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

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

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

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

coordinate

参考サイト:
http://questionbox.jp.msn.com/qa5718320.html

2010年11月29日 #javascript #snippet
// 数値を日本円表現にフォーマット。
// 例:12345 -> 12,345
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;
}
2010年11月29日 #環境構築 #linux

環境構築の記事でよく目にすると思いますが
このsudoコマンド。
気になってて調べてみたんです。

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

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

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

sudo open ....
2010年11月29日 #mac #linux

ターミナルの起動

ターミナルはApplication/Utilitiesフォルダにあります。
CTRL+Spaceで直接Terminalを叩いても直接開けますので、
とても便利でずっとこれを使ってます。

基本コマンド

  • :ls
    • (Windowsのdirコマンドと同じ役割)list files and directories
  • :cd
    • change directory
  • :mk
    • ir: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

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

2010年11月29日 #java #database #h2db #spring

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がサポートされています。

2010年11月29日 #mac #ruby #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
2010年11月26日 #apache #php #php #memcache

My環境

XAMPP1.7.3 + WinXP
ダウンロードはこちら

memcache側の設定

memcacheのインストール手順

  • http://code.jellycan.com/memcached/よりmemcached 1.2.6 => win32 binaryバージョンのファイルをダウンロード +zipファイルを適当な場所(例えばc:\memcached)に解凍 +コマンドプロンプトから下記コマンドを叩く、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には載せていない。結構ググって見ても結局古い結果で、しょうがなく友人からそのファイル貰った。。。ここにアップしたので、必要な方はダウンロードしてください。ウイルススキャンしてね。。
. $memcache->getVersion() . "<br />\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:<br />\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/

2010年11月 1日 #rails #new #font #uncategorized

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

2010年10月25日 #diary #ruby #linux #new

終電検索

いつもYahooで終電を検索するんですが、それがアテにならないことが分かりました。
終電検索で深夜1時とか出発でただ乗換が多かったのを見てとりあえず帰れるって安心したんですが、あとで見ると実は二日目の朝4~5時の電車となってしまいました。時間を全部チェックしてなかったのが自分のミスでしたが、、、検索アルゴリズムを改善する必要があると思います。

ブレスト

ブレインストーミングのこと。

ブレインストーミング(Brainstorming)とはアレックス・F・オズボーンによって考案された会議方式のひとつ。集団思考とも訳される。集団発想法、ブレインストーミング法(BS法)、ブレスト、課題抽出ともいう。1941年に良いアイデアを生み出す状態の解析が行われた後、1953年に発行した著書「Applied Imagination」の中で会議方式の名称として使用された。

rsync

rsync is a file transfer program for Unix systems. rsync uses the "rsync algorithm" which provides a very fast method for bringing remote files into sync. It does this by sending just the differences in the files across the link, without requiring that both sets of files are present at one of the ends of the link beforehand.

Some features of rsync include

  • can update whole directory trees and filesystems
  • optionally preserves symbolic links, hard links, file ownership, permissions, devices and times
  • requires no special privileges to install
  • internal pipelining reduces latency for multiple files
  • can use rsh, ssh or direct sockets as the transport
  • supports anonymous rsync which is ideal for mirroring

http://www.samba.org/rsync/

cron

Cron is a time-based job scheduler in Unix-like computer operating systems. The name cron comes from the word "chronos", Greek for "time". Cron enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates. It is commonly used to automate system maintenance or administration, though its general-purpose nature means that it can be used for other purposes, such as connecting to the Internet and downloading email.

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

redcar

結構使えそう。

  • Cross platform: OS X, Linux, Windows.
  • Syntax highlighting for many languages
  • Snippets for many languages
  • TextMate Theme support
  • Split panes
  • Block typing
  • Soft tabs
  • Optional line numbers
  • Bracket and quote matching
  • Automatic indentation for many languages
  • Directory tree pane (not yet a full project view)
  • Extend with Ruby
  • My Plugin – example plugin to start playing with editing for yourself
  • Bulk Rename files and directories
  • Source Control integration for Subversion and Git
  • Build System support via Runnables

http://redcareditor.com/