Netbeans Regular Expressions Find and Replace

Netbeans, Programming, Quanta Plus No Comments »

Powerful find and replace with regular expressions should be the hallmark of every IDE worth its mettle. MS Visual Studio does it so-so, but lo and behold, Netbeans (at least in version 6.1) is even worse.

So I wanted to put foo at the beginning of every line in a text, which calls for a regex like:

^.*

and replace like:

foo $0

However, Netbeans only ever replaces the first match in a text, over and over again. It also hangs up easily in the process.

As with many a Netbeans quirk, it’s Quanta Plus to the rescue again:

Quanta_plus_utf-10

Works like a charm.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

HTML List Items in Two or More Columns without and with Rails

Ruby on Rails No Comments »

Table avoidance is raging on in contemporary HTML design and nobody wan’t to be caught with an unnecessary table on their pages. This may go to far or not, but to display data in multiple columns without resorting to a table you can proceed like this:

<ul class=”lst”>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>

Then make the ul 100% wide and the list items (li) 50% or 33% or 25% or whatever and float them left (fixed values in pixels or ems work as well):

<style type=”text/css”>
.lst
{width:100%}
.lst li
{width:25%;float:left;}
</style>

Here’s the result:

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

However, the progression and count of the list is horizontal while the user expects it vertical, with his view naturally moving down and then to the next column. There is a plethora of css artistry involved in getting this to work cleanly and with just CSS and sometimes JavaScript, see this article for a treat(ment).

In Rails of course you can easily create multiple lists with the in_groups_of method and float them left to line up horizontally:

<% ar = (1..12).to_a; number_of_columns = 3 %>
<div style=”width:100%”>
<% ar.in_groups_of(ar.size/number_of_columns) do |column| %>
<ul style=”width:33%;float:left;”>
<% for item in column %>
<li>
<%= item  %>
</li>
<% end %>
</ul>
<% end %>
</div>

If you need an ordered list (ol) you could set the start attribute programmatically with each new list, but then again the start attribute is deprecated and your mileage may vary. The quoted article has a complex but workable CSS solution. Hope it helps.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Populate an ActiveRecord Model with Images Using attachment_fu

Programming, Ruby on Rails No Comments »

Is there anything more painful than manually populating your model with sample data? The thought alone makes most developers’ skin scrawl because we write code to do the work for us and abhor manually entering fugacious data.

As always, first things first, watch the relevant Railscast, which will introduce you to populator and faker, both great tools you will soon find indispensable. And here’s a little rake task to populate your model with images, useful to see how it looks with product thumbnails or the like. This is just sample code which you should edit to suit your needs. And attachment_fu has to be configured and working. The file, which could be named attachment_populate.rb belongs in the lib/tasks/ directory:

namespace :attachment do
  desc "Add an image to all MyModel items for visual checking"
  task :add_image_to_all_mymodels  => :environment do
    require 'action_controller'
    require 'action_controller/test_process.rb'
    path = "#{RAILS_ROOT}/public/images/samples/sample.jpg"
    mimetype = "image/jpeg"
    MyModel.find(:all).each do |mymodel|
      @attachment = Attachment.new(:uploaded_data => ActionController::TestUploadedFile.new(path, mimetype))
      @attachment.mymodel_id = mymodel.id
      @attachment.save
    end
  end
end

Call with

rake attachment:add_image_to_all_mymodels

The pertinent documentation is in the #{RAILS_ROOT}/vendor/plugins/attachment_fu/README under “attachment_fu scripting”:

# required to use ActionController::TestUploadedFile
require ‘action_controller’
require ‘action_controller/test_process.rb’

path = “./public/images/x.jpg”

# mimetype is a string like “image/jpeg”. One way to get the mimetype for a given file on a UNIX system
# mimetype = `file -ib #{path}`.gsub(/\n/,”")

mimetype = “image/jpeg”

# This will “upload” the file at path and create the new model.
@attachable = AttachmentMetadataModel.new(:uploaded_data => ActionController::TestUploadedFile.new(path, mimetype))
@attachable.save

 And where do you get more info about creating rake tasks? Railscasts of course, who needs books?

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Scroll Wheel Function for the Marble Mouse on Linux

Computing, Linux 7 Comments »

Update: Since Ubuntu 8.10 “Intrepid Ibex” Hal has superseded xserver/xorg.conf as the preferred means to configure input devices.  This post has the settings for hal, and they work just like the old xorg.settings outlined in the original post. Migration to hal will likely bring benefits for most, such as plug-and-play hot plugging. You might want to check out this writeup before taking the plunge.

Original post (applies to xserver/xorg.conf < Ubuntu 8.10):

As you know I consider the Logitech Marble Mouse the Best Pointing Device, bar none. And the final tweak I wanted to enable the trackball to act as a scroll wheel. For Windows and those suffering from the generally horrid Logitech drivers and utilities (SetPoint anyone?), there’s Marble Mouse Scroll Wheel (original download page seems to be down recently, so here is another download link). But for my installation of Linux Mint/Ubuntu I had tried some advice from the web without success, to the point when X failed to load. Finally the approach suggested by linux (USA) in his Amazon review worked. It lets you use the right small button as a paste button and holding the left small button will let you use marble/ball as an omnidirectional scroll wheel. Here it goes:

You must edit your /etc/X11/xorg.conf file (dont’ forget to backup with cp xorg.conf xorg.conf.bak), for xorg 6.8 the relevant settings look like this:

Section “InputDevice”
Identifier “Configured Mouse”
Driver  “mouse”
Option  “CorePointer”
Option  “Device”  “/dev/input/mice”
Option “Protocol” “ExplorerPS/2″
Option “Buttons” “5″
Option “YAxisMapping” “4 2″
Option “XAxisMapping” “6 7″
Option “EmulateWheel” “yes”
Option “EmulateWheelButton” “4″

EndSection

You also need to create an ~/.xmodmap file in your home directory and enter:

pointer = 1 5 3 4 2 6 7

With xorg 7.2 (released 15th Feb. 2007) and newer you have to remove the “YAxisMapping” and change the “EmulateWheelButton” to “8”, so that the entire section looks like this:

Section “InputDevice”
Identifier “Configured Mouse”
Driver  “mouse”
Option  “CorePointer”
Option  “Device”  “/dev/input/mice”
Option “Protocol” “ExplorerPS/2″
Option “XAxisMapping” “6 7″
Option “EmulateWheel” “yes”
Option “EmulateWheelButton” “8″

EndSection

Your ~/.xmodmap file will have to contain this:

pointer = 1 9 3 4 5 6 7 8 2 10 11

instead of the above. The protocol setting “ExplorerPS/2” is also important to get the buttons to work even though the device is connected via USB.

To enable horizontal scrolling in Firefox you’ll have to go to the about:config page and set:

mousewheel.horizscroll.withnokey.action 0

The ~/.xmodmap file will likely be loaded automatically when you start your system, but if not you might have to create a ~/.xinitrc file. This page has more info, and here’s more info about monitoring your buttons using the xev utility. Hope it helps.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in