Skip to content

Instantly share code, notes, and snippets.

@alaroia-cfa
alaroia-cfa / README.md
Created February 8, 2022 16:40
m1-debugging.md

Plan:

  • Make sure Ruby is not x86_64 Ruby but amd64 Ruby
@alaroia-cfa
alaroia-cfa / stack_trace.json
Created January 18, 2022 16:31
full stack trace
["/Users/asheesh/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/body_proxy.rb:18:in `respond_to?'", "/Users/asheesh/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/body_proxy.rb:18:in `respond_to_missing?'", "/Users/asheesh/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/body_proxy.rb:18:in `respond_to?'", "/Users/asheesh/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/body_proxy.rb:18:in `respond_to_missing?'", "/Users/asheesh/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/body_proxy.rb:18:in `respond_to?'", "/Users/asheesh/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/body_proxy.rb:18:in `respond_to_missing?'", "/Users/asheesh/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/body_proxy.rb:18:in `respond_to?'", "/Users/asheesh/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/body_proxy.rb:18:in `respond_to_missing?'", "/Users/asheesh/.rbenv/versions/2.6.5/l
@alaroia-cfa
alaroia-cfa / events.rb
Last active January 18, 2022 16:30
puma extra printouts
# look for puma/events.rb
# look for def unknown_error
# add these lines into the method
# i guess i could have done this with a monkey patch, oh well
puts "error.inspect=#{error.inspect}"
puts "error.full_message=#{error.full_message}"
puts "error.backtrace=#{error.backtrace}"
puts "error.cause&.full_message=#{error.cause&.full_message}"
@alaroia-cfa
alaroia-cfa / 0001-bold-nonsense.patch
Created January 18, 2022 16:23
Patch Ruby to ignore critical region issue when raising SystemStackError
From 14e13773a22ac3b57060c9300cf84f6f0c990674 Mon Sep 17 00:00:00 2001
From: Asheesh Laroia <alaroia@codeforamerica.org>
Date: Sat, 15 Jan 2022 14:43:06 -0500
Subject: [PATCH] bold nonsense
---
vm_insnhelper.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
@alaroia-cfa
alaroia-cfa / tracebacks.txt
Created January 15, 2022 19:54
tracebacks.txt
error.inspect=#<SystemStackError: stack level too deep>
error.full_message=Traceback (most recent call last):
1803: from /Users/asheesh/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/puma-5.5.2/lib/puma/thread_pool.rb:147:in `block in spawn_thread'
1802: from /Users/asheesh/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/puma-5.5.2/lib/puma/server.rb:447:in `process_client'
1801: from /Users/asheesh/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/puma-5.5.2/lib/puma/request.rb:76:in `handle_request'
1800: from /Users/asheesh/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/puma-5.5.2/lib/puma/thread_pool.rb:340:in `with_force_shutdown'
1799: from /Users/asheesh/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/puma-5.5.2/lib/puma/request.rb:77:in `block in handle_request'
1798: from /Users/asheesh/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/puma-5.5.2/lib/puma/configuration.rb:249:in `call'
1797: from /Users/asheesh/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/railties-6.1.4.1/lib/rails/engine.rb:539:in
@alaroia-cfa
alaroia-cfa / split_and_resend.rb
Created October 6, 2021 18:25
split_and_resend.rb
def chunk(s, max_size)
chunks = []
rest = s
while rest.size != 0
if rest.size <= max_size
chunks << rest
rest = ""
else
split_point = rest.first(max_size).rindex(" ")
@alaroia-cfa
alaroia-cfa / README.md
Last active March 4, 2021 19:34
2021-03-04-getyourrefund-aptible-data-access-for-data-science.md

A data science team member needs read access to our full Get Your Refund database. He's using the GetCalFresh EC2 machine for analysis. I set up an Aptible database endpoint which allows access to the replica, and I gave him the credentials.

Status

I've set this up for staging but not production yet. Once he confirms it works for staging, I'll set it up for production as well.

I'm grateful for feedback, especially before we enable this in production.

@alaroia-cfa
alaroia-cfa / 2021-03-02-null-bytes.md
Last active March 2, 2021 18:31
Null bytes info

A "null byte" is a character (like a letter) whose numeric value is zero. All characters (letters) have a numeric value. The numeric value of capital "A" is 65. There is one whose numeric value is zero.

Null bytes have a special meaning for software written in C. We depend on some software written in C, such as postgresql. Security vulnerabilities can arise when our code passes text data to software written in C and the C code treats it differently than we would. Rails has had security problems with this, such as Validation bypass for queries generated for PostgreSQL.

Tinfoil sends us data with null bytes to find out what happens. This causes exceptions that have disturbed Dimitri and others.

We implemented a general way to block data with null bytes as a Rails middleware, based on a blog post, Don't let the null bytes bite.

This was breaking our ability to receive email attachments, so I removed it. I ha

@alaroia-cfa
alaroia-cfa / READE.md
Last active February 24, 2021 23:33
Bad wifi and what to do about it

If your home wifi is bad, here's what I'd try.

Find out if connecting by wired fixes everything (this requires spending money on a USB Ethernet adapter & Ethernet cable). Try a speed test [1] [2] or Zoom call with someone once your laptop is connected by cables.

This is useful so that you know the problem isn't your home Internet service provider [3]. If it is the service provider, then the rest of this document doesn't apply to you.

If that works, then the problem has something to do with wifi. There are a few reasons home wifi can be bad. Historically, home wifi can be slowed down for everyone if there's one slow device on it. I don't know if that still applies, but it definitely used to.

Sometimes people buy "wifi repeaters," but those sadly have a tendency to cause problems instead of fix them. I stay away from them. If the problem is that there's too many people with wifi near you (too much background noise for your wifi to operate well), then adding a repeater can add more noise, which can make th

@alaroia-cfa
alaroia-cfa / log.txt
Created February 21, 2021 02:55
Sending emails before their attachments save
irb(main):001:0> OutgoingEmail.create!(to: "example@example.com", body: "hi", subject: "Hi subj", sent_at: DateTime.now, client: Client.find(1), attachment: Rack::Test::UploadedFile.new("spec/fixtures/attachments/test-pattern.png", "image/png"))
Client Load (0.7ms) SELECT "clients".* FROM "clients" WHERE "clients"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
(0.3ms) BEGIN
OutgoingEmail Create (1.0ms) INSERT INTO "outgoing_emails" ("body", "client_id", "created_at", "sent_at", "subject", "to", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["body", "hi"], ["client_id", 1], ["created_at", "2021-02-21 02:55:23.240130"], ["sent_at", "2021-02-21 02:55:23.133501"], ["subject", "Hi subj"], ["to", "example@example.com"], ["updated_at", "2021-02-21 02:55:23.240130"]]
Client Update (0.5ms) UPDATE "clients" SET "last_internal_or_outgoing_interaction_at" = $1, "updated_at" = $2 WHERE "clients"."id" = $3 [["last_internal_or_outgoing_interaction_at", "2021-02-21 02:55:23.243275"], ["updat