Skip to content

Instantly share code, notes, and snippets.

View gist:0216f3c0cf2e11b4ec8b
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 Oct 11, 2015
vagrant-panic
View paniclog.log
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
View rescue.rb
def method_name
state.thing_that_throws
rescue
state.error
ensure
state.thing
state
end
@latortuga
latortuga / 1_terrible.erb
Last active Sep 9, 2015
CSV Renderer/Helper
View 1_terrible.erb
<%= 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] %>
View 1minitest.md

Run tests via Minitest how it's supposed to work

# manual way
Minitest.run(args)

# magic way
require 'minitest/autorun'
# or
Minitest.autorun
View form-v1.rb
# 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
View gist:ca7ed1d87593640f0d8f
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
View poodr.rb
$ 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>'
View annual-prepay.md

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

@latortuga
latortuga / 1.md
Last active Oct 29, 2016
rails-4-2-overview
View 1.md

What's new in Rails 4.2?

ActiveJob

Adapter layer on top of queueing systems like Resque and Delayed Job. Full adapter list: :backburner, :delayed_job, :qu, :que, :queue_classic, :resque, :sidekiq, :sneakers, :sucker_punch

ActiveJob::Base.queue_adapter = :inline # default queue adapter

# Declare a job: