Skip to content

Instantly share code, notes, and snippets.

View vesan's full-sized avatar

Vesa Vänskä vesan

View GitHub Profile

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).

/**
* Generic hook for submitting data via fetcher using FormData.
* Relies on React Router 7's type generation for the action's return type.
*
* @template TSchema - The Zod schema type for input data validation and type inference.
* @template TActionReturn - The specific return type of the target route's action function (inferred via RR7 typegen).
* @param _schema - Zod schema (used primarily for type inference of the 'data' in submit).
* @param actionUrl - The target URL for the fetcher submission.
* @param prepareFormData - A function that takes the typesafe data object (z.infer<TSchema>) and returns a FormData instance.
@amkisko
amkisko / debug_helper.rb
Last active June 1, 2025 14:16
Amazing debugging for grape-ruby, rspec test examples, show SQL traces, show stack calls and all exceptions in stack, helper to find out which spec file stuck, store logs to files
require "amazing_print"
class Debug
attr_reader :messages, :before_gc_stats, :after_gc_stats, :time_report, :mem_report
def initialize(with_sql: false, with_stack: false, store_file: false, console_print: false, output_path: nil, context: nil, file_prefix: nil, messages: [])
@with_sql = with_sql
@with_stack = with_stack
@console_print = console_print
@context = context
@messages = messages
@chmolto
chmolto / transporter.py
Last active April 14, 2025 20:13 — forked from keshav-space/transporter.py
Migrate GitHub project between accounts
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://aboutcode.org for more information about nexB OSS projects.
#
from traceback import format_exc as traceback_format_exc
import requests
@amkisko
amkisko / solid_queue_alive.rb
Last active May 23, 2025 10:06
Rails solid_queue / solid queue alive server livenessProbe readinessProbe health check kubernetes helper
class SolidQueueAliveServer
def initialize(host: nil, port: nil, engine: nil, logger: nil)
@host = host || "0.0.0.0"
@port = port || 7433
@engine = engine || "puma"
@logger = logger || Rails.logger
end
def run!
require "rackup"
@robconery
robconery / Book.md
Last active June 6, 2025 18:04
Obsidian Bujo Templates
title description author created updated
{{title}}
{{description}}
{{author}}
{"DATE:YYYY-MM-DD HH:mm:ss" => nil}
{"DATE:YYYY-MM-DD HH:mm:ss" => nil}

cover|150

@JonnieCache
JonnieCache / zellij_tab_title.zsh
Last active April 17, 2025 17:13
ZSH script to set the zellij tab title to the running command line, or the current directory
function current_dir() {
local current_dir=$PWD
if [[ $current_dir == $HOME ]]; then
current_dir="~"
else
current_dir=${current_dir##*/}
fi
echo $current_dir
}

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
@amkisko
amkisko / debug_callbacks.rb
Last active February 6, 2025 09:12
Rails ActiveRecord and ActiveSupport callbacks wrapper for collecting metrics in pair with rspec
if ENV["DEBUG_CALLBACKS"]
Rails.application.eager_load!
ActiveRecord::Callbacks::CALLBACKS.each do |callback_type|
ApplicationRecord.descendants.each do |model|
kind, name = callback_type.to_s.split("_")
chain = model.__callbacks[name.to_sym]&.send(:chain)
filtered = chain&.select { |chain_callback| chain_callback.kind == kind.to_sym }
$callbacks_counter ||= {}
$callbacks_counter[model.name] ||= {}
@amkisko
amkisko / Gemfile
Last active April 28, 2025 12:51
ActiveAdmin v4 propshaft, importmap, stimulus, tailwindcss and ActionPolicy configuration
# NOTE: partial content required for Gemfile
gem "rails"
gem "propshaft"
gem "importmap-rails"
gem "stimulus-rails"
gem "tailwindcss-rails"
gem "action_policy"