Skip to content

Instantly share code, notes, and snippets.

View koert's full-sized avatar

Koert Zeilstra koert

View GitHub Profile
@koert
koert / absolute-position.html
Created September 6, 2012 13:07
Absolute/relative positioning
<p:outputPanel layout="block" style="position: relative;">
<div style="position: absolute; top: 0.5em; right: 0.5em; z-index: 10;">
</div>
</p:outputPanel>
@koert
koert / HtmlToText.java
Last active March 26, 2020 16:10
Extract plain text from HTML
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.parser.ParserDelegator;
final StringBuilder sb = new StringBuilder();
HTMLEditorKit.ParserCallback parserCallback = new HTMLEditorKit.ParserCallback() {
public boolean readyForNewline;
@koert
koert / TestService.java
Created July 5, 2015 07:52
Example REST service implemented with JAX RS
import javax.annotation.ManagedBean;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.xml.bind.annotation.XmlRootElement;
/**
* JAX RS implementation of REST logfile service.
@koert
koert / HelloRepository.java
Created July 5, 2015 07:55
Example repository that produces a greeting
/**
* Example repository.
* @author Koert Zeilstra
*/
public class HelloRepository {
/**
* @return Example greeting.
*/
public String getGreeting(String name) {
return "Hello world " + name;
@koert
koert / minimal-web.xml
Created July 5, 2015 07:56
Minimal web.xml for servlet 3.0
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>test-service</display-name>
</web-app>
@koert
koert / minimal-beans.xml
Created July 5, 2015 07:57
Minimal beans.xml
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>
@koert
koert / TestServiceApplication.java
Created July 5, 2015 07:58
JAX RS application configuration
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
/**
* Application configuration.
* See https://stackoverflow.com/questions/23508159/jax-rs-glassfish-eclipse-a-simple-web-service-doesnt-work
* @author Koert Zeilstra
*/
@ApplicationPath("/")
public class TestServiceApplication extends Application {
}
package test;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
package enterprise.programmatic_login;
import java.io.*;
import java.net.*;
import javax.annotation.security.DeclareRoles;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Copied from https://docs.oracle.com/javaee/6/tutorial/doc/gjiie.html
/**
* Repository for authentication.
* @author Koert Zeilstra
*/
@ApplicationScoped
public class AuthenticationRepository {
private Map<String, AuthenticationToken> tokenCache = new HashMap<>();
public Optional<AuthenticationToken> authenticateUser(String userName, String password) {