java7 ネットワーク越しにディレクトリ監視
macからwindowsの共有ディレクトリとwindowsからwindowsの共有ディレクトリは監視できた
linuxはインストールするのがめんどくさいからやめた
OSというか共有の仕方に関係ありそうな気もする
import java.io.IOException; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Path; import java.nio.file.StandardWatchEventKinds; import java.nio.file.WatchEvent; import java.nio.file.WatchKey; import java.nio.file.WatchService; public class JavaApplication1 { public static void main(String[] args) throws IOException, InterruptedException { FileSystem fileSystem = FileSystems.getDefault(); // for mac -> windows //Path path = fileSystem.getPath("/Volumes/shared"); // for windows -> windows //Path path = fileSystem.getPath("\\\\servername_or_ip\\dirname"); Path path = fileSystem.getPath("/Volumes/shared"); WatchService watchService = fileSystem.newWatchService(); path.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE); while(true) { WatchKey watchKey = watchService.take(); for (WatchEvent<?> event : watchKey.pollEvents()) { System.out.println(event.kind() + " " + event.context()); } watchKey.reset(); } } }
slim3をコマンドラインから実行する
下記をpom.xmlに追記して
mvn jetty:run
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <configuration> <scanIntervalSeconds>10</scanIntervalSeconds> <contextPath>/</contextPath> <webXml>war/WEB-INF/web.xml</webXml> <webAppSourceDirectory>war</webAppSourceDirectory> </configuration> </plugin>
MacでGauche
環境は
% gosh -V
Gauche scheme shell, version 0.9.1 [utf-8,pthreads], i386-apple-darwin10.6.0
Emacs
GNU Emacs 23.3.1 (x86_64-apple-darwin, NS apple-appkit-1038.35) of 2011-03-10 on black.porkrind.org
Gaucheのインストールは省略
;; Gaucheの設定
(modify-coding-system-alist 'process "gosh" '(utf-8 . utf-8)) (setq scheme-program-name "/usr/local/bin/gosh") (setq gauche-program-name "/usr/local/bin/gosh") (autoload 'scheme-mode "cmuscheme" "Major mode for Scheme." t) (autoload 'run-scheme "cmuscheme" "Run an inferior Scheme process." t) (defun scheme-other-window () "Run scheme on other window" (interactive) (switch-to-buffer-other-window (get-buffer-create "*scheme*")) (run-scheme scheme-program-name) (auto-complete-mode)) (define-key global-map "\C-cs" 'scheme-other-window)
入門記事を見ながら勉強中...
もうひとつのScheme入門
rails入力チェックの独自実装
rails3でvalidatorを実装した場合に
lib/hoge_validator.rbをおいただけだとモデルで
validates, :foo, :hoge => true
でそんなバリデーションないヽ(`Д´)ノプンプンって怒られる
rails3からは自動で読み込まないとのことで
require 'lib/hoge_validator.rb'
を入れる必要がある
調べるの1時間もかかった...
railsでメッセージを日本語化するときにネストした項目を日本語する方法
AテーブルにひもづくBテーブルを一度に更新する場合にAのエラーもBのエラーも出したい
config/locales/ja.yml (どっかからパクったのに追加)
activerecord: models: user: ユーザー item: アイテム attributes: user: name: 名前 sex: 性別 age: 年齢 item: name: アイテム名 price: 値段 item: name: アイテム名 price: 値段
modelsにモデルの日本語名、attributesにモデル>属性になるように記述する
deviseでモジュールを追加する方法
change_tableでmigrationを記述
class AddUsersLockable < ActiveRecord::Migration def self.up change_table(:users) do |t| t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both end add_index :users, :unlock_token, :unique => true end def self.down end end
migration実行
rake db:migrate
model修正
lockableを追加した
devise :database_authenticatable, :timeoutable, :recoverable, :rememberable, :trackable, :validatable, :lockable