This example is plain wrong. The InputStream will cause an endless loop as it always returns a value >= 0. Working code as follows: private static InputStream _newInputStream(final ByteBuffer buf) { return new InputStream() { public synchronized int read() throws IOException { return buf.hasRemaining() ? buf.get() : -1; } public synchronized int read(byte[] bytes, […]
Grails has a good mechanism for including JavaScript Libraries to do all that fance Ajax stuff. It all starts with: <g:javascript library="scripaculous" /><g:javascript library="scripaculous" /> Library can be one of yahoo, prototype, dojo, scriptaculous or rico. It’s a nice fact, that Grails doesn’t force you to use any special of these. I wanted to change […]
Escaping single quotes in ruby is the same mess as in java: puts ":'(".gsub(’\”, ‘\\\\\”)puts ":'(".gsub(‘\”, ‘\\\\\”) I needed this to make the smilies after my comment box (here) clickable. Shortly after that, i found escape_javascript, maybe it still comes in handy.
Ruby On Rails has a neat little feature called “respond_to”: class WeblogController < ActionController::Base def index @posts = Post.find :all respond_to do |format| format.html format.xml { render :xml => @posts.to_xml } format.rss { render :action => "feed.rxml" } end end endclass WeblogController < ActionController::Base def index @posts = Post.find :all respond_to do |format| format.html format.xml […]
Manchmal ist es praktisch, wenn eine JComboBox keinen Scrollbalken mehr hat. Ist bei extrem vielen Einträgen natürlich nicht sinnvoll, aber bei einer überschaubar großen Zahl schon: iimport javax.swing.JComboBox; public class Blah { public void blub() { final JComboBox combo = new JComboBox(); combo.setMaximumRowCount(combo.getModel().getSize()); } }iimport javax.swing.JComboBox; public class Blah { public void blub() { […]