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 / GreetingController.java
Created June 28, 2016 20:49
Spring Rest Exception Handling
@RestController
public class GreetingController {
@RequestMapping("/my/rest/exception")
public @ResponseBody ResponseEntity<String> myException() {
if (true)
throw new MyRestException("should see me");
return new ResponseEntity<String>("don't see me", HttpStatus.OK);
}
@m-x-k
m-x-k / gitAlias
Created July 17, 2016 17:52 — forked from ParkinT/gitAlias
A list of example git alias shortcuts from the "Mastering Git" [ISBN 978-1-78355-413-3] book by Packt Publishing. This is described in Section 7.
### Common Commands
ssb = status -sb
logo = log --oneline
c = commit -m
a = add
cob = checkout -b
st = status -s
co = checkout
stat = status
cl = clone
@m-x-k
m-x-k / FileUploadController.java
Last active April 8, 2018 02:13
Spring boot jpa mongo gridfs example
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.gridfs.GridFsTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
@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 {
@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 / 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 / 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 / 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 / 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 / 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();