Skip to content

Instantly share code, notes, and snippets.

View phansson's full-sized avatar

lbruun phansson

View GitHub Profile
@phansson
phansson / !README.md
Last active August 27, 2017 20:16
Windows EXE utils for Java

Windows .exe utilities

Reads the machine type field from a Windows .exe file. From this we can determine 32-bit vs 64-bit as well as a couple of other things.

@phansson
phansson / !README.md
Created February 26, 2017 20:21
SafeHtml utility class for making strings safe to use in HTML

SafeHtml

This small Java class is a utility class for escaping strings so that they are safe to use in HTML. There's a single static method, htmlEscape(), which does the job.

I've found that all existing solutions (libraries) I've reviewed suffered from one or several of the below issues:

  • They escape too much ... which makes the HTML much harder to read and takes longer time.
  • They don't tell you in the Javadoc exactly what they replace.
  • They do not document when the returned value is safe to use (safe to use for an HTML entity?, for an HTML attributute?, etc)
@phansson
phansson / watchdir.c
Created August 9, 2015 16:20
Solaris File Events Notification working example
/* ************************************************************************
* watchdir.c
*
* watchdir uses Solaris' File Event Notification system to monitor
* a directory for changes. It is in this respect similar in use case
* to Linux's inotify-tools.
*
* This method of monitoring a directory is far superior to any
* alternative that would probably use looping and some sort of polling.
*