I hereby claim:
- I am pingortle on github.
- I am pingortle (https://keybase.io/pingortle) on keybase.
- I have a public key ASDdzMBjB_KEboIXEmrJvAuon9g6lIZR3Z0KREwT5svJUAo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
| # Given #1: a list of ids in a specific order you want to preserve | |
| ordered_ids = (1..3).to_a.reverse | |
| #=> [3, 2, 1] | |
| indexed_ids = ordered_ids.each_with_index.to_h | |
| #=> {3=>0, 2=>1, 1=>2} | |
| # Given #2: a collection of items with the same ids as in the list above, but in no particular order | |
| # Example: `Model.where(…)` in rails | |
| Model = Struct.new(:id, :name) | |
| items = (1..3).map { |id| Model.new(id, "Item #{id}") } |
| module ActiveJobListeningToErrors | |
| extend ActiveSupport::Concern | |
| module ClassMethods | |
| def on_error(error_class) | |
| around_perform do |job, perform_block| | |
| perform_block.call | |
| rescue error_class => error | |
| yield job, error | |
| raise |
The behavior of enqueue.active_job changed slightly between Rails 5.2 and 6.0. In 5.2 the event doesn't fire if there's an error queuing the job. In 6.0 it always fires regardless of error.
Relevant rails code is…
One more interesting difference between 5.2 and 6.0 here is that 5.2 did not include timing information since it fires in an after_enqueue. In 6.0 it has moved to around_enqueue and passes the block to be instrumented.
| if Gem::Version.new("2.6") <= Gem::Version.new(RUBY_VERSION) | |
| def compose(*funcs) | |
| funcs.map(&:to_proc).reduce(:<<) | |
| end | |
| else | |
| def compose(*funcs) | |
| funcs.map(&:to_proc).reduce { |f, g| ->(*x) { f.call(g.call(*x)) } } | |
| end | |
| end |
| require "benchmark" | |
| require "test/unit/assertions" | |
| extend Test::Unit::Assertions | |
| text = <<END | |
| here's some | |
| text for | |
| you |
| #!/bin/sh -e | |
| # A simple script to keep a tidy ~/code directory organized by owner & then repo | |
| # When the script is done, just hit command-v to switch into the directory | |
| # (Github and Mac only. Sorry, openness!) | |
| # | |
| # Usage: | |
| # gloan <org>/<repo> | |
| # Or: | |
| # gloan <org> <repo> |
| #!/bin/bash | |
| set -e | |
| # Install brew | |
| /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
| brew update | |
| brew install rbenv |
| # navigate to the boot partition | |
| # set WPA_SSID and WPA_PSK | |
| touch ssh | |
| cat > wpa_supplicant.conf <<EOF | |
| ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev | |
| update_config=1 | |
| country=US |
| function Node(data, { left, right } = {}) { | |
| this.data = data | |
| this._left = left || this, | |
| this._right = right || this | |
| } | |
| Node.prototype = { | |
| left, | |
| right, | |
| insertLeft, |