Skip to content

Instantly share code, notes, and snippets.

@ankushs92
ankushs92 / Category.java
Last active July 29, 2017 10:01
IAB categories enum(for OpenRTB 2.5 spec)
public enum Category {
//IAB1 : Arts & Entertainment
IAB1_1("IAB1-1","Books & Literature"),
IAB1_2("IAB1-2","Celebrity Fan/Gossip"),
IAB1_3("IAB1-3","Fine Art"),
IAB1_4("IAB1-4","Humour"),
IAB1_5("IAB1-5","Movies"),
IAB1_6("IAB1-6","Music"),
IAB1_7("IAB1-7","Television"),
@ankushs92
ankushs92 / SpingBeansConfig.java
Created October 26, 2016 17:04
How to autowire RestTemplate.
@Bean(name="testRestTemplate")
public RestTemplate getPubPostbackRestTemplate(){
final int readTimeOut = 5000;
final int connectTimeout = 5000;
final HttpComponentsClientHttpRequestFactory clientHttpRequestFactory =
new HttpComponentsClientHttpRequestFactory();
clientHttpRequestFactory.setConnectTimeout(connectTimeout);
clientHttpRequestFactory.setReadTimeout(readTimeOut);
return new RestTemplate(clientHttpRequestFactory);
@ankushs92
ankushs92 / .txt
Last active August 21, 2016 05:50
Most used maven repositories
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
compile group: 'org.spockframework', name: 'spock-core', version: '1.0-groovy-2.4'
compile group: 'com.google.guava', name: 'guava', version: '19.0'
compile group: 'org.spockframework', name: 'spock-spring', version: '1.0-groovy-2.4'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.1'
################## Profiles ################
spring.profiles.active=dev
################### Logging ################
logging.level.org.springframework.web=debug
################### Security ################
security.basic.enabled=false
@ankushs92
ankushs92 / gist:4fd3fa2afe827a3a981e7561f4cc20d2
Last active July 26, 2016 17:09
application-dev.properties
################### Logging ################
logging.level.org.springframework.web=debug
################### Security ################
security.basic.enabled=false
################### DataSource ################
spring.datasource.url=jdbc:h2:mem:devDb
@ankushs92
ankushs92 / HttpServletRequestUtils.java
Created May 26, 2016 17:43
Some helper methods for HttpServletRequest
public class HttpServletRequestUtils {
public static String getIp(final HttpServletRequest request) {
PreConditions.checkNull(request, "request cannot be null");
String ip = request.getHeader("X-FORWARDED-FOR");
if (ip==null || ip.trim().length()==0)) {
ip = request.getRemoteAddr();
}
return ip;
}
@ankushs92
ankushs92 / gist:420bbbef948285b912a8f1ff706f3705
Last active September 26, 2017 14:02
.gitignore for Most groovy,gradle,java and spring boot projects
# Directories #
/build/
bin/
repos/
/repos/
doc/
/doc/
.gradle/
/bin/
target/
@ankushs92
ankushs92 / PreCondition.java
Created April 16, 2016 17:22
Some Pre conditions/assertions that one would encounter in everyday programming
public class PreCondition {
public static <T> void checkNull(final T t, final String errorMsg){
if(t==null){
throw new IllegalArgumentException(errorMsg);
}
}
public static void checkEmptyString(final String str, final String errorMsg){
if(!Strings.hasText(str)){
throw new IllegalArgumentException(errorMsg);
@ankushs92
ankushs92 / JsonUtils.java
Last active December 28, 2017 08:56
Some Json utilities that I use for every project.Uses Jackson library.
import java.io.IOException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JsonUtils {
private static final ObjectMapper objMapper = new ObjectMapper();
public static <T> T toObject(final String json , final Class<T> clazz) throws Exception{
@ankushs92
ankushs92 / EnumUtils.java
Created April 16, 2016 17:15
Convert a String to an Enumeration (if possible).
public class EnumUtils {
public static <T extends Enum<T>> T getEnumFromString(final Class<T> enumClass,final String value) {
if(enumClass == null){
throw new IllegalArgumentException("enumClass cannot be null");
}
for (final Enum<?> enumValue : enumClass.getEnumConstants()) {
if (enumValue.toString().equalsIgnoreCase(value)) {