Skip to content

Instantly share code, notes, and snippets.

View vorburger's full-sized avatar
💭
I may be slow to respond.

Michael Vorburger vorburger

💭
I may be slow to respond.
View GitHub Profile
@vorburger
vorburger / ProjectUtil.java
Created January 23, 2015 16:10
Eclipse Optional<IJavaProject> getJavaProject(IProject project)
// TODO This probably already exists somewhere?
public Optional<IJavaProject> getJavaProject(IProject project) {
try {
if (project.hasNature(JavaCore.NATURE_ID)) {
IJavaProject javaProject = JavaCore.create(project);
return Optional.of(javaProject);
} else {
return Optional.absent();
}
} catch (CoreException e) {
@vorburger
vorburger / first_eclipse.org_xtext_gerrit
Created February 8, 2014 16:34
My first contribution to Xtext on Eclipse.org via Gerrit
vorburger@yoko:~/git/org.eclipse.xtext$ git push origin
Counting objects: 21, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (11/11), 1.01 KiB | 0 bytes/s, done.
Total 11 (delta 6), reused 0 (delta 0)
remote: Resolving deltas: 100% (6/6)
remote: Processing changes: new: 1, refs: 1, done
remote: ----------
remote: Reviewing commit: commit 04b2c6347d0ae4b20ff3a3749120568a9f772322 1391876867 ----sp
package ch.vorburger.xtext.utils;
import java.io.File;
import java.util.Collection;
import org.apache.commons.io.FileUtils;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
/**
* Copyright (c) 2014 Michael Vorburger and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors: Michael Vorburger - Initial API and implementation
*/
@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
#!/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 / 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 {
@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 / 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 / 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() {