Skip to content

Instantly share code, notes, and snippets.

@latortuga
latortuga / delete_failed_jobs.rb
Created September 15, 2022 18:37 — forked from nisanthchunduru/delete_failed_jobs.rb
Selectively remove/retry failed jobs in Resque 1.x
def delete_failed_job_if
redis = Resque.redis
(0...Resque::Failure.count).each do |i|
string = redis.lindex(:failed, i)
break if string.nil?
job = Resque.decode(string)
should_delete_job = yield job
next unless should_delete_job
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x0]
goroutine 10 [running]:
runtime.gopanic(0x5a7020, 0xc8200101b0)
/usr/local/go/src/runtime/panic.go:461 +0x3e6
runtime.panicmem()
/usr/local/go/src/runtime/panic.go:42 +0x49
runtime.sigpanic()
/usr/local/go/src/runtime/sigpanic_unix.go:24 +0x2ba
@latortuga
latortuga / paniclog.log
Last active October 11, 2015 18:36
vagrant-panic
drew:~/projects/prj$ zeus start
Starting Zeus server v0.15.5.rc1
[ready] [crashed] [running] [connecting] [waiting]
boot
└── default_bundle
├── development_environment
│  └── prerake
└── test_environment
└── test_helper
def method_name
state.thing_that_throws
rescue
state.error
ensure
state.thing
state
end
@latortuga
latortuga / 1_terrible.erb
Last active September 9, 2015 22:13
CSV Renderer/Helper
<%= CSV.generate do |csv| %>
<% csv << ["All Orders"] %>
<% csv << [] %>
<% total = 0.0 %>
<% orders.each do |order| %>
<% csv << [order.id, order.subtotal, order.tax, order.shipping, order.total] %>
<% total += order.total %>
<% end %>
<% csv << [] %>
<% csv << ["Total", total] %>
@latortuga
latortuga / 1minitest.md
Last active August 29, 2015 14:27
ARGH-V

Run tests via Minitest how it's supposed to work

# manual way
Minitest.run(args)

# magic way
require 'minitest/autorun'
# or
Minitest.autorun
# Imagine we have a form that only sets user name for verified users
class Form
include ActiveModel::Model
attr_accessor :name
def save(user)
user.name = name if user.verified?
end
end
@latortuga
latortuga / gist:ca7ed1d87593640f0d8f
Created April 20, 2015 18:48
Rails #18952 reproduction
require 'active_record'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Schema.define do
create_table :somethings, force: true do |t|
t.integer :age
t.integer :count
end
end
class Something < ActiveRecord::Base
@latortuga
latortuga / poodr.rb
Created February 17, 2015 21:10
ecoding5
$ ruby poodr.rb
poodr.rb:20:in `prepare_trip': undefined method `each' for nil:NilClass (NoMethodError)
from poodr.rb:6:in `block in prepare'
from poodr.rb:5:in `each'
from poodr.rb:5:in `prepare'
from poodr.rb:54:in `<main>'

Notes

This is the latest version of an email which I send periodically, offering customers the opportunity to pre-pay for SaaS in return for a discount. The benefits to the SaaS company are better cash flow and reduced churn rate. The benefits to the customer are, well, in the email. This genre of email has produced hundreds of thousands of dollars in pre-pays for some companies I work with, and it rarely requires any more work than this example.

I've put $79 is as a placeholder for the cost of the user's plan. We calculate that for each account, naturally, along with the billing contact's name.

Subject: Save $79 on Appointment Reminder (and get a tax write-off) Formatting: 100% plain text. Gmail automatically links up the central link. From: Patrick McKenzie (Appointment Reminder) patrick@appointmentreminder.org