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]

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]

Change the Netbeans Windows Layout

Netbeans, Programming No Comments »

In Netbeans there currently (Version 6.1) is no built-in option to save a windows layout, you can only do a “Reset Windows”  (in the Window menu) to get back to the factory layout.
I’ve been looking for a solution to get a *cough* Visual Studio *cough* like layout (all navigation on the right of the code window) and found a great plugin called Perspective (click this link twice as for some reason on the first click it will give you the plugin home page) that lets you save a layout and switch easily between layouts (er, perpectives). You can’t download it using the Netbeans plugin installer as it’s not signed, so you’ll have to download and install from disk: 

Netbeans_window_layout_perspective_plugin

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

Generating CHM Documentation for RSpec on Rails

Programming, Ruby on Rails No Comments »

RSpec is the king of the BDD hill when it comes to Rails, and the learning curve is quite steep. For Windows developers hooked on CHM documentation, it’s very easy to generate RSpec CHM files by running the command

rdoc -f chm -o chm_folder rspec*

in the

/vendor/plugins

directory of your RoR project where you have installed the RSpec and RSpec on Rails plugins using

ruby script/plugin install http://rspec.rubyforge.org/svn/tags/CURRENT/rspec
ruby script/plugin install http://rspec.rubyforge.org/svn/tags/CURRENT/rspec_on_rails

as described on the RSpec home page.

The resulting CHM is not the prettiest but it’s fully searchable and easier to use than sifting through the online rdocs in your browser.

Update December 5, 2008: RSpec is under heavy development, and installation instructions change frequently, so you should always refer to the rspec home page for details.

RSpec and RSpec for Rails are now gems only so to generate the chm file cd to your gems directory (usually C:\ruby\lib\ruby\gems\1.8\gems), which you can determine by running

gem env

at the command prompt, and then run

rdoc -f chm -o chm_folder rspec* -x helper_spec.rb

helper_rspec.rb has to be excluded as it causes the rdoc generation to hang. Here’s the updated resulting chm file for rspec, raw and unedited.

P.S.: This only works on Windows as it depends on HTML Help Workshop but the chm file can be viewed with other chm viewers. I recommend xCHM for Linux.

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

The Dark Side Revisited - Alternative Color Themes for Visual Studio

Programming, Visual Studio 7 Comments »

Developers have been experimenting with darker color schemes for Visual Studio, aiming to port their beloved Textmate or Vim environment to other IDEs including VS.

The Textmate Vibrant Ink theme was ported for Visual Studio and recently improved. Zenburn was ported from Vim to Visual Studio.

Collections of other dark color themes can be found here, here, and here. Some like them, some don’t.

I was in the latter group until recently. That was when I came across the Aloha scheme for Netbeans 6, which is based on the work of Carmelyne Thompson inspired by the RubyRobot scheme for Textmate.

I find the colors very enchanting so I went ahead and created an approximation of the Aloha theme for Visual Studio. I made the following changes:

  • Changed the font to Consolas 10 from Monaco 12. You can download the “original” Monaco font for Windows here.
  • Changed the green (102,153,51) strings to a light blue (191,191,255).

Please note that this a just and approximation and not an exact port for every language. Then again, why should it be? You can tweak the settings yourself quite easily in Options>Environment>Fonts and Colors.

Here’s a screen shot:

image

You can download the vssettings file and import it in Tools>Import and Export Settings…

In Visual Studio 2005 you will get a message similar to this:

The file x.vssettings was created with an unsupported version of this application and cannot be added to the settings file list.

Simply open the file in Notepad and replace

<ApplicationIdentity version=”9.0″/>

with

<ApplicationIdentity version=”8.0″/>

and it should import just fine.

One more thing: When you export the font and color settings, deselect all settings first and then just select Options>Environment>Fonts and Colors, so that the Export dialog looks like so:

 image

Enjoy!

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