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
@joeywang
joeywang / audit.md
Created September 23, 2024 21:43
Auditing in Database Applications: Ensuring Data Integrity and Compliance

Auditing in Database Applications: Ensuring Data Integrity and Compliance

In today's data-driven world, maintaining the integrity and security of information stored in databases is paramount. One crucial aspect of this is auditing - the practice of tracking and logging all changes made to data within a system. This article explores the importance of auditing in database applications and compares several popular auditing solutions.

Why Auditing Matters

Implementing a robust auditing system in your database application offers several key benefits:

  1. Compliance: Many industries are legally required to maintain an audit trail of changes to sensitive data.
  2. Security: Audit logs help detect unauthorized access or potential data breaches.
@hopsoft
hopsoft / README.md
Last active July 30, 2024 19:55
Simple Template Rendering

Simple Template Rendering

I'm experimenting with a simple template rendering solution that leverages Ruby's native String formatting. It feels a little bit like Mustache templates. Note that this demo adds new "formatting specifiers" to support Rainbow color mechanics.

Tip

See the files below for the implementation... and note that this is simply a proof of concept (POC)

Usage

require 'open3'
require 'reline'
class Reline::LineEditor
private def perform_completion(list, _just_show_list)
_preposing, target, _postposing = retrieve_completion_block
namespace = IRB.CurrentContext.io.retrieve_doc_namespace(target)
namespace = namespace.first if namespace.is_a?(Array)
if namespace.nil? || !('A'..'Z').include?(namespace[0])
namespace = IRB.conf[:__MAIN__]
# In your Gemfile
gem "localhost"

# Then, depending on your desired server
gem "falcon"
gem "puma"
@julianrubisch
julianrubisch / _search.html.erb
Created June 7, 2024 10:02
Sitepress Pagefind Integration
<div data-controller="search">
<div data-search-target="button">
<div role="button" data-action="click->search#open keydown.meta+k@document->search#open keydown.ctrl+k@document->search#open" class="outline secondary search">
<%= heroicon "magnifying-glass" %>
<span>Search</span>
<kbd>Cmd/Ctrl+K</kbd>
</div>
<dialog data-search-target="dialog">
<article>
@kaspth
kaspth / concern.rb
Created June 4, 2024 20:37
Writing Concerns without the `extend`/`included`/`class_methods` boilerplate.
# Maybe there's a way to support ActiveSupport::Concern's dependencies too?
# Although this doesn't use the module hierarchy, so `prepend` can't work.
class Concern < Module
def initialize(&block) = @block = block
def included(klass) = klass.class_eval(&@block)
end
module Kernel
def Concern(...) = Concern.new(...)
end

Ruby: The future of frozen string literals

What is a literal?

In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.

Some examples:

7 # integer literal
@michelson
michelson / async_method_job.rb
Created April 23, 2024 01:50
Asynchronously Concern
class AsyncMethodJob < ApplicationJob
queue_as :default
def perform(target:, method_name:, args:, queue_name: :default)
self.class.queue_as(queue_name)
# `target` could be either an instance or a class
target = target.constantize if target.is_a?(String) # Convert class name to class object if needed
target.send(method_name, *args)
end
end
@owaiswiz
owaiswiz / print_redundant_indexes.rb
Last active September 5, 2024 04:42
Print redundant indexes in a Rails app.
# Unnecessary indexes slows down writes and consumes additional storage and memory.
# Just paste this snippet in your Rails console (bundle exec rails c).
# And it will print all redundant indexes that are already covered by another index on the table:
# Table `pages`: index `site_idx` (site_id) already covered by `site_slug_idx` (site_id,slug)
# Table `optins`: index `list_idx` (list_id) already covered by `list_active_idx` (list_id,active)
ActiveRecord::Base.connection.tables.map do |table|
indexes = ActiveRecord::Base.connection.indexes(table).select(&:valid).reject(&:where)
@searls
searls / ensures_logger_broadcasts_to_stdout.rb
Last active March 4, 2024 19:18
This logger wrapper I wrote.
# Leverages the BroadcastLogger introduced in Rails 7.1 to wrap the current
# logger in a new logger that broadcasts to both the current logger and $stdout
#
# (Announcement: https://rubyonrails.org/2023/9/29/this-week-in-rails)
#
# If the current logger already broadcasts to $stdout, it will not be wrapped,
# making it safe to call this method multiple times without knowing the current
# logging "sitch".
#
# Usage probably looks something like this: