Skip to content

Instantly share code, notes, and snippets.

View vorburger's full-sized avatar

Michael Vorburger vorburger

View GitHub Profile
public class helloclass
{
/**
* @author vorburger
*/
public static void main(String args[])
{
System.out.println("Hello World!");
}
}
@vorburger
vorburger / ClassPathScanner.java
Created July 3, 2011 21:56
List all resources under a certain directory on the Classpath (using Spring)
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "/META-INF/resources/birt/**");
@vorburger
vorburger / CopyResourcesFromClassPathToFilesystemDirectory.java
Created July 3, 2011 22:29
Copy resources from Classpath into a temporary directory
import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.apache.commons.io.FileUtils;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
package learning;
public class DevFirstJava {
public static void main(String[] args) {
// start bye saying hello
System.out.println("hello");
}
@vorburger
vorburger / gist:3429822
Created August 22, 2012 22:03
How to find an available (free) TCP port in Java
/**
* Returns a free port number on localhost.
*
* Heavily inspired from org.eclipse.jdt.launching.SocketUtil (to avoid a dependency to JDT just because of this).
* Slightly improved with close() missing in JDT. And throws exception instead of returning -1.
*
* @return a free port number on localhost
* @throws IllegalStateException if unable to find a free port
*/
private static int findFreePort() {
@vorburger
vorburger / Test.java
Created August 25, 2012 10:06
WebDriver ChromeDriver setProperty("webdriver.chrome.driver"...)
private ChromeDriver getChromeDriver() throws URISyntaxException {
URL url = getClass().getResource("/ch/vorburger/vaadin/designer/tests/web/chromedriver.exe");
File file = new File(url.toURI());
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
return new ChromeDriver();
}
@vorburger
vorburger / InputStreamFromString
Created January 21, 2013 23:23
How to best obtain an InputStream from a String (e.g. to pass it to an API dealing only with InputStream, such as an Eclipse org.eclipse.core.resources.IFile create().
InputStream is = new ByteArrayInputStream(xmlString.getBytes(Charsets.UTF_8));
@vorburger
vorburger / badSomeFamilies.efactory
Last active December 21, 2015 17:58
Syntactically invalid EFactory example which causes the OutOfMemoryError at org.eclipse.xtext.ui.editor.syntaxcoloring reported on the Xtext Forum
family.City {
families += family.Family Flintstones {
members = [
family.Person Fred {
age = 45
}
]
members += family.Person Fred {
#!/usr/bin/python
# https://lists.fedoraproject.org/pipermail/test/2009-May/081959.html
# from http://askubuntu.com/questions/4499/how-can-i-diagnose-debug-maximum-number-of-clients-reached-x-errors/6639#6639
from subprocess import Popen, PIPE
client_sockets = []
match = 0
@vorburger
vorburger / InjectorToString.java
Created January 27, 2014 16:48
InjectorToString.java - Guice Injector toString - nicer than built-in massive one line dump (currently unfinished)
/**
* Copyright (C) 2014 Michael Vorburger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software