range1 = ::Scheduling::DateRange.new(1.day.ago..Time.now)
range2 = ::Scheduling::DateRange.new(2.days.ago..Time.now)
range1.exclusion(range2) => []
range2.exclusion(range1) => [::Scheduling::DateRange.new(2.days.ago..1.day.ago)]
This file contains 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
-- Create tables | |
CREATE TABLE groups (id serial NOT NULL, name character varying NOT NULL); | |
CREATE TABLE network_group_members (pid integer, cid integer NOT NULL); | |
-- Insert the groups | |
INSERT INTO groups (name) VALUES ('GROUP 1'),('GROUP 2'),('GROUP 3'),('GROUP 4'),('GROUP 5'),('GROUP 6'),('GROUP 7'),('GROUP 8'),('GROUP 9'),('GROUP 10'),('GROUP 11'),('GROUP 12'),('GROUP 13'); | |
-- Build the "Network" | |
INSERT INTO network_group_members(pid,cid) VALUES (1,2),(1,3),(1,4),(2,5),(5,6),(5,7),(7,8),(3,9),(4,10),(4,11),(11,12),(12,13); |
This file contains 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 ParamsSlicer | |
def initialize(params, *whitelist) | |
@params = params | |
@nested_whitelist = whitelist.extract_options! | |
@whitelist = whitelist | |
end | |
def call | |
params.slice(*whitelist).tap do |result| | |
nested_whitelist.each do |k, v| |
We can't make this file beautiful and searchable because it's too large.
This file contains 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
Location Id,Bing Display Name,Location Type,Replaces,Status,AdWords Location Id | |
1,Albanie,Country,,Active,2008 | |
2,Antarctique,Country,,Active,2010 | |
3,Algérie,Country,,Active,2012 | |
4,Samoa américaines,Country,,Active,2016 | |
5,Andorre,Country,,Active,2020 | |
6,Angola,Country,,Active,2024 | |
7,Antigua-et-Barbuda,Country,,Active,2028 | |
8,Argentine,Country,,Active,2032 | |
9,Australie,Country,,Active,2036 |
This file contains 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 CreateInvoiceNumbers < ActiveRecord::Migration | |
def up | |
create_table :invoice_numbers do |t| | |
t.integer :year, null: false, unique: true | |
t.integer :next_number_within_year, null: false, default: 1 | |
end | |
add_index :invoice_numbers, :year, unique: true | |
(2016..2045).each do |year| |
This file contains 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 ApplyProductStateOrder | |
def initialize(status_change_order) | |
@status_change_order = status_change_order | |
end | |
def call | |
ActiveRecord::Base.transaction do | |
state_change = update_product | |
status_change_order.update_timestamps(state_change) |
This file contains 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 ApplyProductStateOrder | |
def initialize(status_change_order) | |
@status_change_order = status_change_order | |
end | |
def call | |
with_valid_state_change do | |
ActiveRecord::Base.transaction do | |
product.send(transition) | |
product.save! |
This file contains 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
# frozen_string_literal: true | |
source "https://rubygems.org" | |
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } | |
gem 'twilio-ruby' | |
gem 'dotenv' | |
gem 'waterfall' |
This file contains 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
# test utility for the script | |
def assert(actual, expected) | |
if actual == expected | |
puts "ok #{expected}" | |
else | |
puts "ko, you expected: #{expected} but got #{actual}" | |
end | |
end | |
# first implementation, more functional programming friendly, pure method |
This file contains 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 CreateUserFromInvitation | |
include Waterfall | |
def initialize(invitation) | |
@invitation = invitation | |
end | |
def call | |
chain { build_user } | |
when_falsy { user.save } |
NewerOlder