Skip to content

Instantly share code, notes, and snippets.

View jameslafa's full-sized avatar

James Lafa jameslafa

View GitHub Profile
jameslafa /
Last active December 8, 2020 08:07
Script to square pictures, add a white border and resize them to 1200px for instagram
for dir in */ ; do
# Check if there are images in the folder before moving forward
if [[ $(find $dir -maxdepth 1 -type f -name "*.jpg"| wc -l) -ge 1 ]]; then
# If there is already an instagram folder in this folder, I skip.
if [[ ! -d "$dir"instagram ]]; then
mkdir "$dir"instagram
for file in "$dir"*.jpg ; do

Keybase proof

I hereby claim:

  • I am jameslafa on github.
  • I am jameslafa ( on keybase.
  • I have a public key ASAWFkLVBvndTyh-TtPTyARV9zAKQI_CuebhX1xJkPJXnQo

To claim this, I am signing this object:

In case Redis is down, the job will be perform synchronously instead of crashing.

On your job, use perform_later_with_failover instead of perform_later.

Take this into account:

  1. You should find a way to monitor that Redis/Sidekiq is down and be alerted. You will be in a degraded mode if the task are executed synchronously and you should be aware of this as soon as possible
  2. You should use perform_later_with_failover only if you expect the execution time of the task to be fairly short (send email, slack notification, etc.) If you know the task requires time to be perform, it's not a good solution because your user's browser will be blocked.
acrobat africa alaska albert albino album
alcohol alex alpha amadeus amanda amazon
america analog animal antenna antonio apollo
april aroma artist aspirin athlete atlas
banana bandit banjo bikini bingo bonus
camera canada carbon casino catalog cinema
citizen cobra comet compact complex context
credit critic crystal culture david delta
dialog diploma doctor domino dragon drama
jameslafa / pre-commit
Last active January 5, 2022 14:11
Git pre-commit to avoid commiting breakpoints, secret files, etc.
#!/usr/bin/env ruby
# Place in your project .git/hooks/pre-commit
# Heavily inspired by, so thank you to him
############# CONFIGURATION
# The two sections of regular expressions below ("forbidden" and "warning")
# will trigger a commit failure, *if* they are found on an added or edited line.
jameslafa / matchers.rb
Created August 16, 2016 09:21
RSpec::Matchers have_same_attributes_as
RSpec::Matchers.define :have_same_attributes_as do |expected|
ignored_attributes = ['id', 'updated_at', 'created_at']
match do |actual|
actual.attributes.except(*ignored_attributes) == expected.attributes.except(*ignored_attributes)
chain :except do |*attributes|
ignored_attributes += {|a| a.to_s}
jameslafa / my_controller_spec.rb
Created July 17, 2016 10:50
Expect Job being enqueued with args
RSpec.describe MyController, type: :controller do
include ActiveJob::TestHelper
describe "..." do
it "enqueues the job with the right arguments" do
expect {
@bookmark = post :create, {:bookmark => valid_attributes}
}.to have_enqueued_job(SlackNotifierJob).with { |args|
expect(args).to eq(["new_bookmark", @bookmark])
jameslafa / debug.rake
Created July 11, 2016 12:58
Easily debug rake task
desc "switch rails logger to stdout"
task :verbose => [:environment] do
Rails.logger =
desc "switch rails logger log level to debug"
task :debug => [:environment, :verbose] do
Rails.logger.level = Logger::DEBUG
jameslafa / to_boolean.rb
Created April 26, 2016 14:34
Rails: convert anything to boolean
# config/initializers/to_boolean.rb
module ToBoolean
def to_bool
return true if ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(self)
return false
class NilClass; include ToBoolean; end
jameslafa / test_spec.rb
Created January 30, 2016 08:09
Include Money-rails Helper in the feature tests
context 'when changing the selected materials', :js => true, focus: true do
include MoneyRails::ActionViewExtension
it 'updates the offers' do
# bla bla