How To Write Your Own Time Comparison Function in Ruby Like time_ago_in_words Without Rails
# time_ago_in_words(Time.now, 1.day.ago) # => 1 day # time_ago_in_words(Time.now, 1.hour.ago) # => 1 hour def time_ago_in_words(t1, t2) s = t1.to_i - t2.to_i # distance between t1 and t2 in seconds resolution = if s > 29030400 # seco...
Written by Sean Behan on 10/17/2013
Roll Your Own Full Page Caching in Sinatra
It's as simple as this. # app.rb get '/:slug' do @slug = File.basename("#{params[:slug]}") @cache = "public/cache/#{@slug}.html" if File.exists?(@cache) File.read(@cache) else @post = Post.find_by(page: params[:slug]) ...
Written by Sean Behan on 08/23/2013