Skip to content

Instantly share code, notes, and snippets.

@fmarot
fmarot / pom.xml
Last active February 7, 2020 10:52
surefire 3.0.0-M4 problem
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.teamtter.fake</groupId>
<artifactId>test-fake-module</artifactId>
<version>2.0.0-SNAPSHOT</version>
<properties>
<java.source.target.version>1.8</java.source.target.version>
@fmarot
fmarot / HttpSessionEventPublisherWithcontextDoesNotStopWorkaround
Last active May 27, 2019 13:48
workaround for spring context re-creating itself when closing after a JUnit test class annotated @SpringBootTest has run
import javax.servlet.http.HttpSessionEvent;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextStartedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.security.web.session.HttpSessionEventPublisher;
/** This class workaround a bug we observed in JUnit tests when using a full- sds server in AbstractRealDatamanagerTest:
* the problem was that when the spring context was trying to close, then tomcat was finally closed triggering a
* 'sessionDestroyed' event that in turn tried to publish a 'sessionDestroyed' having the effect of reviving the context.
@fmarot
fmarot / jenkins-detect-cron
Created April 15, 2019 19:59
do not take this code as-is because I just copy-pasted it from an old test and do not really know anymore if it works correctly. It may help though...
def userIdCause = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)
boolean buildTriggeredManually = (userIdCause != null);
//boolean buildIsNightly = userIdCause.toString().toLowerCase().contains("trigger") || currentBuild.rawBuild.getCauses().get(0).toString().contains("BranchIndexingCause")
def buildIsNightly = false
currentBuild.upstreamBuilds?.each { b ->
echo "Upstream build: ${b.getFullDisplayName()}"
buildIsNightly = true
}
//def specificCause = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause) // must be set to null once used because it is not serializable
echo "userIdCause = ${userIdCause}, buildTriggeredManually = ${buildTriggeredManually}, buildIsNightly = ${buildIsNightly}" // #debug
@fmarot
fmarot / BackgroundObjectBuilder.java
Created April 4, 2019 14:20
This class contains a builder method that allows to create object with time-consuming constructor in background. Then it can be used as usual from a user perspective. Totally trensparent from user-side apart the construction using the provided builder method.
package com.oleamedical.dbclient.sds;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
import java.util.function.Supplier;
@fmarot
fmarot / monitor.groovy
Created June 25, 2018 21:36
monitor availability of KIMSUFI KS-2
@Grab('org.eclipse.jetty.aggregate:jetty-server:8.1.19.v20160209')
@Grab('org.eclipse.jetty.aggregate:jetty-servlet:8.1.19.v20160209')
@Grab('javax.servlet:javax.servlet-api:3.0.1')
@Grab('org.seleniumhq.selenium:selenium-api:3.5.3')
@Grab('org.seleniumhq.selenium:selenium-remote-driver:3.5.3')
@Grab('org.seleniumhq.selenium:selenium-server:3.5.3')
@Grab('junit:junit:4.12')
import org.openqa.selenium.By;
@fmarot
fmarot / parseGamelistRecalbox.groovy
Created May 12, 2018 17:04
This script creates a CSV file from the gamelist.xml files contained in your Recalbox
/**
This script creates a CSV file from the gamelist.xml files contained in your Recalbox
*/
/*
Telechargement automatique des librairies:
- jcifs pour acceder au partage reseau des fichier (protocole samba)
- IOUtils, la librairie contenue dans commons-io et qui permet de lire des fichiers facilement
*/
@Grapes([
@fmarot
fmarot / PrintPreviewPagesTester.java
Created May 2, 2017 08:01
A Swing layout able to lay pages horizontally inside an horizontally scrollable panel
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Rectangle;
import java.awt.event.ComponentEvent;
#!/bin/bash
#If we do not sleep, the network is not available :( => we should use systemd !!!
sleep 8
# inspired by http://disq.us/p/1anwvre
# requires to set wallpaper mode as slideshow from ~/wallpaper
echo "`date`" >> getBingWallpaper.log
export EXTENSION=jpg
export TARGET_DIRECTORY=/home/pierrehenri/Dropbox/scans
export TIMESTAMP=$(date +%Y%m%d_%H%M%S)
export TMP_FILE=/tmp/scan-$TIMESTAMP.$EXTENSION
export OUTPUT_FILE=$TARGET_DIRECTORY/scan-$TIMESTAMP.$EXTENSION
export ARCHIVE_DIR=$TARGET_DIRECTORY/vieux-scans/
mkdir -p $TARGET_DIRECTORY
mkdir -p $ARCHIVE_DIR
@fmarot
fmarot / SingleComponentAspectRatioKeeperLayout.java
Last active February 3, 2024 16:09
A Java Swing Layout Manager that keep the aspect ratio of the component inside the container while enlarging/shrinling it. Contains a main() method with a JFrame to see by yourself. I crerated it because was unable to find simple exemples on the net.
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager;
import javax.swing.JFrame;
import javax.swing.JPanel;