Skip to content

Instantly share code, notes, and snippets.

View arturozv's full-sized avatar

Arturo Zendrera Valsecchi arturozv

View GitHub Profile
@arturozv
arturozv / SpringBatchConfiguration
Created April 22, 2015 06:33
Spring batch configuration using hsql for meta-data schema
@Configuration
public class SpringBatchConfiguration implements BatchConfigurer {
@Bean(name = "hsqlDataSource")
public DataSource hsqlDataSource() {
EmbeddedDatabaseBuilder embeddedDatabaseBuilder = new EmbeddedDatabaseBuilder();
return embeddedDatabaseBuilder
.addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql")
.setType(EmbeddedDatabaseType.HSQL).build();
@arturozv
arturozv / gist:431d1ad194ae2e4d1c8f
Created May 12, 2015 14:24
Linked resources with spring hateoas
package com.shootr.api.domain;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import java.util.ArrayList;
import java.util.List;
import org.springframework.hateoas.Resource;
@arturozv
arturozv / gist:3556cd2e0ed2636710b3
Created May 12, 2015 14:26
Spring cache manager with guava cache
package com.shootr.api.config;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import javax.annotation.PreDestroy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
@arturozv
arturozv / gist:6df2355a33d44998e8de
Created May 12, 2015 14:32
Spring @ControllerAdvice to handle exceptions
package com.shootr.api.web.rest.exception;
import java.util.ArrayList;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@arturozv
arturozv / gist:35d248ca14927196ab56
Created May 12, 2015 14:33
Spring mvc message converter configuration with jackson
package com.shootr.api.config;
import java.util.List;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheStats;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.PublicMetrics;
import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import java.util.ArrayList;
#!/bin/bash
# Params:
# 1- filename in s3. Ex: mongobackup-tst-28-05-2015-1432802174.7z
# 2- source env. Ex: pro
# 3- target env to restore in. Ex: tst
# 4- target database name. Ex: databaseRestore
# ex: ./restore.sh mongobackup-tst-28-05-2015-1432802174.7z pro tst databaseRestore
# s3 file exists and ends with .tar.gz
if [ -z "$1" ] || [[ ! $1 =~ .*.7z ]]; then
#!/bin/bash
# ./backup.sh pro databaseName
# Validations
if [ -z "$1" ] ; then
echo `date`" specify a environment ['tst', 'pro']"
exit 1
elif [ "$1" != "tst" ] && [ "$1" != "pro" ]; then
echo `date`" specify a valid environment ['tst', 'pro']"
exit 1
@arturozv
arturozv / gist:f9084111bb3365dc0f5d
Created June 11, 2015 07:48
Spring data mongodb custom auditing with AbstractMongoEventListener
import org.joda.time.Instant;
import org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener;
public class MongoSynchronizedListener extends AbstractMongoEventListener<Object> {
/**
* Called in MongoTemplate insert, insertList and save operations before the
* object is converted to a DBObject using a MongoConveter.
*/
@arturozv
arturozv / gitlabssl.sh
Last active November 11, 2015 13:15
Ubuntu -> update gitlab ssl certificates
echo -n | openssl s_client -connect gitlab.com:443 | \
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | \
sudo tee '/usr/local/share/ca-certificates/gitlab_com.crt'
sudo update-ca-certificates