All posts tagged with 'Code Snippets'

Java: Creating a Stream on a ByteBuffer

18-Oct-07

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, […]

Read the complete article »

Grails 0.6: Modifying JavaScript Libraries

19-Sep-07

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 […]

Read the complete article »

Don’t make that sad smilie cry even more

22-Aug-07

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.

Read the complete article »

Rails’ respond_to method

06-Aug-07

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 […]

Read the complete article »

JComboBoxes auf maximale Größe bringen

09-Nov-06

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() { […]

Read the complete article »