Skip to content

Instantly share code, notes, and snippets.

View adipasquale's full-sized avatar

Adrien Di Pasquale adipasquale

View GitHub Profile
@adipasquale
adipasquale / html2haml.sh
Created December 21, 2022 15:00
VSCode command to convert html.erb to haml
# scripts/html2haml.sh
ls $1 | sed 'p;s/.erb$/.haml/' | xargs -n2 bundle exec html2haml --ruby19-attributes -E utf-8:utf-8
ls $1 | sed 's/.erb$/.haml/' | xargs sed -i '' 's/é/é/g'
ls $1 | sed 's/.erb$/.haml/' | xargs sed -i '' 's/è/è/g'
ls $1 | sed 's/.erb$/.haml/' | xargs sed -i '' 's/ /\ /g'
ls $1 | sed 's/.erb$/.haml/' | xargs sed -i '' 's/«/«/g'
ls $1 | sed 's/.erb$/.haml/' | xargs sed -i '' 's/»/»/g'
ls $1 | sed 's/.erb$/.haml/' | xargs sed -i '' 's/à/à/g'
ls $1 | sed 's/.erb$/.haml/' | xargs sed -i '' 's/’/ʼ/g'
@adipasquale
adipasquale / active_storage_attachment_rotation.rb
Created December 15, 2022 14:06
Monkey patch Active Storage Attachment to add a rotate method - with ImageProcessing and VIPS
# config/initializers/active_storage_attachment_rotation.rb
# frozen_string_literal: true
module Rotation
def rotate!(degrees: 90)
rotated_tempfile = nil
blob.open do |original_tempfile|
rotated_tempfile = ImageProcessing::Vips.source(original_tempfile).rotate(degrees).call
end
@adipasquale
adipasquale / fix-orientation.md
Last active December 15, 2022 10:43
How to fix Rails Active Storage thumbnails orientation

If you use Active Storage variants to generate thumbs and your thumbnails are sometimes misoriented, you may have EXIF metadata problems For example:

  • the original image can have an EXIF metadata specifying a 90° rotation
  • when resizing by default libvips will apply this rotation to the pixels
  • HOWEVER it will also preserve the EXIF metadata including this rotation info
  • so the thumbnail is doubly rotated

a solution is to remove all EXIF metadata from the generated thumbs by using saver: { strip: true } in the config:

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
code nom dans_nom
01 Ain dans lʼAin
02 Aisne dans lʼAisne
03 Allier dans lʼAllier
04 Alpes de Haute Provence dans les Alpes de Haute Provence
05 Hautes Alpes dans les Hautes Alpes
06 Alpes Maritimes dans les Alpes Maritimes
07 Ardèche en Ardèche
08 Ardennes dans les Ardennes
09 Ariège dans lʼAriège
This file has been truncated, but you can view the full file.
{"ok": true, "database": "collectif-objets", "query_name": null, "rows": [{"code_insee": "01001", "nom": "L'Abergement-Cl\u00e9menciat", "objets_count": 2, "latitude": 4.92007112503, "longitude": 46.151676178}, {"code_insee": "01004", "nom": "Amb\u00e9rieu-en-Bugey", "objets_count": 2, "latitude": 5.35882997513, "longitude": 45.9578018188}, {"code_insee": "01005", "nom": "Amb\u00e9rieux-en-Dombes", "objets_count": 4, "latitude": 4.9028423, "longitude": 45.9957877}, {"code_insee": "01007", "nom": "Amberieu", "objets_count": 22, "latitude": 5.36072, "longitude": 46.00739}, {"code_insee": "01010", "nom": "Anglefort", "objets_count": 5, "latitude": 5.80891990662, "longitude": 45.9136009216}, {"code_insee": "01012", "nom": "Aranc", "objets_count": 4, "latitude": 5.5087919, "longitude": 46.0013273}, {"code_insee": "01013", "nom": "Arandas", "objets_count": 2, "latitude": 5.485944, "longitude": 45.89675}, {"code_insee": "01014", "nom": "Arbent", "objets_count": 23, "latitude": 5.680257, "longitude": 46.2945869}, {"c
@adipasquale
adipasquale / departements_francais.csv
Last active April 18, 2022 14:57
Liste des noms et numéros des départements français au format CSV
01 Ain
02 Aisne
03 Allier
04 Alpes de Haute Provence
05 Hautes Alpes
06 Alpes Maritimes
07 Ardèche
08 Ardennes
09 Ariège
10 Aube

Keybase proof

I hereby claim:

  • I am adipasquale on github.
  • I am adipasquale (https://keybase.io/adipasquale) on keybase.
  • I have a public key ASCJUSTkSF_UhgHe3imKTZYlUYtjqxeU-RMb_I-c_A-8bwo

To claim this, I am signing this object:

@adipasquale
adipasquale / rails-tests.yml
Last active March 5, 2021 16:10
GitHub Action for CI Rails Tests with a specific ruby version, minitest, Chrome Headless and PostgreSQL
# .github/workflows/rails-tests.yml
name: Rails Tests
on: [push]
jobs:
build:
runs-on: ubuntu-latest
env:
PGHOST: localhost
PGUSER: postgres
RAILS_ENV: test
@adipasquale
adipasquale / heroku.integration.js
Created March 7, 2019 15:41
Rocket.chat Heroku Deploys integration
class Script {
process_incoming_request({ request }) {
// console is a global helper to improve debug
// console.log(request.url.query);
const query = request.url.query;
return {
content: {
text: `${query.user} released in production ` +