places to eat, the best deals around, perl, ruby on rails, cars and things that make life living for
Pages
▼
Sunday, August 21, 2011
Bad experience shopping with Baby Bunting, Bentleigh East
Tried to give us a cheaper mattress in our cot, and pram delivered without promised raincover
Bought a cot and COMBI pram went to pick it up in Baby Bunting, Bentleigh East on Saturday, 20.7.2011
1) The mattress was not the one which we paid for (in fact, it was a lower grade one when we rung up to check) . We had to bring the mattress in today (21.7.2011) to get the right one
2) The pram we bought during layby period had a free raincover included. When we picked up the pram, the rain cover was missing (21.7.2011). This meant we had to make another trip back to the shop within the same day. Given that the layby started a few months ago, and we were assured that the rain cover has been put aside, it makes me wonder if the staff meant their words
3) The store man we dealt with (tall, fairly old, NZ accent) on 20.7.2011 was not only unhelpful, but was very rude when we wanted to pick our cott and pram. We couldn't fit everything in the end into our car. We could only put the mattress and pram in the car's boot but when we ask that he mark the remaining pieces of the cot (which we would come back to pick up the next day) & communicate with the front counter that there's still items to be picked up, he refused.
As per point (2), we had to return to the store to get the raincover.
When we checked with the manager, Sue at the counter, it was shown in the system that EVERYTHING had been picked up. Lucky we went back for the second time. Otherwise, there would be another drama the next day when we picked up the remaining pieces of the cot.
I thought I paid good money for good, honest and reliable service.
Very, very, very dissappointed.
Tuesday, August 16, 2011
Having problems installing rails 3 on dreamhost shared hosting?
I encountered a fair few problems as i figured i give dreamhost's shared hosting facilities a go.
One of the problems was installing rails 3 itself.
Read around google and used the command below:
"gem install rails --no-rdoc --no-ri"
Worked as expected :) Installation successful.
Successfully installed rails-3.0.9
1 gem installed
I encountered a fair few problems as i figured i give dreamhost's shared hosting facilities a go.
One of the problems was installing rails 3 itself.
Read around google and used the command below:
"gem install rails --no-rdoc --no-ri"
Worked as expected :) Installation successful.
Successfully installed rails-3.0.9
1 gem installed
Saturday, August 06, 2011
ruby - the deal with variables
Here's a sample scenario:
Base class: Product
Sub-classes that inherit from base class: Electronic, Clothing, MusicalInstrument, Food
local variables
p exchange_rate
>> nil
- the reason why this is returning nil is because exchange_rate was a local variable within the expression but given that defined never runs any expression, the value of the 2.5 was in the scope of the defined expression only
>> "method"
instance variables
class variables
Variable names - ruby 1.9 and above now support utf 8
Here's a sample scenario:
Base class: Product
Sub-classes that inherit from base class: Electronic, Clothing, MusicalInstrument, Food
local variables
- does not get set to nil prior to initialisation
- to declare one, just put a underscore in front of the name OR just the name itself (no "@" or "@@").
- they come to live only when they are assigned with a value (initialisation)
- its scope is limited to the block which it is in
- helper method: defined?( expression/argument ). Thanks to Shane Hanna for passing me this link for a better understanding of the method :)
- it will return the type of expression or argument is otherwise the value, nil.
p defined?( exchange_rate = 2.5; end )>> expression
- if given an expression, please note that defined DOES NOT RUN the expression. It just tries to figure out what it actually is
p defined?(exhange_rate = 2.5); end)>> expression
p exchange_rate
>> nil
- the reason why this is returning nil is because exchange_rate was a local variable within the expression but given that defined never runs any expression, the value of the 2.5 was in the scope of the defined expression only
- the argument is usually a single identifier. For example, a variable
def store_name; end;puts defined.store_name;
>> "method"
- Refererence: http://www.rubyist.net/~slagell/ruby/localvars.html
instance variables
- gets set to nil before it's used for the first time
- i would call them "private" or "attribute variables" of a class
- if you've done C++ or java, think of instance variables as variables with a private scope for which class accessor and mutator methods are used to interact with these variables (encapsulation virtue of object oriented programming)
- example: name of each Electronic, MusicalInstrument, Clothing, Food class. Say if stratocaster and telecaster were objects which instantiated from the Electronic class, its name and description attributes are instance variables. ** Telecaster and stratocasters are musical instruments
- Reference: http://www.rubyist.net/~slagell/ruby/instancevars.html
class variables
- gets set to nil before it's used for the first time
- scope is limited to the class and all its instances hence they are shared between all instances of the class
- to declare one, just prepend a "@@" symbol in front of the variable's name
- example: @@government_tax variable that is the same across all products being sold in a store. For Australia, the government tax (aka gst) is 10% across the board
global variables
- append a "$" to the name of the variable
- scope - available to the whole application/program
- it gets initialised to nil automaticall
- Reference: http://www.rubyist.net/~slagell/ruby/globalvars.html
constants
- begins with a letter within A-Z
- it can be reassigned but ruby will issue a warning. In perl, doing so is impossible as the interpreter restricts further assignments after the initial assignment
Variable names - ruby 1.9 and above now support utf 8
- this means that we are no longer restricted to a-zA-Z characters for variable names
- one way to explicitly have ruby select utf-8 for encoding is to have the comment, "# encoding: utf-8" at the top of the script (usually after "#!/usr/bin/ruby")
- prior to ruby 1.9, local variable names have to begin with a letter within a-z
- with ruby 1.9 onwards, utf 8 encoding is supported
- Credits to Shane Hanna's example and Ruby 1.9's Three Default Encodings
Good reference(s):
Thursday, August 04, 2011
ruby: strings and symbols
Symbols, is something that does not exist in perl. After reading a few good books and articles online,
I now have an understanding of symbols.
Symbols are of the Symbol class and they represent themselves just like how integers represent themselves.
For example, the number three, "3". You can't assign it anything yet you can use it.
Symbols are pretty much like a "refactored" data type of the language. Why?
Well, symbols can be used over and over again without causing memory footprints to increase.
For example, in an application that deals with address book contacts, throughtout the code, you will be declaring strings in hashes to represent "first_name", "last_name", "email" and "contact_number".
For every entry, your program has to create 5 units of memory for just the attributes.
Imagine if you had X entries. That would be 5X memory units.
In ruby, when you declare something as a symbol, it can be used over and over again.
So, in this case, you declare those attributes as symbols by sticking a colon in front of them and you have symbols.
Symbols, is something that does not exist in perl. After reading a few good books and articles online,
I now have an understanding of symbols.
Symbols are of the Symbol class and they represent themselves just like how integers represent themselves.
For example, the number three, "3". You can't assign it anything yet you can use it.
Symbols are pretty much like a "refactored" data type of the language. Why?
Well, symbols can be used over and over again without causing memory footprints to increase.
For example, in an application that deals with address book contacts, throughtout the code, you will be declaring strings in hashes to represent "first_name", "last_name", "email" and "contact_number".
For every entry, your program has to create 5 units of memory for just the attributes.
Imagine if you had X entries. That would be 5X memory units.
In ruby, when you declare something as a symbol, it can be used over and over again.
So, in this case, you declare those attributes as symbols by sticking a colon in front of them and you have symbols.
:first_name, :last_name, :email and :contact_number.
Besides saving space, ruby works faster with symbols as it looks them up faster. This is thanks to its symbol table which it allows the programmer to use (ie. add new symbols to). There's a speed gain there.
The following article painted a good understanding for me. I hope it helps you too.
Wednesday, August 03, 2011
Started to pick up rspec in order to port an existing web application from rails 2.3.8 to rails 3.
As a perl developer for 11 years ( i started before graduation ) and doing test driven development since Realestate.com.au ( say 5 yrs back ), I am very supportive and believe in TDD. My daily work doesn't really involve a clear MVC framework and doesn't believe in TDD or automated regression tests. Anyway, with rails, I have been able to develop a site with minimal tests (Test::Unit with rails 2.3.x) but I figured it's about time I embraced something that's more industry preferred - RSpec and its friend, cucumber.
rspec - view specs
In reference to the Rspec book, I've been a bit confused with some elements of view specs.
1) let()
2) assign()
Looking at page 85's example:":symbol" is being used when it's being called in methods like let but when it's to be used, we loose the ":".
As a perl developer for 11 years ( i started before graduation ) and doing test driven development since Realestate.com.au ( say 5 yrs back ), I am very supportive and believe in TDD. My daily work doesn't really involve a clear MVC framework and doesn't believe in TDD or automated regression tests. Anyway, with rails, I have been able to develop a site with minimal tests (Test::Unit with rails 2.3.x) but I figured it's about time I embraced something that's more industry preferred - RSpec and its friend, cucumber.
rspec - view specs
before()
-any source code found here will run before the tests/specs
-there are 3 values for the single argument this method accepts:
- each - this is default. It does get executed for each spec but gains in terms of reliability as instance variable values often get reinitialised
- all - this gets run exactly once. Its instance variables will be shared across with other specs. The danger here is that if specs change the values of instance variables, this could result in unwanted states of the instance variables
- scope
In reference to the Rspec book, I've been a bit confused with some elements of view specs.
1) let()
2) assign()
Looking at page 85's example:":symbol" is being used when it's being called in methods like let but when it's to be used, we loose the ":".
describe Game do
let( :output ) { .... } <---- the contents of the block are assigned to the symbol, :output
let(:game) {......}
describe "start game" do
it "sends a welcoming message" do
output.should_receive(:puts) .... <---- observe how output is used without the ":"
game.start('player name')...
-----------
it's a hard one to stomach and utterly stupid but I think it's one of those things (the rails way).
Similar to our example,
describe "parts/new.html.erb" do
let(:part) { <----- the mocked model mocking operation is assigned to a method with the symbol of :part. I think it's because the mocked model is to be assigned to the @part instance variable in the view (also refered to as :part in the current spec's scope)
mock_model('Part').as_new_ record.as_null_object
}
before do
assign(:part, part) <---- :part refers to the part var in spec (@part in view), whilst 'part' at the end refers to just the part method in let.. Really stupid - i know.
end
it "renders a form to add a new part" do
render
render.should have_selector( "form",
:method => "post",
:action => parts_path,
) do |form|
form.should have_selector("input", :type => "submit")
end
end
it "renders input fields to add a new part" do
part.stub("title"=> "HKS EVC boost controller")
render
rendered.should have_selector( "form" ) do |form|
form.should have_selector( "input",
:type => "text",
:name => "part[title]",
:value => "HKS EVC boost controller"
)
end
end
end
I'm awaiting for some clarification on this. Will be interesting to post back what's going on...