Mittwoch, 3. Dezember 2008

Start/Stop Mysql on Leopard

sudo /usr/local/mysql/support-files/mysql.server start

sudo /usr/local/mysql/support-files/mysql.server stop

Donnerstag, 13. November 2008

Rspec installation

>sudo gem install ZenTest
>sudo gem install rspec-rails

in application root:
>ruby script/generate rspec

autotest (if it hangs use >RSPEC=true autotest)


rake spec
rake spec:app

rake spec:models
rake spec:controllers
rake spec:views
rake spec:helpers
rake spec:plugins
rake --tasks:plugins

Freitag, 7. November 2008

Compare time

module ApplicationHelper
..SOMETIME_FORMAT = "%a %b %d %H:%M:%S %z %Y"
..SOMETIME_FORMAT_DB = '%Y-%m-%d %H:%M:%S'

..def sometime_this_month(time, format='user')
....return time.beginning_of_month.strftime(SOMETIME_FORMAT) if format == 'user'
....return time.beginning_of_month.strftime(SOMETIME_FORMAT_DB) if format == 'db'
..end

..def sometime_today(time, format='user')
....return time.beginning_of_day.strftime(SOMETIME_FORMAT) if format == 'user'
....return time.beginning_of_day.strftime(SOMETIME_FORMAT_DB) if format == 'db'
..end

end


Time based finds.

created_at time from the database is: "2008-10-24 22:06:18 +0200"

However retrieving the Time.now results in the format as follows: "Fri Nov 07 15:31:56 +0100 2008"

end

Named scope with variables

in model *.rb (in this case weight_meassurements.rb)

named_scope :user_weight_meassurements, lambda { |user_id| { :order => 'created_at DESC', :conditions => ["user_id == ?", user_id] } }

named_scope :today, lambda { |today| { :conditions => ["created_at > ?", today] } }

Calling from the controllers or helpers @user.weight_meassurements.today('2008-11-07 00:00:00') wil retrieve all weight_meassurement record belonging to the user created after midnight of the passed date.

You can also call WeightMeassurements.user_weight_meassurements(@user.id) for all this user weight meassurement records.

Montag, 27. Oktober 2008

Mysql import

mysql -p -u{Benutzername} {DB-Name} < filename

Converting database time to human time

model.created_at.begining_of_day.strftime(%B, %Y)
>October, 2008
model.creted_at.strftime("%d").to_i.ordinalize
>25th

%a weekday name.
%A weekday name (full).
%b month name.
%B month name (full).
%c date and time (locale)
%d day of month [01,31].
%H hour [00,23].
%I hour [01,12].
%j day of year [001,366].
%m month [01,12].
%M minute [00,59].
%p AM or PM
%S Second [00,61]
%U week of year (Sunday)[00,53].
w weekday [0(Sunday),6].
W week of year (Monday)[00,53].
x date (locale).
%X time (locale).
%y year [00,99].
%Y year [2000].
%Z timezone name.

Donnerstag, 16. Oktober 2008

Memcache Rails

>sudo port install memcached
>/opt/local/bin/memcached -d -m 64 -u www -l -p 11211

see also
/Library/LaunchDaemons/org.macports.memcached.plist
memcached -h
man memcached