Skip to content

Instantly share code, notes, and snippets.

View ffoodd's full-sized avatar
🎯
Focusing

Gaël Poupard ffoodd

🎯
Focusing
View GitHub Profile
@mayank99
mayank99 / inline-workers.js
Last active March 14, 2024 13:06
Create a web worker in the same file where it's used
function createWorker(fn) {
const url = URL.createObjectURL(
new Blob([`\
onmessage = ({ data }) => {
const fn = ${fn.toString()};
const result = fn(...JSON.parse(data));
self.postMessage(result);
};
`])
);
@captainbrosset
captainbrosset / dom-mutation-logger.js
Last active November 14, 2022 13:03
Useful DevTools snippets
function logMutation(mutation) {
console.log(mutation);
}
const mutationObserver = new MutationObserver((mutations) => {
for (const mutation of mutations) {
// Build a reason object that will let the user know what exactly happened
let details = null;
if (mutation.type === "attributes") {
details = {
function invert() {
// grab the favicon
const icon = document.querySelector('link[rel*="icon"]');
if (!icon) return;
// make a canvas
const canvas = document.createElement('canvas');
canvas.width = 128;
canvas.height = 128;
document.body.append(canvas);
const ctx = canvas.getContext('2d');
@daviddarnes
daviddarnes / index.njk
Created June 1, 2019 08:02
Eleventy blog from API
<h1>API post list</h1>
<ul>
{% for post in posts %}
<li>
<a href="/posts/{{ post.id }}/">{{ post.title }}</a>
</li>
{% endfor %}
</ul>
@DavidKuennen
DavidKuennen / minimal-analytics-snippet.js
Last active March 28, 2024 01:45
Minimal Analytics Snippet
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
@anybodesign
anybodesign / gist:3954ae559522aa5e41696a66198f0a8e
Last active July 6, 2018 06:23
WordPress Gutenberg Color Palette
// Define your own color palette
add_theme_support( 'editor-color-palette',
array(
'name' => __( 'very dark gray', 'textdomain' ),
'slug' => 'very-dark-gray',
'color' => '#4a4a4a',
),
array(
'name' => __( 'very light gray', 'textdomain' ),
@enwin
enwin / sticky-focus.js
Last active May 17, 2022 13:11
Detect and change the scroll position when a focused element is under a sticky element
// sticky element
var stickyHeader = document.querySelector( '.intro-banner' );
function handleFocus( e ){
// don't try to change the scroll if the focused element is in the sticky element
if( stickyHeader.contains( e.target )){
return;
}
// quick & dirty client height on each focus
@7studio
7studio / POST.md
Created June 2, 2018 16:51
Améliorer le choix des dispositions dans un contenu flexible ACF

Améliorer le choix des dispositions dans un contenu flexible ACF

ACF Flexible Content Enhancer

Je pense que tout est parti d'un screenshot que j'ai vu passer sur le slack WordPress-fr et où je me suis dit que ça serait génial d'avoir la même chose pour nos contributeurs 😍

Au boulot, nous adorons les contenus flexibles ACF mais il faut bien se l'avouer, la popin pour choisir les dispositions n'est pas très "sexy" pour l'utilisateur final.

Je pensais que cela serait assez simple car comme nous le savons tous, ACF est très extensible et bien codé, sauf qu'il a fallu réfléchir un peu plus que prévu 😅 ACF ne propose pas encore la possibilité d'ajouter une option à une disposition d'un contenu flexible. Pour les curieux, ça se passe ici : plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-flexible-content.php#L564-648 et vraiment aucun hook dans les parages… De toute façon, en y réfléch

function fs_add_dropdown_labels() {
?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
$('.facetwp-dropdown').each(function() {
var facet_name = $(this).parent().attr('data-name');
var facet_label = FWP.settings.labels[facet_name];
$(this).attr('id', facet_name);
@stereokai
stereokai / index.css
Created June 18, 2017 11:03
Trigonometry in CSS
//----------------------------------*\
// TRIGONOMETRY FUNCTIONS
//----------------------------------*/
// # Trigonometry in CSS
//
// - Through Taylor/Maclaurin polynomial representation: http://people.math.sc.edu/girardi/m142/handouts/10sTaylorPolySeries.pdf
// - Useful if you don't want to use JS.
// - With CSS Variables.
// - `calc()` can't do power (x ^ y) so I used multiplication instead.