Skip to content

Instantly share code, notes, and snippets.

View adipasquale's full-sized avatar

Adrien Di Pasquale adipasquale

View GitHub Profile
@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:

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
@adipasquale
adipasquale / revenus disponibles france metropolitaine - deciles.ipynb
Created December 1, 2018 15:44
iPython Notebook revenus disponibles France Métropolitaine - deciles
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@adipasquale
adipasquale / facebook_download_photos.pl
Created March 27, 2012 16:14
perl script to download photos from facebook. input file should be the source copied from your browser. then write the output of the script in a file and execute it
#!/usr/bin/perl;
@ARGV = ("temp_fb_profile.html");
while (<>) {
while (/(http[a-z\-\.0-9:\/]*\w*)_a.jpg/g) {
print "wget $1_n.jpg\n";
}
}
@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

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: