Skip to content

Instantly share code, notes, and snippets.

View Yegorov's full-sized avatar
🏢
Work it harder. Make it better. Do it faster.

Artem Yegorov

🏢
Work it harder. Make it better. Do it faster.
View GitHub Profile
@clashnewbm3
clashnewbm3 / Code
Created August 26, 2025 11:06
Ruby Hacker Text Animation
print "\e[?25l"
rows, cols = `stty size`.split.map(&:to_i)
drops = Array.new(cols) { rand(rows) }
chars = ("0".."9").to_a + ("A".."Z").to_a + ("a".."z").to_a
loop do

name: tester description: Use this agent when you need to write RSpec tests for new functionality, including feature specs for user workflows and unit tests for models, services, or other classes. Examples: Context: User has just implemented a new authentication feature and needs comprehensive test coverage. user: 'I just added magic link authentication to the User model. Can you write tests for this?' assistant: 'I'll use the rspec-test-writer agent to create comprehensive tests for your magic link authentication feature.' Since the user needs RSpec tests written for new functionality, use the rspec-test-writer agent to create appropriate test coverage. Context: User has created a new controller action and wants to ensure it's properly tested. user: 'I added a new endpoint for project time tracking. Here's the controller code...' assistant: 'Let me use the rspec-test-writer agent to write feature specs and controller tests for your new time tracking en

@mdchaney
mdchaney / fix_encoding.rb
Last active August 2, 2025 11:35
Fix encoding to deal with mixed UTF-8 / Latin-1
def fix_encoding(str)
# The "b" method returns a copied string with encoding ASCII-8BIT
str = str.b
# Strip UTF-8 BOM if it's at start of file
if str.byteslice(0..2) == "\xEF\xBB\xBF".b
str = str.byteslice(3..-1)
end
if str.ascii_only?
@rain-1
rain-1 / base model trends.md
Last active October 19, 2025 08:19
base model trends.md

Namespaces 101

Introduction

Ruby has recently merged namespaces as an experimental feature that is disabled by default, as of this writing.

This is a non-trivial development driven by @matz himself, and mainly implemented by @tagomoris, who just became a Ruby committer (🎉).

The feature has been cooking for a long time, with a first ticket opened a couple of years ago (#19744) and a revised one opened just last week (#21311).

# Usage:
#
# class Post < ApplicationRecord
# include HasNanoid
# has_nanoid
# end
#
module HasNanoid
extend ActiveSupport::Concern
require "digest"
require "rack"
# This class encapsulates a unit of work done for a particular tenant, connected to that tenant's database.
# ActiveRecord makes it _very_ hard to do in a simple manner and clever stuff is required, but it is knowable.
#
# What this class provides is a "misuse" of the database "roles" of ActiveRecord to have a role per tenant.
# If all the tenants are predefined, it can be done roughly so:
#
# ActiveRecord::Base.legacy_connection_handling = false if ActiveRecord::Base.respond_to?(:legacy_connection_handling)
@joeldrapper
joeldrapper / fuzzy_index.rb
Created March 27, 2025 11:20
Simple fuzzy index with left weight
class FuzzyIndex
def initialize
@index = Hash.new { |h, k| h[k] = Set.new }
end
def []=(key, value)
trigrams(key).each { @index[it] << [key, value] }
end
def [](query)
@lazaronixon
lazaronixon / _form.html.erb
Last active September 22, 2025 15:08
Hotwire Event-Driven Update Pattern
<%= form_with model: citizen, class: "card flex flex-col gap", data: { controller: "form" } do |form| %>
<div class="flex flex-col gap mb-2">
<div class="flex flex-col gap-half">
<% countries = Country.order(:name) %>
<%= label_tag :country_id, "Country", class: "text-sm font-medium leading-none" %>
<%= select_tag :country_id, options_from_collection_for_select(countries, :id, :name, citizen.country_id), include_blank: "Select one", class: "input", data: { action: "form#submit", form_submitter_param: "on_country_change" } %>
</div>
<div class="flex flex-col gap-half">
<% states = State.where(country_id: citizen.country_id).order(:name) %>
@jwbee
jwbee / jq.md
Last active July 15, 2025 12:12
Make Ubuntu packages 90% faster by rebuilding them

Make Ubuntu packages 90% faster by rebuilding them

TL;DR

You can take the same source code package that Ubuntu uses to build jq, compile it again, and realize 90% better performance.

Setting

I use jq for processing GeoJSON files and other open data offered in JSON format. Today I am working with a 500MB GeoJSON file that contains the Alameda County Assessor's parcel map. I want to run a query that prints the city for every parcel worth more than a threshold amount. The program is