This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Slot.group('TIME(datetime)').count | |
| # => {"06:00:00"=>8, "07:00:00"=>8, "08:00:00"=>8, "09:00:00"=>8, "10:00:00"=>8, "11:00:00"=>8, "12:00:00"=>8, "13:00:00"=>8, "14:00:00"=>8, "15:00:00"=>8, "16:00:00"=>8, "17:00:00"=>8, "18:00:00"=>8, "19:00:00"=>8} | |
| Slot.group('DATE(datetime)').count | |
| # => {"2013-08-29"=>14, "2013-08-30"=>14, "2013-08-31"=>14, "2013-09-01"=>14, "2013-09-02"=>14, "2013-09-03"=>14, "2013-09-04"=>14, "2013-09-05"=>14} | |
| Slot.group('datetime::time').count | |
| Slot.group('datetime::date').count |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <% | |
| min_hour, max_hour = @slots.minimum_hour, @slots.maximum_hour | |
| datetimes = (@slots.minimum_date..@slots.maximum_date).map do |date| | |
| (min_hour..max_hour).map do |hour| | |
| date.to_datetime.change(hour: hour) | |
| end | |
| end.flatten | |
| @slots = @slots.group_by(&:datetime) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| duration = '1h2min3s' | |
| # duration = '2min3s' | |
| # duration = '3s' | |
| # match = duration.match(/(?<hours>.+h)?(?<minutes>.+min)?(?<seconds>.+s)?/) | |
| # hours, minutes, seconds = [match[:hours], match[:minutes], match[:seconds]].map(&:to_i) | |
| # 3600 * hours + 60 * minutes + seconds | |
| match = duration.match(/ | |
| ( (?<hours>[[:digit:]]+)h ){0,1} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Antihero::Application.routes.draw do | |
| scope module: :admin, as: :admin do | |
| root 'dashboard#index' | |
| resources :articles, only: [:new, :create] | |
| end | |
| end | |
| # Prefix Verb URI Pattern Controller#Action | |
| # admin_root GET / admin/dashboard#index | |
| # admin_articles GET /articles(.:format) admin/articles#index |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Macchiato | |
| class Application < Rails::Application | |
| config.autoload_paths += Dir[Rails.root.join('lib', 'validators').to_s] | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person | |
| @all = [] | |
| def self.all | |
| @all | |
| end | |
| def self.where(conditions) | |
| all.select do |person| | |
| conditions.map do |k, v| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gem 'bootstrap-sass' | |
| gem 'bcrypt-ruby', '~> 3.1.2' | |
| gem_group :development, :test do | |
| gem 'debugger' | |
| end | |
| gem_group :development do | |
| gem 'commands' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Rails.if __FILE__ == $PROGRAM_NAME | |
| $stdout.puts ENV['ouch']['ouch'] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ConnectController | |
| def authorize | |
| redirect_to stripe_authorize_url | |
| end | |
| def callback | |
| if code = params[:code] | |
| auth_token = client.auth_code.get_token(code) | |
| current_user.update!(token: auth_token) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # As a first example, let's consider an "adjacency list", a tree represented in a table. Suppose we have a table comments, representing a threaded discussion: | |
| comments = Arel::Table.new(:comments) | |
| # [:id, :body, :parent_id] | |
| replies = comments.alias | |
| comments_with_replies = \ | |
| comments.join(replies).on(replies[:parent_id].eq(comments[:id])) | |
| # => SELECT * FROM comments INNER JOIN comments AS comments_2 WHERE comments_2.parent_id = comments.id |