1. 10 Ruby and Rails Pro Tips
Michel Pigassou, Co-founder & CTO at Fidzup, michel@fidzup.com
2014-08-05
A few things you may or may not know
2. Use debugger
Just use it!
How? http://guides.rubyonrails.org/debugging_rails_applications.html
Bonus:
byebug for Ruby 2: https://github.com/deivid-rodriguez/byebug
11. Let the DB Do its Work
Filling dates without value:
WITH filled_dates as (
select day, 0 as blank_count from generate_series('#{@start_date}', current_date::date, '1 day') as day
),
stats as (
SELECT COUNT(*) AS count, date_trunc('day', created_at) AS day
FROM "checkins" WHERE
(created_at >= '#{@start_date.to_s}')
GROUP BY date_trunc('day', created_at)
ORDER BY date_trunc('day', created_at)
)
SELECT date(filled_dates.day), coalesce(stats.count, filled_dates.blank_count) as count
FROM filled_dates
LEFT OUTER JOIN stats on stats.day = filled_dates.day
ORDER BY filled_dates.day;
Also: Postgresql uuid(), MD5(), etc.