Skip to content

Instantly share code, notes, and snippets.

@shotgundebugging
shotgundebugging / rails.lua
Created November 20, 2024 21:12
Rails neovim config
vim.cmd("set expandtab")
vim.cmd("set tabstop=2")
vim.cmd("set softtabstop=2")
vim.cmd("set shiftwidth=2")
vim.g.mapleader = " "
vim.opt.swapfile = false
-- Navigate vim panes better
vim.keymap.set('n', '<c-k>', ':wincmd k<CR>')
@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
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
@shotgundebugging
shotgundebugging / alert.js
Created October 16, 2023 18:35 — forked from tomnomnom/alert.js
Ways to alert(document.domain)
// How many ways can you alert(document.domain)?
// Comment with more ways and I'll add them :)
// I already know about the JSFuck way, but it's too long to add (:
// Direct invocation
alert(document.domain);
(alert)(document.domain);
al\u0065rt(document.domain);
al\u{65}rt(document.domain);
window['alert'](document.domain);
{
"mode": "patterns",
"proxySettings": [
{
"address": "127.0.0.1",
"port": 8080,
"username": "",
"password": "",
"type": 1,
"title": "127.0.0.1:8080",