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 Crons | |
| class CheckRecurringDocuments < ApplicationCron | |
| CUTOFF_EARLIEST = -> { Time.current - 20.days } | |
| CUTOFF_LATEST = -> { Time.current - 12.months } | |
| def run | |
| [ | |
| Documentation::Categories::VatReturns.all, | |
| Documentation::Categories::CorporationTax.all, | |
| Documentation::Categories::PaymentsToThirdParties.all, # TODO: get all with had_period? true |
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
| require 'active_record' | |
| class AddMeowToCat < ActiveRecord::Migration | |
| def change | |
| add_column :cats, :meow, :string | |
| end | |
| end | |
| AddMeowToCat.new.migrate :up | |
| # migrates up the table 'cats' using a database connection from the ActiveRecord::Base pool |
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 CuteCat | |
| def meow | |
| "meow" | |
| end | |
| end | |
| cute_cat = CuteCat.new | |
| cute_cat.meow # -> "meow" | |
| cute_cat.define_singleton_method(:bark) { "#{meow}... bark" } |
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
| $.ajax('http://whatever.com').success(callback) | |
| .failure(callback2) | |
| .always(callback3) |
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
| columns = execute("select \"column\" from pg_table_def where tablename = '#{tables.first}'") | |
| .field_values('column') | |
| selections = tables.map { |table| "select #{columns.join(', ')} from #{table}" } | |
| union = selections.join("\nunion ") | |
| execute "create or replace view #{view_name} as\n#{union};" |
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
| input = %w(my_first_love, my_second_love, some_person) | |
| # Required output: ['first', 'second'] | |
| # Which do you like best? Anyone got a neater one? | |
| #1 | |
| input.map { |love| love.match(/my_(\w+)_love/) } | |
| .compact | |
| .map { |match| match[1] } |