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 / core-async-demo.clj
Last active June 12, 2018 10:59
Introduction to Clojure's core.async library
;;;;;;;;;;
;;;; Introduction to core.async based on
;;;; https://github.com/clojure/core.async/tree/master/examples
;;;;;;;;;;
(require [clojure.core.async
:refer [>! <! >!! <!! go chan close! alts! alts!! alt! alt!!
timeout dropping-buffer sliding-buffer]])
;;;;;;;;;;
@beatngu13
beatngu13 / ref-types-demo.clj
Last active June 12, 2018 10:59
Introduction to Clojure's reference types
;;;;;;;;;;
;;;; Introduction to Clojures reference types based on
;;;; http://clojure-doc.org/articles/language/concurrency_and_parallelism.html#clojure-reference-types
;;;;;;;;;;
;; Clojure provides a powerful set of reference types, each of them with its own
;; concurrency semantics for different kinds of operations:
;;
;; | Coordinated | Uncoordinated
;; ------|-------------|--------------
@beatngu13
beatngu13 / fun.clj
Last active June 12, 2018 10:58
Fun with Clojure
;;;;;;;;;;
;;;; Fun with Clojure
;;;;;;;;;;
;; Comments are based on Peter Norvig's recommendations from his tutorial on
;; good Lisp programming style (see
;; http://www.cs.umd.edu/~nau/cmsc421/norvig-lisp-style.pdf on page 41):
;; ; inline comment
;; ;; in-function comment
;; ;;; between-function comment

Without line wrapping

Bacon ipsum dolor amet rump porchetta short ribs venison filet mignon boudin pork loin, landjaeger pastrami ball tip ribeye. Drumstick jowl leberkas hamburger kielbasa tongue porchetta corned beef shank venison chuck biltong short loin pork belly. Ham hock jowl pork loin tail burgdoggen capicola pork belly pork chop andouille chuck leberkas. Ham shank pork, kielbasa sausage tongue sirloin bacon filet mignon cupim frankfurter cow hamburger. Alcatra corned beef tri-tip shoulder, turducken salami tenderloin ham hock burgdoggen cow. Jerky chicken picanha salami capicola tri-tip short ribs andouille swine meatloaf shankle ground round porchetta pork belly burgdoggen. Boudin jerky tail frankfurter tenderloin tongue capicola venison turducken bresaola chicken.

With line wrapping

Bacon ipsum dolor amet rump porchetta short ribs venison filet mignon boudin pork loin, landjaeger pastrami ball tip ribeye. Drumstick jowl leberkas hamburger kielbasa tongue porchetta corned beef shank venison c

@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
@beatngu13
beatngu13 / CrossBrowserTest.java
Last active May 14, 2024 13:43
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 / 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 / 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 / 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 / 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();