Skip to content

Instantly share code, notes, and snippets.

Avatar
👋

Nicolas Hoizey nhoizey

👋
View GitHub Profile
@nhoizey
nhoizey / README.md
Last active Oct 28, 2021
Example data for searching multiple dimensions in Algolia
View README.md
@nhoizey
nhoizey / flickr-remove-faves-bookmarklet.js
Last active Oct 3, 2020
Remove faves from gallery pages
View flickr-remove-faves-bookmarklet.js
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
Compute faves/views ratio on Flickr stats pages
View flickr-faves-views-ratio-bookmarklet.js
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 Mar 11, 2020
Node.js script to move Markdown files from previous Jekyll to new Eleventy setup
View markdown-from-jekyll-to-eleventy.js
#!/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 Mar 11, 2020
Node.js script to migrate comments from Jekyll to Eleventy
View jekyll-comments-to-eleventy-data-file.js
#!/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
Get screen density and viewport width, useful for responsive web design
View browsing-contexts.js
// 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 Jul 4, 2018
Extracts the url of the largest image from a `srcset-w`
View extract-largest-image.rb
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 Mar 8, 2018
Get screen density and viewport width, useful for Analytics
View responsive-context.js
// 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')
View macOS settings.md

Chrome

Disable touch history back/forward

defaults write com.google.Chrome AppleEnableSwipeNavigateWithScrolls -bool FALSE
@nhoizey
nhoizey / README.md
Created Sep 23, 2016
Restore a Firefox session backed up with to Save My Tabs
View README.md

Save My Tabs is a great Firefox extension, because Firefox is great, but crashes a lot (at least mine, with hundreds of tabs).

Unfortunately, Save My Tabs doesn't have any restoration function, so you can copy/paste all URLs yourself, or try this script.

This simple Shell script for Mac OS X will launch Firefox with all URLs present in the backup file you pass as parameter:

./restore-savemytabs.sh opentabs--20160913-1900.txt