Skip to content

Instantly share code, notes, and snippets.

View m-x-k's full-sized avatar

Martin Kelly m-x-k

View GitHub Profile
@m-x-k
m-x-k / BiFunctionValidationExample.java
Last active April 8, 2018 02:13
Validation Example with BiFunction
import java.util.function.BiFunction;
import java.util.function.Function;
import static Pet.*;
public class BiFunctionValidationExample {
public static void main(String[] args) {
// BiFunction example
BiFunctionValidation<Pet, String> v = new BiFunctionValidation<>(IS_EMPTY_RETURN_PET);
@m-x-k
m-x-k / pipelineChooseDockerTags.groovy
Created November 16, 2016 22:05
Jenkins pipeline - choose docker tags
/*
* Displays input dropdown select containing docker image tags
* Manage Jenkins->Script Approval (required)
*/
node {
stage('chooseDockerTags') {
def image = "IMAGE"
def url = "https://LOCAL-DOCKER-REG:5000/v2/${image}/tags/list"
def list = getDockerImageTags(url)
@m-x-k
m-x-k / outputCredentialsPipeline.groovy
Created November 18, 2016 15:36
Jenkins Pipeline sample using Credentials Binding Plugin
node {
stage('GetUserCredential') {
// Requires Credential setup (MyCredentialID)
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'MyCredentialID',
usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
sh '''
set +x
echo "$USERNAME" > output.txt
'''
@m-x-k
m-x-k / MyInterceptor.java
Last active July 21, 2020 08:57
Spring Boot Interceptor with annotation support
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import static java.lang.String.format;
@m-x-k
m-x-k / BaseTest.java
Created December 22, 2016 08:03
Junit assert log statements
public class BaseTest {
final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
@Mock
protected Appender mockAppender;
@Captor
protected ArgumentCaptor<LoggingEvent> captorLoggingEvent;
@Before
@m-x-k
m-x-k / build.gradle
Created December 22, 2016 08:31
gradle register java custom annotations with intellij
apply plugin: 'groovy'
apply plugin: 'idea'
repositories {
jcenter()
}
idea {
project {
ipr {
@m-x-k
m-x-k / index.html
Created December 26, 2016 23:05
ChatBot with module design pattern
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="keywords" content="design patterns">
<title>Mastering Javascript</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
@m-x-k
m-x-k / index.html
Last active April 8, 2018 01:22
ChatBot with reveal design pattern
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="keywords" content="design patterns">
<title>Mastering Javascript</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
@m-x-k
m-x-k / circleGeneratorSingleton.js
Last active April 8, 2018 01:22
Javascript singleton pattern
(function(win, $) {
var CircleGeneratorSingleton = (function() {
var instance;
function init() {
var _aCircle = [],
_stage = $('.advert');
function _position(circle, left, top) {
@m-x-k
m-x-k / circleFactory.js
Last active April 8, 2018 01:22
Create circles with Factory Pattern javascript
(function(win, $) {
var RedCircle = function() {
this.item = $('<div class="circle"></div>');
},
BlueCircle = function() {
this.item = $('<div class="circle" style="background:blue"></div>');
},
CircleFactory = function(color) {
this.create = function(color) {
if (color === 'blue') {