Feeds:
Posts
Comments

Archive for the ‘Ruby and Ruby On Rails’ Category

I was working with struts validators and need to test a phone number to be digits and starts with a leading 00, I wanna share it here

^00+\d{9,17}$

below is a ruby code snippet:

phone_no=”009621111111″

if phone_no =~ /^00+\d{0,9}$/

puts “match”

else

puts “No match”

end

a quick explain is

^ start from the beginning of the string

+\d{9,17} should include digits with at least 9 digits and at most 17 digits (excluded the leading 00)

$ indicates the end of the string

well, that was not much, but I wish it save someone’s 10 minutes!

Cheers

Read Full Post »

Today I installed Netbeans 6 and my first Impression is Wow! I will be posting in-depth look at netbeans-6.0 later.

but, what is new on netbeans-6.0?

Editor Improvements

  • Smarter code completion
  • Highlights
  • Better Navigation and Inspection
  • Live Templates and Surround Functionality

Ruby/JRuby/Ruby on Rails Support

  • Project support including Gems and RSpec
  • Advanced Ruby Editing
  • ActiveRecord Code Completion
  • Ruby Debugger
  • Ruby on Rails Support

Profiling

  • Profiler integrated into NetBeans IDE
  • Compare Memory Snapshots
  • Heap Walker
  • JMeter Integration
  • Dynamic Attach on JDK 1.6

Web and Java EE

  • Built-in visual design for web applications
  • Visual page flow editing
  • Enhanced JavaScript support
  • Enhanced web services support
  • Support for Ajax-enabled JavaServer Faces components

Mobility

  • New Integrated UI for CLDC/MIDP and CDC development
  • New game builder
  • New Visual Mobile Designer
  • Re-written JSR-172 stub compiler

SOA

  • Artifacts for service composition and assembly
  • Graphical WSDL editor
  • XSLT editor to edit transformations.
  • Tooling support for binding components
  • Java EE Web Service project support

Check out NetBeans 6.0 Released with Support for Ruby, Mobility Enhancemens, and Integrated Profiles

Read Full Post »

Ruby and Yaml

Yaml (Yet Another markup language) allows developers to serialize and deserialize Object to files and still human readable and editable. in short!

I will explain how to load, save, update yaml file using ruby (Yaml4r). a sample source code can be found at the end of this article

As always: busy developer walk through:

  • Installation
    • gem install RbYAML
  • Usage
    • Tip! you can serialize any object to yaml files (well, user defined object need more extra steps); now we load, flush, and update an object – all by yaml file:
      • Step One: loading object from yaml file
        obj = YAML::load(File.open(‘test.yaml’));
      • Step Two: modifying/creating the object (which is an array) and save it back to the file:
        obj << ‘anything’ File.open(‘test.yaml’, ‘w+’) { |out| YAML::dump(obj, out)}

require ‘yaml.rb’

obj = YAML::load(File.open(‘test.yaml’))
if obj
obj << ‘anything’
else
obj = [‘anything’]
end

File.open(‘test.yaml’, ‘w+’) { |out|
YAML::dump(obj, out)
}

Read Full Post »

This is a busy developer tutorial that walk through installing ruby on rails on Linux Machine.

get Downloads ready

  • type yum install ruby rdoc irb
  • Rubygems from http://www.rubyonrails.com/down
    • unzip the package.
    • type ruby setup.rb
  • type gem update
  • type gem install rails –include-dependencies
  • choose your lovely database: we will be using mysql for this tutorial; so, that requires us to install mysql
    • type yum install mysql mysql-server mysql-devel
    • type gem install mysql
      if you got some error of compiling native blah blah … the check you have GCC installed, and you may use some options like the following:
      gem install mysql — –with-mysql-include=/usr/include/mysql –with-mysql-lib=/usr/lib/mysql

Testing your installation

  • go to path of your choose.
  • type rails <your project name> you will notice a new folder created. cd it!
  • type ./script/server and go to your browser http://localhost:3000 ; if you see RoR welcome page. then you are there. Congratulations.

Read Full Post »