Skip to content

Instantly share code, notes, and snippets.

View BarnabeD's full-sized avatar

Barnabé BarnabeD

View GitHub Profile
@BarnabeD
BarnabeD / convert_to_webp.rb
Created October 4, 2024 19:46 — forked from julianrubisch/convert_to_webp.rb
Ruby Oneliners to convert images to webp and generate thumbnails
require 'fileutils'
# Loop through all .jpg and .png files in the current directory
Dir.glob("{*.jpg,*.png}").each do |img|
# Construct the output filename with .webp extension
output_filename = "#{File.basename(img, File.extname(img))}.webp"
# Execute ffmpeg command to convert the image
system("ffmpeg -i '#{img}' '#{output_filename}'")
end
@BarnabeD
BarnabeD / crud_concern_rails.rb
Created September 28, 2024 05:41 — forked from VishalTaj/crud_concern_rails.rb
CRUD Concern for Rails Controllers
module CrudConcern
extend ActiveSupport::Concern
# Rails version < 5
##################################################################
# This module take cares the CRUD controller methods #
# #
# Note: add skip_before_action if you want to ignore any of the #
# above action to be loaded from module #
##################################################################
class BaseClient
class APINotFound < StandardError; end
attr_reader :auth_strategy
def initialize(auth_strategy: :headers, headers: {})
@auth_strategy = auth_strategy
@headers = headers
end
@BarnabeD
BarnabeD / includes.rb
Created March 21, 2024 15:48 — forked from abhionlyone/includes.rb
Rails includes for nested active-record associations
# https://stackoverflow.com/questions/24397640/rails-nested-includes-on-active-records
# I believe the following should work for you.
Event.includes(users: :profile)
# If you want to include an association (we'll call it C) of an already included association (we'll call it B), you'd use the syntax above. However, if you'd like to include D as well, which is also an association of B, that's when you'd use the array as given in the example in the Rails Guide.
A.includes(bees: [:cees, :dees])
# You could continue to nest includes like that (if you actually need to). Say that A is also associated with Z, and that C is associated to E and F.
@BarnabeD
BarnabeD / move_deployed_linear_issues.rb
Created November 24, 2022 07:02 — forked from asterite/move_deployed_linear_issues.rb
A Ruby script that moves Linear issues to staging/production columns
# Make sure to configure this script!
# 1. Change `TEAM_LINEAR` properties below to match your Linear team
# 2. Optionally add more teams
# 3. Change the value of `DEPLOYED_TO_STAGING_GIT_TAG` to the tag/branch you use for deploys to staging
# 4. Change the value of `DEPLOYED_TO_PRODUCTION_GIT_TAG` to the tag/branch you use for deploys to production
#
# Usage:
# LINEAR_API_KEY=... GITHUB_API_KEY=... ruby move_deployed_linear_issues.rb
#
# Adding new teams (change "LinearTeam" to your team name):
heroku pg:info -a your_app
@BarnabeD
BarnabeD / devise.fr.yml
Created April 21, 2021 07:50 — forked from tadatoshi/devise.fr.yml
I18n French translation for Devise (http://github.com/plataformatec/devise)
#########################################################################################################
# I18n French translation for Devise (http://github.com/plataformatec/devise)
# I18n traduction française pour Devise
#########################################################################################################
fr:
errors:
messages:
not_found: "n'a pas été trouvé(e)"
already_confirmed: "a déjà été confirmé(e)"
@BarnabeD
BarnabeD / gist:1a73397554fc09b208cce98af75e649c
Created February 26, 2021 09:13 — forked from lbspen/gist:5674563
Select date and time for capybara-rspec from rails forms
def select_date(date, options = {})
field = options[:from]
base_id = find(:xpath, ".//label[contains(.,'#{field}')]")[:for]
year, month, day = date.split(',')
select year, :from => "#{base_id}_1i"
select month, :from => "#{base_id}_2i"
select day, :from => "#{base_id}_3i"
end
def select_time(hour, minute, options = {})