Skip to content

Instantly share code, notes, and snippets.

View nhoizey's full-sized avatar
👋

Nicolas Hoizey nhoizey

👋
View GitHub Profile
/* ***********************************************
Styles for Mastodon
Adapted from different sources
- https://write.as/panais/styles-pour-mastodon-avec-stylus
- https://mastodon.social/@matuzo/109284559864791077
- https://mastodon.social/@matuzo/109284628517006156
- https://gist.github.com/justmarkup/e4f6d52bef604e170815aaf44f459fbc
*********************************************** */
/* Private messages */

Heaviest images on French government sites (.gouv.fr)

Google BigQuery request with HTTP Archive data

Here's the how to.

SELECT
  url,
 ROUND(respBodySize/1024) AS imgWeight,
@nhoizey
nhoizey / README.md
Last active October 28, 2021 09:27
Example data for searching multiple dimensions in Algolia
@nhoizey
nhoizey / flickr-remove-faves-bookmarklet.js
Last active October 3, 2020 21:00
Remove faves from gallery pages
javascript:(function(){((document)=>{document.querySelectorAll('.engagement-item.fave.faved').forEach(row=>{row.closest('.photo-list-gallery-photo-view').remove();});})(window.document);})();
@nhoizey
nhoizey / flickr-faves-views-ratio-bookmarklet.js
Last active May 29, 2020 10:33
Compute faves/views ratio on Flickr stats pages
javascript:(function()%7B((document)%20%3D%3E%20%7Bdocument.querySelectorAll('.row').forEach(row%20%3D%3E%20%7Blet%20views%20%3D%20parseInt(row.querySelector('td%3Anth-child(3)').innerText.replace('%2C'%2C%20'')%2C%2010)%3Blet%20faves%20%3D%20parseInt(row.querySelector('td%3Anth-child(4)').innerText.replace('%2C'%2C%20'')%2C%2010)%3Blet%20ratio%20%3D%20Math.round(10000%20*%20faves%20%2F%20views)%20%2F%20100%3Brow.querySelector('td%3Anth-child(4)').innerText%20%3D%20row.querySelector('td%3Anth-child(4)').innerText%20%2B%20'%20('%20%2B%20ratio%20%2B%20'%20%25)'%3B%7D)%3B%7D)(window.document)%7D)()
@nhoizey
nhoizey / markdown-from-jekyll-to-eleventy.js
Created March 11, 2020 16:48
Node.js script to move Markdown files from previous Jekyll to new Eleventy setup
#!/usr/bin/env node
// Move Markdown files from previous Jekyll to new Eleventy setup
// Jekyll: 2018/06/15-users-do-change-font-size/2018-06-15-users-do-change-font-size.md
// Eleventy: 2018/06/15/users-do-change-font-size/index.md (with date added as YFM)
const fs = require('fs');
const path = require('path');
const insertLine = require('insert-line');
@nhoizey
nhoizey / jekyll-comments-to-eleventy-data-file.js
Created March 11, 2020 16:35
Node.js script to migrate comments from Jekyll to Eleventy
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const yfm = require('front-matter');
const rootDir = './src/_comments';
let comments = {};
@nhoizey
nhoizey / browsing-contexts.js
Last active May 28, 2021 15:31
Get screen density and viewport width, useful for responsive web design
// get device pixel ratio in dppx
// https://github.com/ryanve/res/blob/master/res.js
var screen_density =
typeof window == 'undefined'
? 0
: +window.devicePixelRatio ||
Math.sqrt(screen.deviceXDPI * screen.deviceYDPI) / 96 ||
0
// keep only 3 decimals: http://jsfiddle.net/AsRqx/
screen_density = +(Math.round(screen_density + 'e+3') + 'e-3')
@nhoizey
nhoizey / extract-largest-image.rb
Last active July 4, 2018 15:59
Extracts the url of the largest image from a `srcset-w`
url = srcset.scan(/([^, ][^ ]+)\s+([0-9]+)w/).map{ |url, size| { 'url' => url.strip, 'size' => size.to_i } }.reduce({ 'url' => '', 'size' => 0 }){ |current, new| current = new if new['size'] > current['size'] }['url']
@nhoizey
nhoizey / responsive-context.js
Created March 8, 2018 09:20
Get screen density and viewport width, useful for Analytics
// get device pixel ratio in dppx
// https://github.com/ryanve/res/blob/master/src/index.js
var screen_density =
typeof window == 'undefined'
? 0
: +window.devicePixelRatio ||
Math.sqrt(screen.deviceXDPI * screen.deviceYDPI) / 96 ||
0
// keep only 3 decimals: http://jsfiddle.net/AsRqx/
screen_density = +(Math.round(screen_density + 'e+3') + 'e-3')