Skip to content

Instantly share code, notes, and snippets.

View fgm's full-sized avatar

Frédéric G. MARAND fgm

View GitHub Profile
// Insert doc:
sections = [
{
slug:"introduction",
title:"Introduction",
videos:[
{"k": "v0"},
{"k": "v1"},
{"_id": ObjectId('abcdefghijkl')}
]
@fgm
fgm / isdebugging.go
Last active February 3, 2022 10:31
Detect whether a Go process is running from Delve debugger
package isdebugging
import (
"os"
"github.com/mitchellh/go-ps"
)
// IsDebugging will return true if the process was launched from Delve or the
// gopls language server debugger.
@fgm
fgm / CheckedResult.php
Last active January 29, 2021 10:52
Finding vendor-dir from Drupal using Composer
<?php
declare(strict_types=1);
namespace Drupal\upgrade_status;
/**
* CheckedResult provides a format to return both a result and an error.
*
* When the error is not NULL, the result is to be ignored
*/
@fgm
fgm / HostsReferencedInPage.js
Created December 20, 2019 12:12
List the hosts referenced on a HTML page (href, src), by decreasing occurrence count
/**
* List the hosts referenced on a HTML page.
*
* Licence: MIT.
*/
a = {};
document.querySelectorAll("a[href],[src]").forEach((v, k) => {
const raw = v.getAttribute("href") || v.getAttribute("src");
if (raw[0] !== "h") {
@fgm
fgm / TenMostRepeatedLinksOnPage.js
Created November 29, 2019 11:10
List of the 10 most repeated links on a HTML page
function duplicateLinks(document) {
const elements = Array.from(document.body.getElementsByTagName('a'));
const linkElements = elements.filter((node, index) => {
const href = node.getAttribute('href');
const isRemote = href && href.match(/^http/);
if (isRemote) {
return true;
}
});
@fgm
fgm / Check fonts on a page
Created November 28, 2019 14:52
Build a list of the font families and weights on a web page, with the number of elements using them
const nodes = document.body.getElementsByTagName('*');
const styles = {};
for (const node of nodes) {
const s = getComputedStyle(node);
if (!styles[s.fontFamily]) {
styles[s.fontFamily] = {};
}
if (!styles[s.fontFamily][s.fontWeight]) {
@fgm
fgm / List services available in Meteor app
Last active December 21, 2018 10:27
List the services available from all Atmosphere packages bundles in the current Meteor app
console.log(Object.keys(Package).sort().map(x => ({ [x]: Object.keys(Package[x]).sort(), })))
/*
Main use case: finding the name of the actual services available when you decide to adopt a
dependency injection pattern, especially with TypeScript, and import every needed package
instead of relying on the global availability provided by the Meteor runtime for /some/ of them.
*/
@fgm
fgm / KernelCommands.php
Created December 19, 2017 14:34
Dump Drupal listeners, including subscribers
<?php
// Place in (module)/src/Commands
namespace Drupal\rdcm\Commands;
use Drush\Commands\DrushCommands;
use Robo\Common\OutputAwareTrait;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Yaml\Yaml;
@fgm
fgm / # php70 - 2016-10-28_14-44-32.txt
Created October 28, 2016 13:48
php70 (homebrew/php/php70) on macOS 10.12.1 - Homebrew build logs
Homebrew build logs for homebrew/php/php70 on macOS 10.12.1
Build date: 2016-10-28 14:44:32
@fgm
fgm / # php70 - 2016-10-28_14-44-32.txt
Created October 28, 2016 13:48
php70 (homebrew/php/php70) on macOS 10.12.1 - Homebrew build logs
Homebrew build logs for homebrew/php/php70 on macOS 10.12.1
Build date: 2016-10-28 14:44:32