Skip to content

Instantly share code, notes, and snippets.

View shotgundebugging's full-sized avatar

Mircea shotgundebugging

View GitHub Profile
tmux new -A -s codex
codex
ttyd -p 7681 -i eth0 -R -O tmux attach-session -t codex -r
# -p 7681 sets the web port.
# -i eth0 binds ttyd to your LAN interface (use wlan0 if on Wi-Fi).
# -R / --readonly disables browser input (no typing/click-to-send-keys).
# -O blocks websocket connections from different origins.
@shotgundebugging
shotgundebugging / route-vs-context-state.js
Created February 20, 2026 15:23
Route vs context state
- Route state (location.state) is a one-time payload passed during navigation (navigate(..., { state }) or <Link state={...}>).
- It does not auto-refresh.
- It can be stale after backend changes.
- It may be missing on direct URL loads/reloads.
- Context state (UserAdminContext) is shared app state provided by UserLinks.
- It is loaded/refreshed from API (fetchUser(userId)).
- It updates over time and is the source of truth for current user data in that section.
- It is consistent across nested admin user pages.
open_tx = ActiveRecord::Base.connection.open_transactions
Rails.logger.info(
"[TX_DEBUG] before_write user_id=#{user.id} open_transactions=#{open_tx} [/TX_DEBUG]"
)
user.update!(stripe_customer_id: stripe_customer.id)
Rails.logger.info(
"[TX_DEBUG] after_write user_id=#{user.id} stripe_customer_id=#{User.where(id: user.id).pick(:stripe_customer_id).inspect} " \
"open_transactions=#{open_tx} rollback_risk=#{open_tx.positive?} [/TX_DEBUG]"
# Required Ruby version
bundle exec ruby -e 'puts Gem::Specification.find_by_name("railties").required_ruby_version
# Get revision
Rails.app.revision
@shotgundebugging
shotgundebugging / test_induced_design_damage.rb
Created October 21, 2024 19:04 — forked from dhh/test_induced_design_damage.rb
This is an extraction from Jim Weirich's "Decoupling from Rails" talk, which explained how to apply the hexagonal design pattern to make every layer of your application easily unit testable (without touching the database etc). It only seeks to extract a single method, the EmployeesController#create method, to illustrate the design damage that's …
# Original Rails controller and action
class EmployeesController < ApplicationController
def create
@employee = Employee.new(employee_params)
if @employee.save
redirect_to @employee, notice: "Employee #{@employee.name} created"
else
render :new
end

Vim Manipulation Cheat Sheet

Action

Key Result
v select
y copy (yank)
c change
d delete
#!/Users/aaron/.rubies/arm64/ruby-trunk/bin/ruby
# This is a demo language server for Ruby, written in Ruby. It just checks
# the syntax of Ruby programs when you save them.
#
# Configure this in Vim by adding the vim-lsp plugin, then doing this
# in your vimrc:
#
# au User lsp_setup
# \ lsp#register_server({
profiler = Thread.new do
while true
p Thread.main.backtrace
sleep 0.5
end
end
def slow_function
sleep 2
end
# actionpack/lib/action_controller/metal/request_forgery_protection.rb
# Sets the token value for the current session.
def form_authenticity_token(form_options: {})
  masked_authenticity_token(session, form_options: form_options)
end
# Creates a masked version of the authenticity token that varies
# on each request. The masking is used to mitigate SSL attacks
# like BREACH.
@shotgundebugging
shotgundebugging / csrf_helper.rb
Created January 5, 2024 12:07 — forked from mctaylorpants/csrf_helper.rb
CSRF protection in Rails - #csrf_meta_tags
# actionview/lib/action_view/helpers/csrf_helper.rb
def csrf_meta_tags
if defined?(protect_against_forgery?) && protect_against_forgery?
[
tag("meta", name: "csrf-param", content: request_forgery_protection_token),
tag("meta", name: "csrf-token", content: form_authenticity_token)
].join("\n").html_safe
end
end