Skip to content

Instantly share code, notes, and snippets.

View ndemengel's full-sized avatar

Nicolas Grisey Demengel ndemengel

View GitHub Profile
@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
@ndemengel
ndemengel / MyServiceQueueConfiguration.kt
Last active April 26, 2020 11:42
Commanq queue: configuring a queue
const val MY_QUEUE_NAME: String = "myServiceQueue"
@Configuration
class MyServiceQueueConfiguration {
@Bean(MY_QUEUE_NAME)
fun myServiceQueue(commandExecutionQueueFactory: CommandExecutionQueueFactory) =
commandExecutionQueueFactory.createQueue(
MY_QUEUE_NAME,
@ndemengel
ndemengel / ClientCode.kt
Last active April 26, 2020 10:42
Commanq queue: scheduling a command execution
@Component
class ClientCode(
@Named(MY_QUEUE_NAME)
private val commandScheduler: CommandScheduler
) {
fun doSomething() {
// ... some code ...
val transactionId: TransactionId = ...
val invoiceId: InvoiceId = ...
commandScheduler.schedule(PushTransactionForInvoiceSpec(transactionId, invoiceId))