All posts tagged with 'Code Snippets'

Enabling tooltips on a JTree

12-Aug-08

Thinks i keep forgetting. Today: Enabling a JTree in J2SE to show different tooltips on his nodes: 1. Create a custom tree renderer like so: import java.awt.Component;   import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer;   public class TooltipTreeRenderer extends DefaultTreeCellRenderer { @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int […]

Read the complete article »

regex: URL thingy with username, password, host and port

07-Jul-08

Just in case i do keep forgetting that stuff, here’s a regex for decoding urls like ftp://user:somepass@somehost:someport in Java: final Hashtable<String, Integer> portMap = new Hashtable<String, Integer>(); portMap.put("ftp", 21); portMap.put("sftp", 22);   final Pattern urlPattern = Pattern.compile("(ftp|sftp)://(\\S+):(\\S+)@([\\S&&[^:]]+)(:(\\d+))?");   final Matcher m = urlPattern.matcher(url); if(!m.matches()) throw new RuntimeException("Invalid ftp url!");   final String protocol = m.group(1).toLowerCase(); […]

Read the complete article »

PDF::Writer and Ruby on Rails 2.1

04-Jun-08

Some days ago, Ruby On Rails 2.1 saw the light of day and as usual, i eagerly updated my Daily Fratze project. I had some minor problems due to an old version of will_paginate and some major ones with my use of PDF::Writer. The PDF::Writer library still works very well but the the instructions here […]

Read the complete article »

Ampersands and XHTML

25-May-08

A regular expression to replace all ampersands (&) in a text that are not part of an entity: t = t.gsub(/&(?!#?\w+;)/, ‘&amp;’)t = t.gsub(/&(?!#?\w+;)/, ‘&amp;’) Language is ruby. The regexp feature used is called a negative lookahead.

Read the complete article »

Patching wp-cache for more security

04-Apr-08

I use wp-cache on all my blogs all the time. No need waiting for being slashdotted or heised. But wp-cache comes with a security flaw. It requires the webserver to have write access on $WP_HOME/wp-content/cache and $WP_HOME/wp-content. The first part is perfectly reasonable, the second not. wp-cache creates it’s wp-cache-config.php in that place and edits […]

Read the complete article »