Skip to content

Instantly share code, notes, and snippets.

View mdread's full-sized avatar

Daniel Camarda mdread

View GitHub Profile
@mdread
mdread / file1.txt
Created September 4, 2015 00:31
the description for this gist
String file contents
@mdread
mdread / index.html
Last active December 29, 2015 16:19
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"></link>
</head>
<body>
just some random text...
<p>
<span id="block1"></span>
</p>
@mdread
mdread / ExtendedHttpSolrServer.java
Created November 27, 2013 18:06
Embed JSON values in Solr fields and auto unmarshall it when converting from a document to a bean
import org.apache.http.client.HttpClient;
import org.apache.solr.client.solrj.ResponseParser;
import org.apache.solr.client.solrj.beans.DocumentObjectBinder;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
public class ExtendedHttpSolrServer extends HttpSolrServer {
private static final long serialVersionUID = -5355794252201598225L;
private DocumentObjectBinder binder;
import org.elasticsearch.action.ActionRequestBuilder
import org.elasticsearch.action.ActionResponse
import org.elasticsearch.action.ActionListener
import scala.concurrent.{ Promise, Future }
import scala.util.Try
object Futurastic {
def execute[T, R <: ActionResponse](builder: ActionRequestBuilder[_, R, _])(action: (R) => Try[T]): Future[T] = {
@mdread
mdread / pom.xml
Last active January 12, 2023 15:55
maven configuration for remote deploying on tomcat with cargo
TODO: add notes on configuration
@mdread
mdread / map.java
Created May 3, 2013 12:52
functional "map" for java
public static <R extends Iterable<K>, K, V> R map(Iterable<V> iter, Function<V, K> func){
List<K> result = new LinkedList<K>();
for (V sourceValue : iter) {
result.add(func.apply(sourceValue));
}
return (R)result;
}
public static interface Function<S, R> {
R apply(S value);
@mdread
mdread / mkString.java
Created May 3, 2013 11:04
method "mkString"
public static String mkString(Iterable<?> values, String start, String sep, String end){
// if the array is null or empty return an empty string
if(values == null || !values.iterator().hasNext())
return "";
// move all non-empty values from the original array to a new list (empty is a null, empty or all-whitespace string)
List<String> nonEmptyVals = new LinkedList<String>();
for (Object val : values) {
if(val != null && val.toString().trim().length() > 0){
nonEmptyVals.add(val.toString());
@mdread
mdread / gist:5454308
Last active December 16, 2015 15:09
javascript array.contains and array.diff
Array.prototype.contains = function(val, eqFunc /* (val, arrVal) */){
eqFunc = eqFunc || function(val1, val2){return val1 == val2;};
for(var i = 0; i < this.length; i++){
if(eqFunc(val, this[i])){
return true;
}
}
return false;
@mdread
mdread / DateConverter.java
Last active December 16, 2015 12:49
convert between string rappresentations of dates. example: from("yyyy-MM-dd").to("dd/MM/yyyy").convert("1987-12-01"); // results in 01/12/1987
import java.text.ParseException;
import java.text.SimpleDateFormat;
public final class DateConverter {
private SimpleDateFormat formatterFrom;
private SimpleDateFormat formatterTo;
private DateConverter(){
super();
}
@mdread
mdread / AccessCondition.java
Last active December 15, 2015 13:09
Spring interceptor for conditional access to a request action
package net.caoticode.spring.interceptors.conditional;
import javax.servlet.http.HttpServletRequest;
import org.springframework.context.ApplicationContext;
public interface AccessCondition {
boolean test(HttpServletRequest request, ApplicationContext context);
}