Skip to content

Instantly share code, notes, and snippets.

View michalbcz's full-sized avatar

Michal Bernhard michalbcz

View GitHub Profile
@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: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 / 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: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 / copy_and_flatten_my_pics_and_zip_it.groovy
Created October 22, 2011 11:57
copy and flatten directories with pictures and zip it to single file as I am lame in Krusader file manager :)
def ant = new AntBuilder() /* rules */
/* copy my roadtrip pictures and videos from CD and flatten it */
ant.copy(todir: "/home/michal/Pictures/Norsko2004", flatten: true /* if false (default) it copies directory structure too */) {
fileset(dir:"/media/Norsko 2004/Norsko 2004", casesensitive: false) {
include(name: "**/*.jpg") /* pictures... */
include(name: "**/*.mov") /* ...and videos */
}
}
@michalbcz
michalbcz / gist:2837835
Created May 30, 2012 17:38
groovy - html modification with state-of-art library JSoup -
@Grapes(
@Grab(group='org.jsoup', module='jsoup', version='1.6.2')
)
import org.jsoup.*
import org.jsoup.nodes.*
/**
* during build time we combine all the js files to single file (to speed up page loading)
* this script is part of the this script and its purpose is to collect all the external js files refered in
* MasterPage.html (template for the page) to feed up function which do the real combining and minifying to
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:3360573
Created August 15, 2012 14:25
groovy - super basic stats and usage of class extensions
// ------------------- methods and extensions definitions -----------------------------
List.metaClass.grepWithIndex = { yield ->
def greppedCollection = []
delegate.eachWithIndex { value, index ->
if (yield(value, index)) {
greppedCollection << value
}
@michalbcz
michalbcz / gist:3634032
Created September 5, 2012 09:26
groovy - simple 'tree' command implementation
new File(".").eachDirRecurse { dir ->
/* if you wonder why not to write ~/\\/ directly see
http://groovy.codehaus.org/Strings+and+GString#StringsandGString-SlashyStringliterals or
http://jira.codehaus.org/browse/GROOVY-2451 */
def bs = "\\\\"
def fs = "/"
def pattern = ~/$bs|$fs/
@michalbcz
michalbcz / gist:3712849
Created September 13, 2012 08:23
liferay - obtain url to page (page is where you place your portlets it's like igoogle and gadget relation)
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
//Layout layout = LayoutLocalServiceUtil.getFriendlyURLLayout(themeDisplay.getScopeGroupId(), false, "/page-name");
HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request);
httpRequest = PortalUtil.getOriginalServletRequest(httpRequest);
//Retrieve layout id of another portlet. Layout is synonym for Page. Will it crash if there are multiple pages??? TODO test it
String portletId = "portletId"; // portlet id is string and you will find this in liferay database scheme or maybe it have some logic, but i don't know what and if it's compatible between liferay versions
long plid = PortalUtil.getPlidFromPortletId(themeDisplay.getScopeGroupId(), portletId);