This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyJob < ActiveJob::Base | |
queue_as :urgent | |
rescue_from(NoResultsError) do | |
retry_job wait: 5.minutes, queue: :default | |
end | |
def perform(*args) | |
MyService.call(*args) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from_cte_sql = ::Namespace::From.where_clause | |
# .. | |
from_table = Arel::Table.new(:from_lane) | |
to_table = Arel::Table.new(:to_lane) | |
rates_table = Arel::Table.new(:rates) | |
rates_table | |
.join(from_table).on(rates_table[:from_id].eq(from_table[:id])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ brew install openssl readline | |
$ CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl` --with-readline-dir=`brew --prefix readline`" rbenv install 2.0.0-p353 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_rollbarConfig = { | |
accessToken: 'your token', | |
captureUncaught: true, | |
payload: { | |
environment: 'production', | |
}, | |
checkIgnore: function(isUncaught, args, payload) { | |
if (isUncaught && args[0] && args[0].indexOf('Script error') === 0) { | |
// ignore | |
return true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pg_restore --clean --no-acl --no-owner -d <database> -U <user> <filename.dump> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Help nginx+passenger serve static index pages | |
# Site specific config | |
server { | |
listen 80; | |
server_name domain.com; | |
index index.html; | |
access_log logs/appname.access.log; | |
error_log logs/appname.error.log; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I was encountering this exception | |
# Net::SMTPServerBusy: 401 4.1.7 Bad sender address syntax | |
# First I searched to see if there's any documentation around this issue, | |
# didn't find anything, so I wrote this snippet to find those invalid characters | |
require 'mail' | |
Mail.defaults do | |
delivery_method :smtp, { | |
:port => 25, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
Unobtrusive JavaScript solution for polling in a Rails application | |
Introduction: | |
Add a polling-placeholder wrapper div to any partial and add a data attribute | |
named poll that should be equal to "true" until you want to stop polling. | |
The default polling frequency will be used unless you provide an "interval" data | |
attribute which should be the number of milliseconds to use for the interval. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# new method | |
def exists?(item) | |
basket_items.exists?(source_id: item.id) | |
end | |
# old method | |
def exists_two?(item) | |
basket_items.select { |curr_item| curr_item.source_id == item.id }.any? | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
require 'set' | |
ranges = [ "a".."z", "A".."Z", 0..9 ] | |
n = ARGV[0].to_i || 100 | |
Benchmark.bm do |x| | |
x.report "array" do | |
n.times do | |
array = [] |