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 […]
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(); […]
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 […]
A regular expression to replace all ampersands (&) in a text that are not part of an entity: t = t.gsub(/&(?!#?\w+;)/, ‘&’)t = t.gsub(/&(?!#?\w+;)/, ‘&’) Language is ruby. The regexp feature used is called a negative lookahead.
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 […]