Skip to content

Instantly share code, notes, and snippets.

View beatngu13's full-sized avatar
💀
Choose death!

Daniel Kraus beatngu13

💀
Choose death!
View GitHub Profile
@beatngu13
beatngu13 / my-github-token.yaml
Created July 29, 2023 15:50
GitHub (fine-grained or classic) access token as K8s secret for Tekton
kind: Secret
apiVersion: v1
metadata:
name: my-github-token
namespace: my-namespace
annotations:
tekton.dev/git-0: 'https://github.com'
# stringData is important; if you use data instead, you might get the following error:
# Secret in version "v1" cannot be handled as a Secret: illegal base64 data at input byte 6
stringData:
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;
class AbortRemainingTestsExtension implements TestExecutionExceptionHandler, BeforeTestExecutionCallback {
private static final String STORE_KEY = "abort";
@Override
@beatngu13
beatngu13 / Jenkinsfile
Last active April 16, 2021 22:35
Cron-triggered Jenkins pipeline to send patches via email on available Maven dependency updates
pipeline {
agent any
triggers {
cron('00 23 * * 1-5')
}
stages {
stage('Check dependency updates') {
steps {
@beatngu13
beatngu13 / download.sh
Last active April 9, 2021 20:48
Download a list of web pages (including assets) for offline usage with Wget
# The user agent to use (see https://en.wikipedia.org/wiki/User_agent).
USER_AGENT='Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Firefox/68.0'
# The web pages to download.
WEB_PAGES=(
'google.com'
'youtube.com'
'facebook.com'
)
@beatngu13
beatngu13 / AbstractVisualTest.java
Last active August 25, 2019 14:14
Deep visual testing across multiple browsers and pages using JUnit 5, Selenium, and recheck-web
/**
* An abstract base class for all visual tests, defining the pages to test. One can also use separate test cases/methods
* if specific pages need different test steps.
*/
abstract class AbstractVisualTest {
WebDriver driver;
Recheck re;
abstract WebDriver getWebDriver();
@beatngu13
beatngu13 / xpath.js
Last active April 8, 2023 22:12
Get the absolute XPath for a given Selenium WebElement
// Taken from https://stackoverflow.com/a/47088726/3429133.
function getAbsoluteXPath(element) {
var comp, comps = [];
var parent = null;
var xpath = '';
var getPos = function(element) {
var position = 1,
curNode;
if (element.nodeType == Node.ATTRIBUTE_NODE) {
return null;
@beatngu13
beatngu13 / SystemProperties.java
Last active June 13, 2020 10:48
Easily handle Java system properties with JUnit 5 extensions
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.extension.ExtendWith;
@Retention( RetentionPolicy.RUNTIME )
@Target( ElementType.METHOD )
@ExtendWith( SystemPropertyExtension.class )
@beatngu13
beatngu13 / JeneticsExample.scala
Last active October 23, 2018 13:22
Knapsack problem in Scala using the MOEA Framework and Jenetics
import java.util.function.{ Function => JFunction }
import scala.collection.JavaConverters
import com.github.beatngu13.gist.knapsack.KnapsackProblem.Capacity
import com.github.beatngu13.gist.knapsack.KnapsackProblem.Items
import com.github.beatngu13.gist.knapsack.KnapsackProblem.OptimalProfit
import com.github.beatngu13.gist.knapsack.KnapsackProblem.OptimalSolution
import io.jenetics.BitChromosome
import io.jenetics.BitGene
@beatngu13
beatngu13 / CrossBrowserTest.java
Last active January 26, 2024 19:39
Dead-simple cross-browser testing with Selenium and JUnit 5 parameterized tests
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.openqa.selenium.WebDriver;
class CrossBrowserTest {
@ParameterizedTest
@MethodSource( "my.package.WebDriverFactory#getAll" )
void cross_browser_test( final WebDriver driver ) {
System.out.println( "Test with " + driver.getClass().getSimpleName() );
@beatngu13
beatngu13 / Jenkinsfile
Last active July 13, 2022 21:58
Fancy notifications for Slack and HipChat in a scripted Jenkins pipeline
// Based on https://jenkins.io/blog/2016/07/18/pipeline-notifications/.
def notifyMessengers(String buildStatus = 'STARTED') {
// Build status of null means successful.
buildStatus = buildStatus ?: 'SUCCESS'
// Replace encoded slashes.
def decodedJobName = env.JOB_NAME.replaceAll("%2F", "/")
def colorSlack
def colorHipchat