Skip to content

Instantly share code, notes, and snippets.

View Irostovsky's full-sized avatar

Ivan Rostovsky Irostovsky

View GitHub Profile
"""
Create missing ReservationExtraFee records for BOOKING reservations affected by PCPv2
(created between 2026-03-24 13:00 UTC and 2026-04-01 09:54 UTC) and generate
invoices for those outside the automatic creation window.
Accounts for Booking.com fee renaming:
- resort_fee, destination_fee, etc. may arrive as "service_charge"
- tourism_fee is mapped into taxe_sejour (city tax)
Usage:
@Irostovsky
Irostovsky / celery-ack-late-idempotency-audit.md
Created February 5, 2026 08:35
Celery ack_late idempotency audit - all tasks analysis

Celery ack_late Idempotency Audit

Context

Celery 5.x has a known bug: without ack_late, the prefetch count is not enforced correctly. Workers grab all messages from the queue into an internal buffer, acking them immediately on receipt. RabbitMQ then shows 0 "Ready" messages, and autoscalers have nothing to trigger on.

With ack_late enabled, the prefetch limit works correctly: each worker holds at most prefetch_multiplier * concurrency (= 2 in our case) unacked messages, and the rest stay as "Ready" in the queue.

Trade-off

@Irostovsky
Irostovsky / show_sql_in_shell
Created May 27, 2019 11:54
python and django tricks
import logging
log = logging.getLogger('django.db.backends')
log.setLevel(logging.DEBUG)
log.addHandler(logging.StreamHandler())
@Irostovsky
Irostovsky / timer.rb
Created July 19, 2018 09:26
Bench timer
# frozen_string_literal: true
module Utils
class Timer
def self.call(name)
t = Time.zone.now
result = yield
time = ((Time.zone.now - t).to_d * 1000).to_i
p "++++++++++ #{name}: #{time}ms"
{ result: result, time: time }
class FooPresenter
include Draper::Decoratable
attr_accessor :user
def initialize(user)
@user = user
end
def name
user.name
@Irostovsky
Irostovsky / tasks_1.rb
Created July 31, 2017 09:12
Let we have Post(title, body) -> Comments(body). Write the active record query to get all posts, where "query" is into title or body or comment.
# Let we have Post(title, body) -> Comments(body).
# Write the active record query to get all posts, where "query" is into title or body or comment.
class Post < ActiveRecord::Base
#title, body
has_many :comments
scope :search, ->(text) {
wildcard_search = "%#{text}%"
joins(:comments).where("title ILIKE :search OR body ILIKE :search OR comments.body ILIKE :search", search: wildcard_search)
Dir["app/assets/images/*"].each do |image|
name = File.basename(image)
if Dir.glob("**/*").reject {|fn| File.directory?(fn) }.
map{|fn| File.read(fn).include?(name) ? fn : nil }.any?
p image
else
p "To delete: #{image}"
File.delete image
end
end
module AuthenticityTokenCatcher
extend ActiveSupport::Concern
included do
rescue_from ActionController::InvalidAuthenticityToken do |exception|
if request.referrer
flash[:error] = I18n.t :authenticit_token_error
redirect_to request.referrer
else
raise exception
end
@Irostovsky
Irostovsky / gist:895705a15e11f04f3032538a241446c3
Created February 10, 2017 12:36
Equi: Find an index in an array such that its prefix sum equals its suffix sum.
This is a demo task.
A zero-indexed array A consisting of N integers is given. An equilibrium index of this array is any integer P such that 0 ≤ P < N and the sum of elements of lower indices is equal to the sum of elements of higher indices, i.e.
A[0] + A[1] + ... + A[P−1] = A[P+1] + ... + A[N−2] + A[N−1].
Sum of zero elements is assumed to be equal to 0. This can happen if P = 0 or if P = N−1.
For example, consider the following array A consisting of N = 8 elements:
A[0] = -1
A[1] = 3