Skip to content

Instantly share code, notes, and snippets.

View fgm's full-sized avatar

Frédéric G. MARAND fgm

View GitHub Profile
@fgm
fgm / instrument.drush.inc
Created August 4, 2016 12:01
Drush time and memory measurement
<?php
/**
* @file
* A simple Drush plugin to report on time spent and memory usage
* without all the noise from the Drush "-d" option. Results look like:
$ drush cc all
'all' cache was cleared. [success]
Duration: 3.39 seconds
Memory:
// 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
*/
#!/bin/bash
# Build a commit frequency list.
ROW_LIMIT=20
git log --name-status $* | \
grep -E '^[A-Z]\s+' | \
cut -c3-500 | \
sort | \
uniq -c | \
@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 / tinytest.api.js
Last active July 25, 2018 07:48 — forked from stbaer/tinytest.api
Meteor tinytest api
// From 1.1.03 packages/tinytest/tinytest.js
test._stringEqual(actual, expected, message) // Source comment: EXPERIMENTAL nicer (multiline) string display in runner
test.equal(actual, expected, message, not) // Source comment: "XXX eliminate 'message' and 'not' arguments"
/* Call this to fail the test with an exception. Use this to record exceptions
* that occur inside asynchronous callbacks in tests. It should only be used
* with asynchronous tests, and if you call this function, you should make
* sure that
* (1) the test doesn't call its callback (onComplete function);
* (2) the test function doesn't directly raise an exception.
*/