Skip to content

Instantly share code, notes, and snippets.

View RStankov's full-sized avatar
🤖
👨‍💻

Radoslav Stankov RStankov

🤖
👨‍💻
View GitHub Profile
When tasked with generating a new file (e.g., model, factory, test), first identify existing files of the same type in the project. Open several relevant examples and analyze their structure, naming conventions, and implementation patterns. Use these patterns as a reference to create a consistent and idiomatic new file. Focus on reusing established conventions and aligning with the existing codebase.
# When writing Ruby
Follow the project rubocop rules.
- Prefer `case in`, instead of `case where`
- Prefer `_1` for blocks with one argument, where you otherwise will use a single letter
- Use `!` versions for `save!` / `update!` / `destroy!` when not checking the result of the operation
- Don't define methods ending with `!` unless there is a method with the same name without `!`

LIVO Engineering

This is LIVO engineering team operates. We operate in Collaborative Single Player Mode.

Collaborative Single Player Mode

Everyone should be able to execute independently without depending on others, but the team should move with the same rhythm.

1) Single Player Mode

Every engineer should be able to take a feature from inception to completion without unnecessary dependencies.

batch = AngryBatch.new label: 'BulkWithdraw'
# check inherits from ActiveJob::Base
batch.on_complete Finance::WithdrawBulkCompleteJob, bulk_withdraw
zerod_fees do |fee|
# check inherits from ActiveJob::Base
# check job includes AngryJob::Batchable
batch.enqueue Taxation::MaintenanceTaxAutoAdjustmentJob, bulk_withdraw, fee: fee, amount: 0
end
# frozen_string_literal: true
require 'net/http'
require 'json'
module OpenAI
extend self
API_KEY = ENV.fetch('openai_api_key')
@RStankov
RStankov / detectUnusedFields.ts
Created September 23, 2024 13:12
Detects unused GraphQL fields
import * as glob from 'glob';
import difference from 'lodash/difference';
import startCase from 'lodash/startCase';
import union from 'lodash/union';
import uniq from 'lodash/uniq';
import { CodeFileLoader } from '@graphql-tools/code-file-loader';
import { DocumentNode, DefinitionNode, OperationDefinitionNode } from 'graphql';
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
import { loadDocuments } from '@graphql-tools/load';
import { visit } from 'graphql/language/visitor';
# frozen_string_literal: true
module ErrorReporting
extend self
def assign_user(user)
return unless Rails.env.production?
Sentry.set_user(
id: user.id,
@RStankov
RStankov / belongs_to_polymorphic.rb
Last active March 25, 2025 09:11
Database tips
module AngrySupport::BelongsToPolymorphic
def belongs_to_polymorphic(name, allowed_classes:, **options)
belongs_to name, polymorphic: true, **options
validates "#{name}_type", inclusion: { in: allowed_classes.map(&:name), allow_nil: !!options[:optional] }
define_singleton_method(:"#{name}_types") { allowed_classes }
define_singleton_method(:"with_#{name}") do |type|
type = case type
@RStankov
RStankov / application_component.rb
Created April 25, 2024 11:56
ViewComponent Tips
class ApplicationComponent < ViewComponent::Base
private
def fetch_with_fallback(hash, key, fallback)
hash.fetch(key) do
ErrorReporting.capture_exception(%(key not found: "#{key}"))
fallback
end
end
@RStankov
RStankov / counter_cache.sql
Created April 4, 2024 13:05
Counter Cache in SQL
CREATE OR REPLACE FUNCTION comments_count_update()
RETURNS TRIGGER AS $$
BEGIN
-- Increase count on insert
IF (TG_OP = 'INSERT') THEN
UPDATE posts SET comments_count = comments_count + 1
WHERE posts.id = NEW.post_id;
RETURN NEW;
-- Decrease count on delete
ELSIF (TG_OP = 'DELETE') THEN
@RStankov
RStankov / emergency_kit.md
Created March 7, 2024 19:38
⛑️ Emergency Kit

⛑️ Emergency Kit

🎥 Video walkthrough of emergency handling `[VIDEO IN TOOL LIKE LOOM]`

Tools