Skip to content

Instantly share code, notes, and snippets.

View aweiland's full-sized avatar

Andrew Weiland aweiland

  • Different Exception
View GitHub Profile
@aweiland
aweiland / lets.kt
Created June 13, 2019 23:46
Plural let
fun <T1: Any, T2: Any, R: Any> lets(first: T1?, second: T2?, block: (T1, T2)-> R?): R? {
return if (first != null && second != null) block(first, second) else null
}
fun <T1: Any, T2: Any, T3: Any, R: Any> lets(first: T1?, second: T2?, third: T3?, block: (T1, T2, T3)-> R?): R? {
return if (first != null && second != null && third != null) block(first, second, third) else null
}
fun <T1: Any, T2: Any, T3: Any, T4: Any, R: Any> lets(first: T1?, second: T2?, third: T3?, fourth: T4?, block: (T1, T2, T3, T4)-> R?): R? {
return if (first != null && second != null && third != null && fourth != null) block(first, second, third, fourth) else null
@aweiland
aweiland / .bablerc
Created January 3, 2017 21:06
Webpack error
{
"presets": ["es2015", "react", "stage-0"]
}
@aweiland
aweiland / Application.Java
Created April 9, 2016 22:43
CORS in Dropwizard
private void configureCors(Environment environment) {
final FilterRegistration.Dynamic cors =
environment.servlets().addFilter("CORS", CrossOriginFilter.class);
// Configure CORS parameters
cors.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
cors.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "X-Requested-With,Content-Type,Accept,Origin,Authorization");
cors.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "OPTIONS,GET,PUT,POST,DELETE,HEAD");
cors.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, "true");
@aweiland
aweiland / rethinkmapindex.java
Created April 1, 2016 13:05
map into a rethink embedded doc to create index
r.db(Rethink.DB).table(Rethink.SOCIAL_USER_TABLE)
.indexCreate(Rethink.USER_APPID_PROVIDER_PROVIDERID_IDX,
user -> user.g("credentials").map(
c -> r.array(user.g("appId"), c.g("provider"), c.g("providerId"))
))
.optArg("multi", true).run(connection);
import com.rethinkdb.RethinkDB;
import com.rethinkdb.net.Connection;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import java.util.concurrent.TimeoutException;
public class RethinkDBFactoryBean extends AbstractFactoryBean<Connection> {
private final Connection conn;
@aweiland
aweiland / RethinkHelper.java
Created April 1, 2016 13:03
RethinkDB helper
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rethinkdb.net.Cursor;
import org.apache.commons.beanutils.BeanMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.stream.Collectors;