Skip to content

Instantly share code, notes, and snippets.

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
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
class CuteCat
def meow
"meow"
end
end
cute_cat = CuteCat.new
cute_cat.meow # -> "meow"
cute_cat.define_singleton_method(:bark) { "#{meow}... bark" }
$.ajax('http://whatever.com').success(callback)
.failure(callback2)
.always(callback3)
@parrydotmy
parrydotmy / thing.rb
Last active February 15, 2025 09:16
rb
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};"
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] }