Skip to content

Instantly share code, notes, and snippets.

View jbleduigou's full-sized avatar

Jean-Baptiste Le Duigou jbleduigou

View GitHub Profile
stage('Violations') {
steps {
// Retrieve golint tool
sh 'go get -u golang.org/x/lint/golint'
// Run golint
sh 'cd $GOPATH/src/github/jbleduigou/budgetcategorizer && golint ./...'
// Run go vet
sh 'cd $GOPATH/src/github/jbleduigou/budgetcategorizer && go vet ./... || true'
stage('Test') {
steps {
// Retrieve tool for converting output to junit format
sh 'go get -u github.com/jstemmer/go-junit-report'
// Run unit tests and redirect output to go-junit-report
sh 'cd $GOPATH/src/github/jbleduigou/budgetcategorizer && go test -v ./... 2>&1 | go-junit-report > report.xml'
}
post {
always {
#!/usr/bin/groovy
pipeline {
agent {
docker { image 'golang:1.13' }
}
environment {
XDG_CACHE_HOME='/tmp/.cache'
GOOS='linux'
GOARCH='amd64'
}
@jbleduigou
jbleduigou / boucles-owasp.groovy
Last active February 12, 2020 20:11
boucles-owasp.groovy
#!/usr/bin/groovy
pipeline {
agent any
tools {
// Install the Maven version configured as "M3" and add it to the path.
maven "M3"
}
stages {
@jbleduigou
jbleduigou / boucles.groovy
Created February 5, 2020 20:17
boucles.groovy
#!/usr/bin/groovy
pipeline {
agent any
tools {
// Install the Maven version configured as "M3" and add it to the path.
maven "M3"
}
stages {
@jbleduigou
jbleduigou / jenkins-aws.sh
Created February 5, 2020 20:16
jenkins-aws.sh
#!/bin/bash
yum update -y
yum install java-1.8.0-devel -y
yum install git -y
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
yum install jenkins -y
service jenkins start
chkconfig --add jenkins
@jbleduigou
jbleduigou / junit5_livetemplate.java
Created January 22, 2020 20:17
An IntelliJ live template for asserting exceptions with Junit 5
Throwable exception = assertThrows(IllegalArgumentException.class, () -> $SELECTION$);
assertThat(
exception.getMessage(),
is("Okay, Houston, we've had a problem here"));
@jbleduigou
jbleduigou / assertexception_junit5.java
Created January 22, 2020 20:14
how to assert exception with Junit 5
Throwable exception = assertThrows(BusinessLogicException.class,
() -> userService.getUserDetails(1337));
assertThat(exception.getMessage(), is("Could not get user details!"));
private static Set<List<Item>> generateAllSubLists(List<Item> items) {
Set<List<Item>> subLists = new HashSet<>();
int allBitMasks = (int) Math.pow(2, Math.min(items.size(), 12));
for (long i = 1; i < allBitMasks; i++) {
List<Item> sublist = new ArrayList<>();
for (int j = 0; j < items.size(); j++) {
if ((i & (1 << j)) > 0) {
sublist.add(items.get(j));
}
}
// Generate all possible sub-lists (PowerSet algorithm)
Set<List<Item>> subLists = generateAllSubLists(items);
// Find best solution for each sub-set
SortedSet<Solution> solutions = new TreeSet<>();
for (List<Item> sublist : subLists) {
Solution solution = findBestSolution(maxWeight, sublist);
solutions.add(solution);
}
// No need to sort solutions, TreeSet implements SortedSet
Solution best = solutions.first();