Skip to content

Instantly share code, notes, and snippets.

View michalbcz's full-sized avatar

Michal Bernhard michalbcz

View GitHub Profile
private void test(List<ExchangeRate> exchangeRates) {
Map<String, ExchangeRate> rateType11Map = new HashMap<String, ExchangeRate>();
Map<String, ExchangeRate> rateType12Map = new HashMap<String, ExchangeRate>();
Collections.sort(exchangeRates, new Comparator<ExchangeRate>() {
@Override
public int compare(ExchangeRate e1, ExchangeRate e2) {
return ComparisonChain.start()
.compare(e1.getRateCurrency(), e2.getRateCurrency())
.compare(e1.getRateType(), e2.getRateType())
@michalbcz
michalbcz / gist:00a069c7a2542ea7fa2a
Created March 19, 2015 10:42
jax-rs (Resteasy) - dynamic image resource sample
@GET
@Path("/images/{id}")
@Produces("image/png")
public Response getImages(final @PathParam("id") String id) {
StreamingOutput imageStreamingOutput = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
final BufferedImage image = new BufferedImage(250, 250, BufferedImage.TYPE_INT_RGB);
@michalbcz
michalbcz / JsonStringProducer.java
Created March 6, 2015 14:30
resteasy - automatically encode output of JSON media type (application/json) as UTF-8
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
@michalbcz
michalbcz / gist:744de11f522248c4e321
Last active August 29, 2015 14:07
linux shell script to easily take screenshot from google glass
# ==== Google Glass =====
# take screenshot
alias gtp='adb shell /system/bin/screencap -p /sdcard/screenshot.png'
# copy screenshot from glass to current directory (pwd)
alias gdp='adb pull /sdcard/screenshot.png screenshot_$(date -d "today" +"%s").png'
# take and copy screenshot to current dir
alias gg='gtp && gdp'
@michalbcz
michalbcz / gist:0be8d667e1ea825de588
Created September 23, 2014 16:09
EN -> CZ translation using slovnik.seznam.cz
/* EN -> CZ translation using slovnik.seznam.cz */
@Grapes([
@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.3.5'),
@Grab(group='org.jsoup', module='jsoup', version='1.7.3')
])
import org.apache.http.impl.client.*
import org.apache.http.client.methods.*
import org.apache.http.util.EntityUtils
import org.jsoup.*
@michalbcz
michalbcz / gist:8298941
Created January 7, 2014 12:59
Java Standard Library way to find out MIME type according to file name (extension)
import java.net.URLConnection;
assert URLConnection.getFileNameMap().getContentTypeFor("someimage.png") == 'image/png'
@michalbcz
michalbcz / StringUtils
Last active March 17, 2017 12:18
replacing characters with diacritic (national characters) with variant without diacritic eg. replace Á to A..etc.
public final class StringUtils {
private StringUtils() { /* cannot be instantiated */ }
/**
* <b>WORKS ONLY IN JAVA 1.6 AND ABOVE !!!</b>
*
* @param textWithDiacritic
*/
public static String removeDiacritics(String textWithDiacritic) {
import java.text.Collator;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import org.apache.wicket.Session;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.model.IModel;
@michalbcz
michalbcz / gist:6775946
Created October 1, 2013 09:25
eclipse template definition - adding LOG declaration to class
${import1:import(org.slf4j.Logger)}
${import2:import(org.slf4j.LoggerFactory)}
private static final Logger LOG = LoggerFactory.getLogger(${enclosing_type}.class);
@michalbcz
michalbcz / md5.groovy
Created September 17, 2013 06:55 — forked from ikarius/md5.groovy
def generateMD5(String s) {
MessageDigest digest = MessageDigest.getInstance("MD5")
digest.update(s.bytes);
new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0')
}