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 / 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 / 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 / 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 / PostJacksonObjectViaRestTemplate.java
Created October 19, 2016 13:44
Post Jackson Object Via Rest Template
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.*;
import org.springframework.web.client.RestTemplate;
class PostJacksonObjectViaRestTemplate {
public static void main(String[] args) throws Exception {
String url = "http://localhost:8080/example/";
HttpHeaders headers = new HttpHeaders();
@m-x-k
m-x-k / SpringBootApplicationJacksonMixInExample.java
Created September 26, 2016 20:13
Spring Boot Application Jackson MixIn Example
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@m-x-k
m-x-k / JacksonJsonViewExample.java
Created September 26, 2016 19:49
Jackson JsonView example
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.ObjectMapper;
class Views {
public static class Normal{}
public static class WithTitle extends Normal{}
}
@m-x-k
m-x-k / Pymongo load $date
Last active August 21, 2018 11:58
Pymongo load $date timestamp or isodate using bson.json_util.loads
from bson import json_util
# load as timestamp
print json_util.loads('{"$date": 1414516147000}')
# load as isodate
print json_util.loads('{"$date": "2014-10-28T17:09:07.000Z"}')
@m-x-k
m-x-k / application.yml
Last active April 8, 2018 02:13
Spring Boot Docker Image with external environment configuration
spring:
data:
mongodb:
host: ${MONGO_HOST}
port: ${MONGO_PORT}
database: ${MONGO_DB}
@m-x-k
m-x-k / basic.yml
Created August 18, 2016 20:21
tmuxinator basic sample - open multiple terminal applications via command line
# ~/.tmuxinator/basic.yml
name: basic
root: ~/
windows:
- editor:
layout: main-vertical
panes:
- top
@m-x-k
m-x-k / JSONUtils.java
Created July 20, 2016 13:51
Simple java json utils for testing
import com.google.gson.Gson;
import org.skyscreamer.jsonassert.JSONAssert;
import static org.junit.Assert.fail;
public final class JSONUtils {
private static final Gson gson = new Gson();
public static void assertValidJson(String jsonInString) {
try {