Skip to content

Instantly share code, notes, and snippets.

View ndemengel's full-sized avatar

Nicolas Grisey Demengel ndemengel

View GitHub Profile
@ndemengel
ndemengel / mock-api-request.ts
Last active July 29, 2024 15:32
Nuxt UI Tests with Playwright @malt: the mock server (as a Playwright fixture)
// noinspection JSVoidFunctionReturnValueUsed
import * as http from 'http';
import {IncomingMessage, ServerResponse} from 'http';
import isEqual from 'lodash';
import type {TestFixture} from 'playwright/test';
import {test as base} from 'playwright/test';
import type {Expectation, ExpectationMatch, MatchingExpectation, MockApiRequestFixturesOptions, MockApiRequestFn} from '../types';
const {isEqual: isDeepEqual} = isEqual;
@ndemengel
ndemengel / reverse-proxy.mjs
Created July 29, 2024 15:26
Nuxt UI Tests with Playwright @malt: the reverse proxy
/* eslint-disable no-console */
// Note: a first version of if was using Typescript and was launched using ts-node, but it took 1-2 additional seconds
// to start, which is noticeable when we want tests to start as fast as possible. So it has been reverted to JS.
import {execSync} from 'child_process';
import * as http from 'http';
const COMMON_BACKEND_ROUTES = ['/api', /* ... */];
function startProxy(proxyPort, appPortForTests, backendPortForTests, apiPrefixes) {
const requestPrefixes = apiPrefixes.split(',');
@ndemengel
ndemengel / buildLanguageBattleChart.js
Created January 16, 2023 14:11
Example of buidling a bar + line chart using Chart.js
function buildLanguageBattleChart({battleData, containerEl, oldLanguage, newLanguage}) {
const dates = battleData.map(d => d.date);
const newLanguageFiles = battleData.map(d => d.newLanguageFiles);
const oldLanguageFiles = battleData.map(d => d.oldLanguageFiles);
const filesRatios = battleData.map(d => d.filesRatio * 100);
const canvas = document.createElement('canvas');
canvas.style = 'width: 600px; height: 400px';
containerEl.appendChild(canvas);
@ndemengel
ndemengel / buildSimpleLineChart.js
Created January 16, 2023 14:09
Example of building a line chart using Chart.js
function buildSimpleLineChart({data, containerEl, title, xField, yField, xTitle, yTitle}) {
const xs = data.map(d => d[xField]);
const ys = data.map(d => d[yField]);
const canvas = document.createElement('canvas');
canvas.style = 'width: 600px; height: 400px';
containerEl.appendChild(canvas);
return new Chart(canvas, {
data: {
@ndemengel
ndemengel / who-knows-about.sh
Created January 16, 2023 10:10
Simple script outputting who likely has the most knowledge about an area of your code base
#!/bin/bash
##
# Outputs the top 10 committers on the provided area, for the period provided,
# based on the number of commits, in the form of 4 columns:
# Lines added, Lines deleted, Number of commits, Author
# (This allows for easily re-sorting the output by piping it into `sort -nr -k COLUMN_NUMBER`)
#
# Tip: replace tabs with commas everywhere below to output valid CSV content.
##
@ndemengel
ndemengel / CheckFreelancerLibsDependenciesTest.kt
Last active January 17, 2021 15:57
Enforcing dependency rules between Maven modules using JUnit
package com.malt.architecture.libfreelancer
import com.malt.architecture.shouldNotDependOnModulesOfOtherGroups
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
@Tag("lib-freelancer")
internal class CheckFreelancerLibsDependenciesTest {
@Test
@ndemengel
ndemengel / CommandSpecification.kt
Created April 26, 2020 15:31
Command queue: specification options
/**
* Specifies a command to be executed with some arguments.
*
* For a better development experience, this class must be extended to ensure each command has
* an specification type, and must define the queue name via:
* - either a static field (for Java classes) named "COMMAND_NAME",
* - or a companion object's property (for Kotlin classes) named "COMMAND_NAME".
*/
abstract class CommandSpecification(
@ndemengel
ndemengel / ExecutionPolicy.kt
Created April 26, 2020 15:27
Command queue: execution policy
data class ExecutionPolicy(
/** How many processes (coroutines, really) to run in parallel. */
val concurrency: Int,
/**
* How much time to wait before processing a command specification/scheduled task.
*
* Consequently, that time is the window during which tasks are subject to deduplication.
*
@ndemengel
ndemengel / CommandSequence.kt
Created April 26, 2020 13:30
Command queue: scheduling a sequence of tasks
commandScheduler.scheduleSequence(
CommandSpec1(argA, argB),
CommandSpec2(),
CommandSpec3(argC)
)
@ndemengel
ndemengel / CommandQueue.kt
Last active April 26, 2020 13:15
Command queue: core logic
class CommandQueue(...) {
// ...
override fun schedule(command: CommandSpecification) {
// add task to queue, log details, emit metrics
schedule(ScheduledTask(
command,
queueName,
clock,
// this is the important part for deduplication to work