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 / DebianDockerPrivateRegistryAccessSetup.txt
Created December 30, 2016 09:06
Debian docker private registry access setup
Go to private repository in browser (e.g. https://<PRIVATE_REG>:5000/v2/_catalog)
Download the certificate (e.g. View Cerificate > Details > Export (PEM format))
Copy crt certificate to: /usr/local/share/ca-certificates/
sudo update-ca-certificates --verbose
systemctl restart docker
Confirm it all works by trying to pull down a docker image from the private registry:
@m-x-k
m-x-k / AppWebMvcConfiguration
Created December 31, 2016 20:38
Spring boot Gson converter
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.util.List;
@Configuration
public class AppWebMvcConfiguration extends WebMvcConfigurerAdapter {
@m-x-k
m-x-k / rx_simple.py
Created January 21, 2017 17:42
Reactive for python. Simple example using lambda's
from rx import Observable, Observer
letters = Observable.from_(['Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon'])
letters.subscribe(on_next=lambda s: print(s),
on_completed=lambda: print('Done'),
on_error=lambda e: print(e))
@m-x-k
m-x-k / rx_operators.py
Created January 21, 2017 20:36
reactive observable operators example
from rx import Observable, Observer
letters = Observable.from_(['Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon']) \
.map(lambda s: len(s)) \
.filter(lambda i: i >= 5) \
.subscribe(lambda i: print(i))
@m-x-k
m-x-k / rx_interval_observerables.py
Created January 23, 2017 21:49
Reactive (Rx) python example with intervals
from rx import Observable, Observer
Observable.interval(1000) \
.map(lambda i: "{0} Mississippi".format(i))\
.subscribe(lambda s: print(s))
input("Press any key to quit")
@m-x-k
m-x-k / TestRandomStringGenerator.java
Created February 3, 2017 15:30
java random string list generator example with streams
import java.util.List;
import java.util.Random;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class TestRandomStringGenerator {
private static Supplier<String> randomDischargeId = () -> RandomStringUtils.randomConsonant(8);
public static void main(String[] args) {
@m-x-k
m-x-k / BubbleSort.java
Last active July 26, 2018 13:33
Java 8 bubble sort integer array example using predicates for acending and descending options
import java.util.Arrays;
import java.util.Random;
import java.util.function.Predicate;
public class BubbleSort {
private static Random random = new Random();
private Integer[] sort(Integer[] array, Predicate<Integer> sortType) {
int count = 0;
@m-x-k
m-x-k / GetValueAsInteger.js
Created February 12, 2017 21:19
Javascript augmenting types example
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
Number.method('integer', function ( ) {
return Math[this < 0 ? 'ceil' : 'floor'](this);
});
document.writeln((-10 / 3).integer( )); // −3
@m-x-k
m-x-k / StringTrimExample.js
Created February 12, 2017 21:22
Javascript augment String prototype to include trim function
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
String.method('trim', function ( ) {
return this.replace(/^\s+|\s+$/g, '');
});
document.writeln('"' + " neat ".trim( ) + '"');
@m-x-k
m-x-k / JSRValidationTest.java
Created February 27, 2017 16:11
JUnit validate JSR-303 with assertion
import org.hibernate.validator.constraints.NotEmpty;
import org.junit.BeforeClass;
import org.junit.Test;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.util.Set;