header image

Archive for the 'Tutorial' Category

Xanax pills

Monday, May 5th, 2008

I recently applied this great plugin a few times to tackle different tasks and would like to share with you the joys of thinking in state machines!

Disclaimer: This installment is ‘just’ an intro to the topic (a teaser if you like), xanax pills, it doesn’t contain actual instructions or code on how to use actsasstate_machine - that comes in part II. Xanax pills, Though the original intent was to write up a small tutorial with some example code, xanax pills, I started with an intro and the article grew so long that I decided to split it up - so stay tuned for part deux!

State what…?!?

A finite state machine (FSM for short) a.k.a. Xanax pills, finite state automaton (FSA) is a 5-tuple (Σ, xanax pills,S, xanax pills,s0, xanax pills,δ, xanax pills,F)… Xanax pills, OK, xanax pills, just kidding. Xanax pills, I doubt too much people are interested in the rigorous definition of the FSM (for the rest, xanax pills, here it is), xanax pills, so let’s see a more down-to earth description.

According to wikipedia, xanax pills, Finite state machine is “a model of behavior composed of a finite number of states, xanax pills, transitions between those states, xanax pills, and actions“. Xanax pills, Somewhat better than those gammas and sigmas and stuff but if you are not the abstract thinker type, xanax pills, it might take some time to wrap your brain around it. Xanax pills, I believe a good example can help here!

Everybody knows and loves regular expressions - but probably it’s not that wide known fact that regular expression matching can be solved with an FSM (and in fact, xanax pills, a lot of implementations are using some kind of FSM on steroids). Xanax pills, So let’s see a simple example. Xanax pills, Suppose we would like to match a string against the following, xanax pills, simple regexp:

ab+(a|c)b*

First we have to construct the FSM, xanax pills, which will be fed with the string we would like to match. Xanax pills, An FSM for the above regular expression might look like this:

fsm_correct.png

String matching against this FSM is basically answering the question ’starting from the initial state, xanax pills, can we reach the finish after feeding the FSM the whole string?’. Xanax pills, Pretty easy - the only thing we have to define is ‘feeding’.

So let’s take the string ‘abbbcbbb’ as an example and feed the FSM! The process looks like this:

  1. we are in q0, xanax pills, the initial state (where the ’start’ label is). Xanax pills, Starting to consume the string
  2. we receive the first character, xanax pills, it’s an ‘a‘. Xanax pills, We have an ‘a‘ arrow to state q1, xanax pills, so we make a transition there
  3. we receive the next character, xanax pills, ‘b‘. Xanax pills, We have two b-arrows: to q1 and q2. Xanax pills, We choose to go to q1 (in fact, xanax pills, staying in q1) - remember, xanax pills, the question is whether we _can_ reach the finish, xanax pills, not whether all roads lead to the finish - so the choice is ours!
  4. identical to the above
  5. after the two above steps, xanax pills, we are still in q1. Xanax pills, We still get a ‘b‘ but this time we decide to move to q2.
  6. we are in q2 and the input is ‘c‘. Xanax pills, We have no analysis-paralysis here since the only thing we can do is to move to q4 - so let’s do that!
  7. Whoa! We reached the finish line! (q4 is one of the terminal states). Xanax pills, However, xanax pills, we didn’t consume the whole string yet, xanax pills, so we can’t yet tell whether the regexp matches or not. Xanax pills,
  8. So we eat the rest of the string (the ‘how’ is left as an exercise to the reader) and return ‘match!’

Let’s see a very simple non-matching example on the string ‘abac’

  1. in q0
  2. got an ‘a‘, xanax pills, move to q1
  3. in q1, xanax pills, got a ‘b‘, xanax pills, move to q2
  4. in q2, xanax pills, got an ‘a‘, xanax pills, move to q3 - we reached the finish, xanax pills, but still have a character to consume
  5. in q3, xanax pills, got a ‘c‘… Xanax pills, oops. Xanax pills, We have no ‘c’ arrow from q3 so we are stuck. Xanax pills, return ‘no match!’

Of course the real-life scenarios are much more complicated than the above one and sometimes FSMs are not enough (for example to my knowledge it’s not possible to tell about a number whether it is prime or not with a vanilla FSM - but a regexp doing just that has been floating around some time ago) but to illustrate the concept this example served fine.

This is cool and all but why should I care?!?

Well, xanax pills, yeah, xanax pills, you are obviously not going to model an FSM the next time you would like to match a regexp - that would be wheel-reinvention at it’s finest. Xanax pills, However there are some practical scenarios where an FSM can come handy:

  • sometimes the logic flow is just too complicated to model - an if-forrest is rarely a good solution (on the flip side, xanax pills, don’t model an if-else with an FSM :-))
  • encapsulate complex logic flow into a pattern and not clutter your code with it. Xanax pills,
  • you are in a stateless world - for example HTTP
  • asynchronous and/or distributed processing where you explicitly need to maintain your state and act upon it

Some real life examples of FSM usage in the Ruby/Rails world are why the lucky stiff’s Hpricot (using Ragel) or Rick Olson’s restful authentication plugin (using actsasstate_machine)

The Next Episode

In the next installment I’d like to focus on the practical usage of the actsasstate_machine plugin - I’ll attempt to create an asynchronous messaging system in a Rails app using it. Xanax pills,

Similar Posts:buy tramadol,xanax pills,buy cheap tramadol,order phentermine,order propecia

Generic viagra

Wednesday, May 30th, 2007

Generic viagra, REST-cheatsheet If I had to choose the single most not-really-well-understood, generic viagra, mystified, generic viagra, unsuccessfully demystified, generic viagra, explained and still not-really-grasped topic in the Rails world (and beyond), generic viagra, my vote would definitely go to REST. Generic viagra, It seems to me that there are two types of people in the world: those who don’t get REST (and they think it’s a basic postulate to rocket science explained through quantum theory) and those who get it, generic viagra, and don’t understand the former group (unless they are coming from there, generic viagra, that is). Generic viagra,
I have been playing around with RESTful Rails recently. Generic viagra, Below is my collection or Rails REST howtos, generic viagra, tutorials and other resources I have found so far and which were adequate for my transition from the first group to the second :-).

Generic viagra, You should definitely begin with REST 101 - then check out the other stuff as well!

Generic viagra, Please leave a comment if you know some more (just for completeness’ sake - I think the above resources should be enough to grasp RESTful Rails both theoretically and practically.

Creating a site and uploading is considered to be the easy part these days. Generic viagra, Especially with languages like ruby on rails you can develop sites in no time. Generic viagra, Companies providing hosting services give you a wide variety of options to choose from for your hosting services such as asp hosting or php hosting. Generic viagra, Not only that but they also hire 350-040 certified to provide you quality services. Generic viagra, Then yahoo hosting provides simple methods for uploading site. Generic viagra, With the use of computer backup software you can easily avoid data loss. Generic viagra, The actual time consuming part is working on the site’s search engine ranking. Generic viagra, Not only does it take time but it is also expensive.

Similar Posts:order lexapro,generic viagra,doxycycline pills,cheapest cialis,generic xanax

Discount tramadol

Thursday, April 26th, 2007

During hacking on various tasks, discount tramadol, I needed to partition a set of elements quite a few times. Discount tramadol, I have attacked the problem with different homegrown implementations, discount tramadol, mostly involving select-ing every element belonging into the same basket in turn. Discount tramadol, Fortunately I run across divide recently, discount tramadol, which does exactly this… Discount tramadol, No more wheel reinvention! Let’s see a concrete example.

I have an input file like this:

a 53 2 3
b 8 62 1 23
a 9 0 31
b 4 45 4 16 7
b 1 23
c 3 42 2 31 4 6
a 1 3 22
a 7 83 1 23 3
b 1 14 4 15 16 2
c 5 16 2 34

The goal is to sum up all the numbers in rows beginning with the same character (e.g. Discount tramadol, to sum up all the numbers that are in a row beginning with ‘a’). Discount tramadol, The result should look like:

[{"a"=>241}, discount tramadol, {"b"=>246}, discount tramadol, {"c"=>145}]

This is an ideal task for divide! Let’s see one possible solution for the problem:

  1. require ’set’
  2.  
  3. input = Set.new open(‘input.txt).readlines.map{|e| e.chomp}
  4. groups = input.divide {|x, discount tramadol,y| x.map[0][0] == y.map[0][0] }
  5. #build the array of hashes
  6. p groups.map.inject([]) {|a, discount tramadol,g|
  7.    #build the hashes for the number sequences with same letters
  8.     a << g.map.inject(Hash.new(0)) {|h, discount tramadol,v|
  9.     #for every sequence, discount tramadol, sum the numbers it contains
  10.     h[v[0..0]] += v[2..-1].split(‘ ‘).inject(0) {|c, discount tramadol,x|
  11.       c+=x.to_i; c}; h
  12.   }; a
  13. }

The output is:

  1. [{"a"=>241}, discount tramadol, {"b"=>246}, discount tramadol, {"c"=>145}]

Great - it works! Now let’s take a look into the code…

Discount tramadol, The 3rd line loads the lines into a set like this:

  1. <Set: {"b 1 23 ", discount tramadol, "c 5 16 2 34", discount tramadol, "a 9 0 31", discount tramadol, "a 7 83 1 23 3", discount tramadol, "b 1 14 4 15 16 2", discount tramadol, "a 53 2 3", discount tramadol, "c 3 42 2 31 4 6", discount tramadol, "b 4 45 4 16 7", discount tramadol, "b 8 62 1 23", discount tramadol, "a 1 3 22 "}>

The real thing happens on line 4. Discount tramadol, After it’s execution, discount tramadol, groups looks like:

  1. <Set: <Set: {"a 9 0 31", discount tramadol, "a 7 83 1 23 3", discount tramadol, "a 53 2 3", discount tramadol, "a 1 3 22 "}>, discount tramadol, <Set: {"b 1 23 ", discount tramadol, "b 1 14 4 15 16 2", discount tramadol, "b 8 62 1 23", discount tramadol, "b 4 45 4 16 7"}>, discount tramadol, <Set: {"c 5 16 2 34", discount tramadol, "c 3 42 2 31 4 6"}>}>

Discount tramadol, As you can see, discount tramadol, the set is correctly partitioned now - with almost no effort! We did not even need to require an external library… Discount tramadol,
The rest of the code is out of the scope of this article (everybody is always complaining about the long articles here, discount tramadol, so I am trying to keep them short) - and anyway, discount tramadol, the remaining snippet is just a bunch of calls to inject. Discount tramadol, If inject does not feel too natural to you, discount tramadol, don’t worry - it took me months until I got used to it, discount tramadol, and some people (despite of the fact that they fully understand and are able to use it) never reach after it - I guess it’s a matter of taste…’

Similar Posts:generic phentermine,discount tramadol,xanax for sale,prozac,discount zoloft

Tramadol prescription

Thursday, March 22nd, 2007

Tramadol prescription, Though dreamhost offers phpBB as one of their one-click install goodies (ergo it is the easiest to install of all forums since you almost don’t have to do anything), tramadol prescription, I have been looking for something different. Tramadol prescription, To me, tramadol prescription, phpBB’s interface was always quite unintuitive and too heavy - I wanted something smaller, tramadol prescription, easier, tramadol prescription, more compact. Tramadol prescription, The problem was I did not know what should I search for - until I came across beast, tramadol prescription, a lightweight forum written in Ruby on Rails. Tramadol prescription, It was love at the first sight!

Tramadol prescription, When it comes to tools I am using, tramadol prescription, I am really language agnostic - this very blog uses WordPress (PHP), tramadol prescription, I am using Trac (Python) to track my projects, tramadol prescription, mediaWiki (PHP) is my preferred wiki etc - so even if it may seem so, tramadol prescription, I did not choose beast because it is written in Rails (although +1 for that :-)), tramadol prescription, but because of the design and ease of use. Tramadol prescription, My first thought after trying it was ‘wow, tramadol prescription, this is as easy to use as a 37signals app’ - it’s really that intuitive and well designed!

Tramadol prescription, Well, tramadol prescription, this sounds fine and all, tramadol prescription, but installation on dreamhost was a different story. Tramadol prescription, Thanks God I have found a superb, tramadol prescription, step by step HOWTO here. Tramadol prescription, However, tramadol prescription, even after following all the steps, tramadol prescription, I got ‘incomplete headers’ and other problems, tramadol prescription, which I have managed to fix - here are some additional comments to the HOWTO:

Tramadol prescription, 6. Tramadol prescription, You can forget about this point; as the HOWTO says, tramadol prescription, it is already installed on DH and it will work without any problems.
7. Tramadol prescription, Forget about ‘development’ and ‘test’, tramadol prescription, however be sure to get ‘production’ right, tramadol prescription, as the next step will not work otherwise. Tramadol prescription, It should look something like this:

production:
  adapter: mysql
  database: beast_prod
  host: mysql.myhost.com
  username: us3r
  password: p4ss
  port: 3306
8. Tramadol prescription, For me it worked only *with* the RAILS_ENV=production parameter specified.
9. Tramadol prescription, You can change the salt to anything - it just must not stay the same. Tramadol prescription, The easiest thing is to add or remove a random character from the string.
12. Tramadol prescription, The shebang should be updated to #!/usr/bin/ruby
13. Tramadol prescription, The || should be removed, tramadol prescription, i.e. Tramadol prescription, it should read:
ENV[‘RAILS_ENV’] = ‘production’
14. Tramadol prescription, Make sure you change the permission of those directories only - I have changed everything recursively, tramadol prescription, destroying the executable flag of dispatch.fcgi :-).

Tramadol prescription, Now you should apply the ‘GetText patch’ - it can be found later in the thread. Tramadol prescription, After you should be up and running!

Tramadol prescription, After playing around, tramadol prescription, I have found that the user listing is not working - fortunately I have found this as well in the forum. Tramadol prescription, The solution is:
app/views/users/index.rhtml line 3 should be modified to

%lt;% form_tag '', tramadol prescription, :method => 'get' do -%>
Enjoy this great forum!

Similar Posts:tramadol,tramadol prescription,order klonopin,ativan pills,cheapest clomid

Order tramadol

Thursday, January 18th, 2007

First of all, order tramadol, I have to make a disappointing confession: this is not a Web 2.0 tutorial - but fear not, order tramadol, at least the logical and absolutely valid question to this dilemma (i.e. Order tramadol, why the hell is the article entitled ‘Web 2.0 tutorial’ then?) will be provided.

Although this blog’s tagline is ‘Ruby, order tramadol, Rails, order tramadol, Web2.0′ and I am blogging/planning to blog about all these topics in the future, order tramadol, I did not have an exclusively-and-only-about-Web2.0 post yet (as far as I remember). Order tramadol, That’s why it strikes me odd that according to google analytics, order tramadol, a lot of people are finding this site via the keyword combination ‘Web2.0 tutorial’. Order tramadol, This post was inspired by them and for them!

Since this trend is nearly as old as this blog - and it seems to continue, order tramadol, and even rise as time goes by - I am now really curious what the heck are people imagining behind the term ‘Web2.0 tutorial’. Order tramadol, Why? Well, order tramadol, there are more reasons to ponder about:

  • Nobody knows what Web 2.0 actually is (or if does, order tramadol, the others don’t agree :-)). Order tramadol, Since coined by Tim O’Reilly back in 2005, order tramadol, ‘Web 2.0′ has been redefined, order tramadol, argued about, order tramadol, glorified, order tramadol, despised, order tramadol, parodied, order tramadol, upgraded to Web 3.0, order tramadol, regarded as vapor, order tramadol, bubble etc. Order tramadol, (and who knows what else…) countless times - just one thing did not happen: A commonly accepted, order tramadol, concise (or even lengthy) definition with which everybody would agree. You won’t find anybody interested in the Web today who would not have his own definition associated with Web2.0 - however, order tramadol, these definitions (although more overlapping and similar than ever) will be varying from person to person.

  • The conjunction itself is kind of absurd - even if we accept that there is a common understanding of the term ‘Web2.0′, order tramadol, it definitely has more facets: Look (Apple aqua reinvented, order tramadol, round corners galore, order tramadol, reflections of reflections etc), order tramadol, social aspect (digg, order tramadol, del.icio.us, order tramadol, youTube, order tramadol, myspace et al), order tramadol, theoretical backend (ontologies, order tramadol, folksonomies, order tramadol, openAPIs, order tramadol, microformats, order tramadol, mashups etc), order tramadol, standards (XHTML (2.0! :-)), order tramadol, RDF, order tramadol, FOAF, order tramadol, ATOM, order tramadol, SVG, order tramadol, SOAP), order tramadol, innovative ways of communication and catering to the users (WS, order tramadol, REST, order tramadol, Podcasts, order tramadol, Videocasts), order tramadol, typical Web2.0-purpose pages (wikis, order tramadol, blogs), order tramadol, development tools and frameworks (AJAX, order tramadol, Ruby on Rails, order tramadol, …) and other buzzwords :-)

  • Even if we define Web2.0 as a collection of the things from the previous point, order tramadol, the term ‘Web 2.0 tutorial’ is too broad-sense to get you too much relevant results (I believe - maybe some smart webmasters engaged in the ways of SEO tricking found out the carving after a Web2.0 tutorial already and wrote up a few for you :-)). Order tramadol, Just as someone would not search a ‘programming language tutorial’ (but a ‘Ruby tutorial’ instead) or a ’sport tutorial’ (rather a ’squash tutorial’), order tramadol, searching after a real ‘Web2.0 tutorial’ could be ineffective, order tramadol, too. Order tramadol, I suggest to look for ’rounded corners tutorial’, order tramadol, ‘mashup tutorial’ or ‘Ruby on Rails tutorial’ etc. Order tramadol, instead. Order tramadol, Additionally, order tramadol, if you are really keen on Web2.0-ness of these documents, order tramadol, don’t forget to add ‘Web2.0′ to the query - just in case :-).

  • Related to the previous point: attack the problem from bottom up rather than the other way around - i.e. Order tramadol, try to look for solutions of concrete problems and assemble them into a Web2.0 style whatever once you are done, order tramadol, rather than trying to do something which is Web2.0 in the first place. Order tramadol, In my opinion you should think like ‘I would like to create a great mashup in Ruby on Rails with AJAX and a Web2.0 look - how should I go about this?’ rather than ‘Let’s see a good Web 2.0 tutorial and then I will cook something great’. Order tramadol, You should strive for creating great looking websites with great content and functionality, order tramadol, and people will like it and use it - whether you call it Web2.0, order tramadol, Web3.0 or whatever - even if the URL of the site will be www.thissiteisnotweb2.0.com :-).

Now that I have mentioned ‘Web2.0′ and ‘Web 2.0 tutorial’ more times in this article, order tramadol, I guess I’ll be receiving even more hits through this query - though this was definitely not the reason for writing this article. Order tramadol, However, order tramadol, if you already got this far, order tramadol, please take a few seconds and share with us your thoughts on this. Order tramadol, After all Web2.0 is also about collaboration, order tramadol, you know. Order tramadol, Heck, order tramadol, I might even write a few Web2.0 tutorials in the future - just tell me what a ‘Web2.0 tutorial’ means… Order tramadol, :-).

Similar Posts:online cialis,order tramadol,plavix prescription,zoloft pills,ambien pills

Cialis pills

Thursday, November 16th, 2006

Cialis pills, A short time ago in a galaxy not so far, cialis pills, far away I came across a nice blog post: 15 Exercises for Learning a new Programming Language.

Cialis pills, One could argue if these are *really* the most appropriate 15(+) exercises to learn a new programming language - however, cialis pills, the task of answering this rather complex question is left as an exercise for the reader. Cialis pills, Instead of this I will show you their implementation in Ruby - rubyrailways.com style.

Cialis pills, Why did I bother to solve these problems (including not really trivial ones, cialis pills, like a scientific calculator with a GUI) ? Well, cialis pills, actually to learn a new programming language! I still consider myself a beginner Ruby apprentice just playing it by ear in my somewhat scarce free time, cialis pills, so I thought that systematically implementing a task list like this will mean great step forward for me compared to just coding random things at random times. Cialis pills, Fortunately I was perfectly right!

Cialis pills, Before we move onto the code, cialis pills, one last disclaimer: the fact that I am still a Ruby n00b implies that the code can be somewhat hairy/not optimal/[insert any other language than Ruby here]-ish so don’t use these snippets as a textbook solution of the problems or anything like that. Cialis pills, I would be glad if someone could suggest a bit of refactoring of the bad parts but I also hope that that there are some nice parts which you can learn from (actually I am quite sure about this since I used some magick formulas from a few Ruby (grand)masters in some cases).

Cialis pills, OK, cialis pills, enough talk for now. Cialis pills, Let’s see the stuff!

Cialis pills, 1. Cialis pills, Problem: “Display series of numbers (1, cialis pills,2, cialis pills,3, cialis pills,4, cialis pills, 5….etc) in an infinite loop. Cialis pills, The program should quit if someone hits a specific key (Say ESCAPE key).”

Cialis pills, Solution: Hmm, cialis pills, well, cialis pills, errr…uh-oh… Cialis pills, I could not solve this problem fully (what a terrific start :-)). Cialis pills, If Henry Ford would sit beside me now, cialis pills, he would say : You can hit any key to exit - so long as it’s ‘C’ - and one more advice: don’t forget to hold CTRL during this action :-). Cialis pills, More on this after the code snippet:

Cialis pills,

  1. i = 0
  2. loop { print "#{i+=1}, cialis pills, " }

Cialis pills, Comments : If anyone knows how to add code which will cause this program to stop with a specific keyhit (say ‘ESC’) please, cialis pills, please, cialis pills, please drop me a note. Cialis pills, I have been researching this for at least 10% of the time of solving all the tasks, cialis pills, nearly spitting blood when I gave up :-). Cialis pills, It seems (to me) that there is no simple (i.e. Cialis pills, no threads and similar) and clean platform-independent solution for this problem. Cialis pills, I guess (hope) the author’s idea here was different than to introduce threading or writing platform specific-code…

Cialis pills, 2. Cialis pills, Problem: “Fibonacci series, cialis pills, swapping two variables, cialis pills, finding maximum/minimum among a list of numbers.”

Cialis pills, Solution:

Cialis pills,

  1. #Fibonacci series
  2. Fib = Hash.new{ |h, cialis pills, n| n < 2 ? h[n] = n : h[n] = h[n - 1] + h[n - 2] }
  3. puts Fib[50]
  4.  
  5. #Swapping two variables
  6. x, cialis pills,y = y, cialis pills,x
  7.  
  8. #Finding maximum/minimum among a list of numbers
  9. puts [1, cialis pills,2, cialis pills,3, cialis pills,4, cialis pills,5, cialis pills,6].max
  10. puts [7, cialis pills,8, cialis pills,9, cialis pills,10, cialis pills,11].min

Cialis pills, Comments: The Fibonacci code was written by Andrew Johnson (found via Ruby Quiz). Cialis pills, I like it so much that I think it would be a shame to present a trivial version here. Cialis pills, I guess the rest of the code is self-explanatory.

Cialis pills, 3. Cialis pills, Problem: “Accepting series of numbers, cialis pills, strings from keyboard and sorting them ascending, cialis pills, descending order.”

Cialis pills, Solution:

Cialis pills,

  1. a = []
  2. loop { break if (c = gets.chomp) == ‘q’; a << c }
  3. p a.sort
  4. p a.sort { |a, cialis pills,b| b<=>a }

Cialis pills, Comments: This version is accepting strings - I think anybody who got to this point can adapt it to work with numbers. Cialis pills,

Cialis pills, 4. Cialis pills, Problem: “Reynolds number is calculated using formula (D*v*rho)/mu Where D = Diameter, cialis pills, V= velocity, cialis pills, rho = density mu = viscosity Write a program that will accept all values in appropriate units (Don’t worry about unit conversion) If number is < 2100, cialis pills, display Laminar flow, cialis pills, If it’s between 2100 and 4000 display 'Transient flow' and if more than '4000', cialis pills, display 'Turbulent Flow' (If, cialis pills, else, cialis pills, then...)"

Cialis pills, Solution:

Cialis pills,

  1. vars = %w{D V Rho Mu}
  2.  
  3. vars.each do |var|
  4.   print "#{var} = "
  5.   val = gets
  6.   eval("#{var}=#{val.chomp}")
  7. end
  8.  
  9. reynolds = (D*V*Rho)/Mu.to_f
  10.  
  11. if (reynolds < 2100)
  12.   puts "Laminar Flow"
  13. elsif (reynolds > 4000)
  14.   puts "Turbulent Flow"
  15. else
  16.   puts "Transient Flow"
  17. end

Cialis pills, Comments: Can you spot the trick in the part which is filling up the variables? They don’t go out of scope after the loop ends because they are constants. Cialis pills, Other possibility would be to use $global variables but I guess it is usually not a very good programming practice to do that.

Cialis pills, 5. Cialis pills, Problem: “Modify the above program such that it will ask for ‘Do you want to calculate again (y/n), cialis pills, if you say ‘y’, cialis pills, it’ll again ask the parameters. Cialis pills, If ‘n’, cialis pills, it’ll exit. Cialis pills, (Do while loop) While running the program give value mu = 0. Cialis pills, See what happens. Cialis pills, Does it give ‘DIVIDE BY ZERO’ error? Does it give ‘Segmentation fault..core dump?’. Cialis pills, How to handle this situation. Cialis pills, Is there something built in the language itself? (Exception Handling)”

Cialis pills, Solution:

Cialis pills,

  1. vars = { "d" => nil, cialis pills, "v" => nil, cialis pills, "rho" => nil, cialis pills, "mu" => nil }
  2.  
  3. begin
  4.   vars.keys.each do |var|
  5.     print "#{var} = "
  6.     val = gets
  7.     vars[var] = val.chomp.to_i
  8.   end
  9.  
  10.   reynolds = (vars["d"]*vars["v"]*vars["rho"]) / vars["mu"].to_f
  11.   puts reynolds
  12.  
  13.   if (reynolds < 2100)
  14.     puts "Laminar Flow"
  15.   elsif (reynolds > 4000)
  16.     puts "Turbulent Flow"
  17.   else
  18.     puts "Transient Flow"
  19.   end
  20.  
  21.   print "Do you want to calculate again (y/n)? "
  22. end while gets.chomp != "n"

Cialis pills, Comments: As you can see, cialis pills, I could not use the same trick here when asking for the variables, cialis pills, because when somebody wants to calculate again, cialis pills, Ruby will complain (although by printing a warning only) that the constants have been already set up. Cialis pills, Therefore I went for the hash solution. Cialis pills, I think the do-you-want-to-calculate-again part is straightforward so I won’t analyze that here.
“While running the program give value mu = 0.”
Ruby gives a rather interesting result in this case: infinity :-).
“Is there something built in the language itself?”
Sure: exception handling. Cialis pills, Division by zero could be caught with a ZeroDivisionError rescue clause.

Cialis pills, 6. Cialis pills, Problem: “Scientific calculator supporting addition, cialis pills, subtraction, cialis pills, multiplication, cialis pills, division, cialis pills, square-root, cialis pills, square, cialis pills, cube, cialis pills, sin, cialis pills, cos, cialis pills, tan, cialis pills, Factorial, cialis pills, inverse, cialis pills, modulus”

Cialis pills, Solution:
Since this code snippet is longer It would look ugly here - you can download it from here instead. Cialis pills,

Screenshot:

screenshot of the scientific calculator in action

Cialis pills, If you would like to try it, cialis pills, you will need the Tk bindings for Ruby (maybe you have them already, cialis pills, here on Ubuntu I did not). Cialis pills, Also note that only the regular 0-9 keys (and of course the mouse) work, cialis pills, the numpad ones do not. Cialis pills, One more little detail: % stands for modulo, cialis pills, not percent.

Cialis pills, Comments: Phew, cialis pills, this was a real challenge, cialis pills, mostly because I never did any GUI in Ruby before. Cialis pills, I was amazed that I could code up a relatively feature rich calculator in 100+ lines of code, cialis pills, without any golfing or trying to optimize for shortness. Cialis pills, What I wanted to say with this is that the shortness does not praise my programming skills (since I did not eve try to golf) but the superb terseness of Ruby. Cialis pills, OK, cialis pills, of course there are some problems (e.g. Cialis pills, cube, cialis pills, cos, cialis pills, tan, cialis pills, inverse are not implemented) but the usability/amount of code ratio is unbelievably high.

Cialis pills, The GUI is also not the nicest since I have used Tk - wxRuby or qt-ruby would produce much nicer results, cialis pills, but since I did not code any GUI in Ruby previously, cialis pills, I have decided to try the good-old-skool Tk for the first time.

Cialis pills, 7. Cialis pills, Problem: “Printing output in different formats (say rounding up to 5 decimal places, cialis pills, truncating after 4 decimal places, cialis pills, padding zeros to the right and left, cialis pills, right and left justification)(Input output operations)”

Cialis pills, Solution:

Cialis pills,

  1. #rounding up to 5 decimal pleaces
  2. puts sprintf("%.5f", cialis pills, 124.567896)
  3.  
  4. #truncating after 4 decimal places
  5. def truncate(number, cialis pills, places)
  6.   (number * (10 ** places)).floor / (10 ** places).to_f
  7. end
  8.  
  9. puts truncate(124.56789, cialis pills, 4)
  10.  
  11. #padding zeroes to the left
  12. puts ‘hello’.rjust(10, cialis pills,’0)
  13.  
  14. #padding zeroes to the right
  15. puts ‘hello’.ljust(10, cialis pills,’0)
  16.  
  17. #right justification
  18. puts ">>#{’hello’.rjust(20)}<<"
  19.  
  20. #left justification
  21. puts ">>#{’hello’.ljust(20)}<<"

Cialis pills, Comments: Amazingly lot of things can be done with sprintf() - I could solve nearly all the problems with it - but that would not really be rubyish, cialis pills, so I have decided for built-in (and one homegrown) functions. Cialis pills, However, cialis pills, mastering (s)printf() is a very handy thing, cialis pills, since nearly all big players (C (of course :-)), cialis pills, C++, cialis pills, Java, cialis pills, PHP, cialis pills, … Cialis pills, ) have it so you get a powerful function in more languages for the price of learning one). Cialis pills, As you can see, cialis pills, r/ljust is a nice one, cialis pills, too.

Cialis pills, 8. Cialis pills, Problem: “Open a text file and convert it into HTML file. Cialis pills, (File operations/Strings)”

Cialis pills, Solution: Well, cialis pills, this problem was not specified in a great detail, cialis pills, to say the least - or to put it otherwise, cialis pills, the solvers are given a great freedom to provide a solution spiced up with their fantasy. Cialis pills, This is what I came up with:

Cialis pills,

FINAL_DOC rules = {'*something*' => 'something', cialis pills, '/something/' => 'something'} rules.each do |k, cialis pills,v| re = Regexp.escape(k).sub(/something/) {"(.+?)"} doc.gsub!(Regexp.new(re)) do content = $1 v.sub(/something/) { content } end end doc.gsub!("\n\n") {"\n

Cialis pills, "} final_doc.sub!(/embed_doc_here/) {doc} puts final_doc

  1. doc = <<DOC
  2.  This is the first line in the first paragraph. <b>Cialis pills</b>, Nothing really interesting here, cialis pills, just plain text.
  3.  
  4. This is the second paragraph. <b>Cialis pills</b>, Let’s see some *strong* markup in action, cialis pills, and also /italic/. <b>Cialis pills</b>, So far soo good.
  5.  
  6. This is the last paragraph, cialis pills, with one more <strong>strong tag</strong>.
  7. DOC
  8.  
  9. final_doc = <<FINAL_DOC
  10. <html>
  11.   <head>
  12.     <title>Text to HTML fun!</title>
  13.   </head>
  14.   <body>
  15.     <p>Cialis pills,
  16.     embed_doc_here
  17.     </p>
  18.   </body>
  19. </html>
  20. FINAL_DOC
  21.  
  22. rules = {‘*something*’ => ‘<strong>something</strong>’, cialis pills,
  23.          ’/something/’ => ‘<i>something</i>’}
  24.  
  25. rules.each do |k, cialis pills,v|
  26.   re = Regexp.escape(k).sub(/something/) {"(.+?)"}
  27.   doc.gsub!(Regexp.new(re)) do
  28.     content = $1
  29.     v.sub(/something/) { content }
  30.   end
  31. end
  32.  
  33. doc.gsub!("\n\n") {"</p>\n<p>Cialis pills, "}
  34.  
  35. final_doc.sub!(/embed_doc_here/) {doc}
  36.  
  37. puts final_doc

Cialis pills, Comments: As you can see, cialis pills, besides that the text is wrapped around with a minimal HTML, cialis pills, every occurrence of words between asterisks is outputted in strong and between slashes in italic. Cialis pills, You can add as many such rules as you like, cialis pills, they will be (hopefully) substituted in the final output.

Cialis pills, 9. Cialis pills, Problem: “Time and Date : Get system time and convert it in different formats ‘DD-MON-YYYY’, cialis pills, ‘mm-dd-yyyy’, cialis pills, ‘dd/mm/yy’ etc.”

Cialis pills, Solution: Well, cialis pills, it was not really clear (for me) what should be the difference between ‘yyyy’ and ‘YYYY’ (resp. Cialis pills, ‘dd’ vs ‘DD’) so again I had to use my imagination. Cialis pills, However, cialis pills, I guess it does not matter too much, cialis pills, the solution has to be changed by 1-2 characters only if the original author had something different on his mind.

Cialis pills,

  1. require ‘date’
  2.  
  3. time = Time.now
  4. #’DD-MON-YYYY’, cialis pills, e.g. <b>Cialis pills</b>, 12-Nov-2006 in my interpetation
  5. puts time.strftime("%d-%b-%Y")
  6.  
  7. #’mm-dd-yyyy’, cialis pills, e.g. <b>Cialis pills</b>, 11-12-2006 in my interpetation
  8. puts time.strftime("%m-%d-%Y")
  9.  
  10. #’dd/mm/yy’, cialis pills, e.g. <b>Cialis pills</b>, 12/11/2006 in my interpetation
  11. puts time.strftime("%d/%m/%Y")

Cialis pills, 10. Cialis pills, Problem: “Create files with date and time stamp appended to the name”

Cialis pills, Solution:

Cialis pills,

  1. #Create files with date and time stamp appended to the name
  2. require ‘date’
  3.  
  4. def file_with_timestamp(name)
  5.   t = Time.now
  6.   open("#{name}-#{t.strftime(’%m.%d’)}-#{t.strftime(’%H.%M’)}", cialis pills, ‘w’)
  7. end
  8.  
  9. my_file = file_with_timestamp(test.txt)
  10. my_file.write(‘This is a test!’)
  11. my_file.close

Cialis pills, Comments: Maybe a more elegant solution could be to subclass File and override its constructor - but maybe that would be an overkill. Cialis pills, I have voted for the latter option in this case :-).

Cialis pills, 11. Cialis pills, Problem: “Input is HTML table. Cialis pills, Remove all tags and put data in a comma/tab separated file.”

Cialis pills, Solution: Since web extraction is both my PhD topic and my everyday job (and even my free-time activity :-)) I will present 3 solutions for this problem. Cialis pills, First, cialis pills, the classic old-school regexp way (by Paul Lutus), cialis pills, then with HPricot and finally with scRUBYt!, cialis pills, a simple yet powerful Ruby web extraction framework currently developed by me.

Cialis pills,

  1. table = <<DOC
  2. <table>
  3.   <tr>
  4.     <td>1</td>
  5.     <td>2</td>
  6.   </tr>
  7.   <tr>
  8.     <td>3</td>
  9.     <td>4</td>
  10.     <td>5</td>
  11.   </tr>
  12.   <tr>
  13.     <td>6</td>
  14.   </tr>
  15. </table>
  16. DOC
  17.  
  18. rows = table.scan(%r{<tr>.*?</tr>}m)
  19.  
  20. rows.each do |row|
  21.    fields = row.scan(%r{<td>(.*?)</td>}m)
  22.    puts fields.join(", cialis pills,")
  23. end

Cialis pills, Now for the HPricot solution (in the further examples let’s consider that table is initialized as in the previous example):

  1. require ‘rubygems’
  2. require ‘hpricot’
  3.  
  4. h_table = Hpricot(table)
  5.  
  6. rows = h_table/"//tr"
  7. rows.each do |row|
  8.   child_text = (row/"//td").collect {|elem| elem.innerHTML }
  9.   puts child_text.join(‘, cialis pills,’)
  10. end

Cialis pills, and last, cialis pills, but not least scRUBYt!

  1. require ’scrubyt’
  2.  
  3. table_data = P.table do
  4.                P.cell1
  5.              end
  6.  
  7. table_data.generalize :cell
  8.  
  9. puts table_data.to_csv

Cialis pills, Some explanation: first of all, cialis pills, at the moment scRUBYt! is avaliable on my hard disk (and partially in my head) only - it should be released around XMAS 2006. Cialis pills, I am using this solution for a little bit of self-promotion :-). Cialis pills,

Cialis pills, The example works like this: extract something (in this case a HTML <table>) which has something (in this case <td>) which has ‘1′ as its text (well in reality much more is going on in the background, cialis pills, but roughly along these lines). Cialis pills, This little code snippet will extract the first <td>s of ALL <tables> on a HTML page. Cialis pills, With the ‘generalize’ call we tell the extractor that it should not extract just the first <td> in a table (which is the default setting), cialis pills, but all of them.

Cialis pills, scRUBYt! can handle much, cialis pills, much, cialis pills, MUCH more complicated examples than this (like an ebay or amazon page) and has loads of sophisticated functions… Cialis pills, so stay tuned!

Cialis pills, 12. Cialis pills, Problem: “Extract uppercase words from a file, cialis pills, extract unique words.”

Cialis pills, Solution: (you can find some_uppercase_words.txt here and some_repeating_words.txt here

Cialis pills,

  1. open(’some_uppercase_words.txt).read.split().each { |word| puts word if word =~ /^[A-Z]+$/ }
  2.  
  3. words = open(’some_repeating_words.txt).read.split()
  4. histogram = words.inject(Hash.new(0)) { |hash, cialis pills, x| hash[x] += 1; hash}
  5. histogram.each { |k, cialis pills,v| puts k if v == 1 }

Cialis pills, 13. Cialis pills, Problem: “Implement word wrapping feature (Observe how word wrap works in windows ‘notepad’).”

Cialis pills, Solution: Unfortunately I am not a Windows user and I have seen notepad a *quite* long time ago - so I am not sure the task and it’s implementation are fully in-line - I have tried my best. Cialis pills, Here we go:

Cialis pills,

  1. input = "Lorem ipsum dolor sit amet, cialis pills, consectetur adipisicing elit, cialis pills, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. <b>Cialis pills</b>, Ut enim ad minim veniam, cialis pills, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. <b>Cialis pills</b>, Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. <b>Cialis pills</b>, Excepteur sint occaecat cupidatat non proident, cialis pills, sunt in culpa qui officia deserunt mollit anim id est laborum."
  2.  
  3. def wrap(s, cialis pills, len)
  4.   result = ”
  5.   line_length = 0
  6.   s.split.each do |word|
  7.     if line_length + word.length + 1  < len
  8.       line_length += word.length + 1
  9.       result += (word + ‘ ‘)
  10.     else
  11.       result += "\n"
  12.       line_length = 0
  13.     end
  14.   end
  15.   result
  16. end
  17.  
  18. puts wrap(input, cialis pills, 30)

Cialis pills, 14. Cialis pills, Problem: “Adding/removing items in the beginning, cialis pills, middle and end of the array.”

Cialis pills, Solution:

Cialis pills,

  1. x = [1, cialis pills,3]
  2.  
  3. #adding to beginning
  4. x.unshift(0)
  5.  
  6. #adding to the end
  7. x << 4
  8.  
  9. #adding to the middle
  10. x.insert(2, cialis pills,2)
  11.  
  12. #removing from the beginning
  13. x.shift
  14.  
  15. #removing from the end
  16. x.pop
  17.  
  18. #removing from the middle
  19. x.delete(2)
  20.  
  21. #we have arrived at the original array!

Cialis pills, 15. Cialis pills, Problem: “Are these features supported by your language: Operator overloading, cialis pills, virtual functions, cialis pills, references, cialis pills, pointers etc.”

Cialis pills, Solution: Well this is not a real problem (not in Ruby, cialis pills, at least). Cialis pills, Ruby is a very high level language ant these things are a must :).

Finally, cialis pills, you can download all the solutions in a single archive from here. I would like to see the implementation of these tasks in both Ruby (different (more optimal) solutions of course) as well as in anything else. Cialis pills, If you set out to do something like that, cialis pills, be sure to drop me a note.

Internet contains huge number of opportunities to earn money online. Cialis pills, Simply create a site that you think has the potential to sell hot items using ruby on rails. Cialis pills, Register a relevant domain name and purchase a web hosting service through hostgator, cialis pills, one of the better web host out there today. Cialis pills, Get a internet connection through one of the wireless internet providers to upload your site. Cialis pills, Work on search engine optimization to get a better traffic and also use affiliate marketing program for the same reason. Cialis pills, Finally get a free voip phone service to contact customers directly. Cialis pills, The pc to phone system is the most effective method of marketing.


Similar Posts:prozac,cialis pills,discount plavix,buy kamagra without prescription,order cialis online

Posted in Devel, Ruby, Tutorial | 30 Comments »

Order lexapro

Thursday, October 19th, 2006

Order lexapro, Update: A lot of people were disappointed that 10.minutes.ago etc. Order lexapro, is not working in pure Ruby. Order lexapro, Well, order lexapro, after executing the line require ‘active_support’ it does - I think this is a fairly small thing to do to enable these powerful features.

Order lexapro, Every guide published on favorable writing principles emphasizes the power of brief and concise style. Order lexapro, This is especially true in the case of technical texts, order lexapro, and in my opinion, order lexapro, in the case of well-designed programming languages as well. Order lexapro,

Order lexapro, Note the word well-designed. Order lexapro, I did not say in the case of any (programming) language, order lexapro, since that would just not be true: conciseness can come at the cost of readability. Order lexapro, (If you ever tried to read kanji, order lexapro, you know what I am talking about ;-) . Order lexapro, However, order lexapro, I am claiming that in the case of a really well-designed programming language, order lexapro, succinctness helps readability, order lexapro, reduces bloat and leads to easier and faster understanding of the code. Order lexapro, In my experience, order lexapro, the amount of boilerplate code to write is decreasing proportionally with the terseness of the programming language, order lexapro, ultimately leading to a coding style where you (nearly) don’t need to write boilerplate at all.

Order lexapro, I will demonstrate this on a few Java vs. Order lexapro, Ruby code examples. Order lexapro, However, order lexapro, this is NOT a Ruby-bashing-Java article, order lexapro, but a few examples of idioms and interesting constructs; C++ vs Haskell or Lisp could serve equally well (sometimes even better), order lexapro, but since I am currently working with Java and Ruby on a daily basis, order lexapro, it is easier for me to use them.

Order lexapro, If you are a pro Ruby and/or Java programmer, order lexapro, and/or you think the article is too long for you, order lexapro, please jump to the “Random Code Snippets” section.

Order lexapro, Possibly the most straightforward reason why Ruby code is more readable even in shorter form is that really everything is an object [1] in Ruby-land. Order lexapro, For example in Java, order lexapro, primitives need wrapper classes to ‘become’ objects., order lexapro, while in Ruby they are first class objects on their own. Order lexapro, This makes constructs like

10.times { print "ho" }  #=> "hohohohohohohohohoho"
or (will output the same string)
print "ho" * 10 #=> "hohohohohohohohohoho"
possible. Order lexapro,

Order lexapro, There are a handful of other reasons which make Ruby more readable and elegant, order lexapro, but before I get bogged down in the explanation too much, order lexapro, let’s see the examples!

Whetting your appetite

In the first part I will describe some basic constructs which would make the life of any Java developer much easier. Order lexapro, These techniques are neat, order lexapro, but they are not using any really sophisticated stuff yet: I will try to take a look at those in the next bigger section.

The empty program

Java:

class Test
{
    public static void main(String args[]) {}
}

Ruby:


I did not forget the Ruby snippet; You can not see anything there because actually a Ruby program doing nothing is exactly 0 characters long. On the other hand, order lexapro, the Java version is slightly longer. Order lexapro, I is kind of weird to explain to a newcomer what do ‘class’, order lexapro, ‘public’, order lexapro, ’static’, order lexapro, ‘void’, order lexapro, ‘String’, order lexapro, the [] operator and several braces here and there mean, order lexapro, and why are they needed if the program does literally nothing

Fun with numbers

Note:For some of the next examples you will need to use Rails Active Support.
Java:

if ( 1 % 2 == 1 ) System.err.println("Odd!") #=> Odd!

Ruby:

if 11.odd? print "Odd!" #=> Odd!
Does not the first example make more sense (even for a non-programmer)?. Order lexapro, I believe it does. Order lexapro, More of this type:
Java:
102 * 1024 * 1024 + 24 * 1024 + 10 #=> 106979338

Ruby:

102.megabytes + 24.kilobytes + 10.bytes #=> 106979338

OK, order lexapro, maybe this is an unfair comparison since Java does not have (?) those functions. Order lexapro, However, order lexapro, the point is that even if it had, order lexapro, the best I could come up with would look like:

Util.megaBytes(102) + Util.kiloBytes(24) + Util.bytes(10) #=> 106979338

Which is far from the elegance and readability of the Ruby example.
In the next example we will assume that we have a Java function similar to ordinalize in Ruby.
Java:

System.err.println("Currently in the" + Util.ordinalize(2) + "trimester");

Ruby:

 print "Currently in the #{2.ordinalize} trimester"    #=> "Currently in the 2nd trimester"

In this example we can observe variable interpolation: anything wrapped in #{} inside double quotes gets evaluated and substituted in the string, order lexapro, providing a more readable form without a lot of + + Java constructs (which is cool mainly if you have more variables inside the double quotes).

Dates

In my opinion, order lexapro, handling dates and times is a great PITA in Java, order lexapro, especially if you are implementing some complex code.
Java:

System.out.println("Running time: " + (3600 + 15 * 60 + 10) + "seconds");

Ruby:

puts "Running time: #{1.hour + 15.minutes + 10.seconds} seconds"

Java:

new Date(new Date().getTime() - 20 * 60 * 1000)

Ruby:

20.minutes.ago

Java:

Date d1 = new GregorianCalendar(2006, order lexapro,9, order lexapro,6, order lexapro,11, order lexapro,00).getTime();
Date d2 = new Date(d1.getTime() - (20 * 60 * 1000));

Ruby:

20.minutes.until("2006-10-9 11:00:00".to_time)

Order lexapro, I think you do not have to be biased towards Ruby at all to admit which code makes more sense instantly…

I have recently found a very cool way of parsing dates in Ruby: using Chronic. Order lexapro, However, order lexapro, I would not like to present it here since it is not a feature of the language, order lexapro, ‘just’ a nifty natural-language date parser [2].

A little bit more advanced stuff

Classes

Java:

Class Circle
  private Coordinate center, order lexapro, float radius;

  public void setCenter(Coordinate center)
  {
    this.center = center;
  }

  public Coordinate getCenter()
  {
    return center;
  }

  public void setRadius(float radius)
  {
    this.radius = radius;
  }

  public Coordinate getRadius()
  {
    return radius;
  }
end;

Ruby:

class Circle
  attr_accessor :center, order lexapro, :radius
end

Order lexapro, Believe it or not, order lexapro, the two code snippets are absolutely equal; The getter and setter methods in Ruby code are generated automatically, order lexapro, so not only you do not have to write them, order lexapro, but they are not even there to clutter the code.

Order lexapro, I have seen argumentation from Java guys that stuff like this (i.e. Order lexapro, the public static void main … Order lexapro, thing, order lexapro, getters/setters and other boilerplate code) can be generated with any decent GUI like Eclipse (or by tools like XDoclet etc) is a non-issue. Order lexapro, Well, order lexapro, as for their generation, order lexapro, let us say this is true. Order lexapro, But for the readability of code it is absolutely not!

Order lexapro, For example. Order lexapro, take getters/setters: Every variable in Java ads 8 more lines of code (not counting the lines between the function declarations) compared to the Ruby :attr_accessor idiom. Order lexapro, That is, order lexapro, a simple class definition having 10 fields in Java will have 80+ lines of code compared to 1 lines of the same code in Ruby. Order lexapro, For me, order lexapro, this definitely means a big difference.

Arrays (and other containers)

Order lexapro, This section was inspired by a blog entry by Steve Yegge.

Order lexapro, Arrays are interesting citizens of Java: They are not really objects in the “classical” sense , order lexapro, so they have very limited functionality compared to first-class Java objects. Order lexapro, On the other hand, order lexapro, they are offering a huge advantage over the other container classes: they can be easily initialized.
Java:

String languages[] = new String[] {"Java", order lexapro, "Ruby", order lexapro, "Python", order lexapro, "Perl"};
instead of
List<String> languages = new LinkedList<String>();
languages.add("Java");
languages.add("Ruby");
languages.add("Python");
languages.add("Perl");
which is kind of lame when you quickly need to hack up some testing data.

Order lexapro, However, order lexapro, they have also some serious problems: you have to define the number of the elements upon construction time, order lexapro, like so:
Java:

String someOtherLanguages<String>[] = new String[15];
which sometimes really cripples their functionality. Order lexapro, [3]

Order lexapro, How does this work in Ruby? Let’s see on three different examples (All three code snippets provide the same result):
Ruby:

stuff = [] #An empty array - as you can see there is no need to define the size
stuff << "Java", order lexapro, "Ruby", order lexapro, "Python" #Add some elements
#Initialize the array with the values
stuff = ["Java", order lexapro, "Ruby", order lexapro, "Python"]
#Yet another method yielding the same result
stuff = %w(Java Ruby Python)

Order lexapro, In my opinion, order lexapro, these forms (especially the last one) are more straightforward and can save a lot of typing.

Order lexapro, Another major shortcoming of Java arrays is that besides the [] operator you have only the methods inherited from Object and a single instance variable : length [4]. Order lexapro, This means that even essential functionality like sorting, order lexapro, selecting elements based on something etc. Order lexapro, has to be done via a ‘third party’ function, order lexapro, like this:
Java:

Arrays.sort(languages);
which seemed quite normal to me when I have been learning Java and have had no previous experience with dynamic languages, order lexapro, but now it looks kind of annoying.

Order lexapro, Another Java-container-woe compared to Ruby is that in Java, order lexapro, an array is an array. Order lexapro, A list is a list. Order lexapro, A stack is a stack. If you are wondering what the hell I am talking about, order lexapro, check out these Ruby code snippets: Ruby:

stuff = %w(Java Ruby Python)
#Add the string "Perl" to the array
stuff << "Perl"
#Prepend the string "Ocaml" 
stuff.unshift "Ocaml"  
=> ["OCaml", order lexapro, "Java", order lexapro, "Ruby", order lexapro, "Python", order lexapro, "Perl"]
#Use the array as a stack
stuff.pop 
=> "Perl"  #stuff is now ["OCaml", order lexapro, "Java", order lexapro, "Ruby", order lexapro, "Python"] 
stuff.push "C", order lexapro, "LISP"
=> ["OCaml", order lexapro, "Java", order lexapro, "Ruby", order lexapro, "Python", order lexapro, "C", order lexapro, "LISP"]
#Update C to C++ 
stuff[4] = "C++"
=> ["OCaml", order lexapro, "Java", order lexapro, "Ruby", order lexapro, "Python", order lexapro, "C++", order lexapro, "LISP"]
#Remove the fisrt element
stuff.shift
=> "OCaml" #stuff is now ["Java", order lexapro, "Ruby", order lexapro, "Python", order lexapro, "C++", order lexapro, "LISP"] 
#Let's just stick with Java and Ruby - slice out the  rest!
stuff.slice!(2..4)
=> ["Python", order lexapro, "C++", order lexapro, "LISP"] #stuff is now ["Java", order lexapro, "Ruby"]
As you can see, order lexapro, the Ruby Array class offers functionality that could be achieved only by mixing up several Java containers into one (to my knowledge, order lexapro, at least) [5]. Order lexapro, In practice, order lexapro, this usually speeds things up a lot.

Order lexapro, Another thing that really annoys me when using containers in Java is the lack of this functionality:
Ruby:

stuff = ["OCaml", order lexapro, "Java", order lexapro, "Ruby", order lexapro, "Python", order lexapro, "C++", order lexapro, "LISP"]
#Lua is just gaining steam, order lexapro, add it to the 7th place
stuff[7] = "Lua"
=> ["OCaml", order lexapro, "Java", order lexapro, "Ruby", order lexapro, "Python", order lexapro, "C", order lexapro, "LISP", order lexapro, nil, order lexapro, "Lua"]
i.e. Order lexapro, that if I am adding an element to an index which is bigger than the size of the array, order lexapro, the empty space inbetween is filled with nils. Order lexapro, Now seriously, order lexapro, who would not exchange this for the Java behaviour (an IndexOutOfBoundsException is thrown) - after all, order lexapro, if I would need this functionality (which is VERY seldomly the case) in Ruby, order lexapro, I could check it myself and raise an exception if I don’t like what I see.

Order lexapro, I wanted to write a bit about differences between hashes and files in Ruby and Java, order lexapro, but the post is already longer now then I wanted it to be so I guess I will just show some concrete code snippets to conclude.

Random Code Snippets

Order lexapro, In this section I would like to present some real cases I have been solving with Ruby recently. Order lexapro, Since I am still new to Ruby, order lexapro, I was totally amazed just how much more simpler, order lexapro, shorter yet much more understandable the code can be in Ruby compared to Java.

Files and Regular Expressions

Order lexapro, As Bruce Eckel once put it, order lexapro, In Java, order lexapro, it’s a research project to open a file. Order lexapro, Well, order lexapro, I have to agree. Order lexapro, Maybe I am the only one Java programmer (besides Bruce) who - even after using Java professionally for five years - still can not write to a file without using google first. Order lexapro, Maybe I should learn it one day?

Order lexapro, Regular expression support in java is OK (at least one does not have to use external packages as in the pre-1.4 era), order lexapro, however, order lexapro, compared to Ruby the syntax is quite heavy. Order lexapro,

Let’s see a demonstration on the following task: Open the file ‘test.txt’ and write all the sentences to the console (one sentence per line) which contain the word ‘Ruby’. Order lexapro, First, order lexapro, the Java solution:
Java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test 
{
    public static void main(String[] args)
    {
        try {
            BufferedReader in = new BufferedReader(new FileReader("test.txt"));
            StringBuffer sb = new StringBuffer();
            String str;
            while ((str = in.readLine()) != null) 
              { sb.append(str + "\n"); }            
            in.close();
            String result = sb.toString();
            Pattern sentencePattern = Pattern.compile("(.*?\\.)\\s+?");
            Pattern javaPattern = Pattern.compile("Ruby");
            Matcher matcher = sentencePattern.matcher(result);
            while (matcher.find()) {
                String match = matcher.group();
                Matcher matcher2 = javaPattern.matcher(match);
                if (matcher2.find())
                    System.err.println(match);
            }
        } catch (IOException e) 
          {
            e.printStackTrace();
          }     
    }
}
It is quite straightforward what this relatively simple code snippet doing - but if this is straightforward, order lexapro, what should I say about the Ruby version?
Ruby
File.read('test.txt').scan(/.*?\. Order lexapro, /).each { |s| puts s if s =~ /Ruby/ }

Order lexapro, Well, order lexapro, umm… Order lexapro, I guess this example quite much expresses the point I am talking about from the beginning: sometimes less is more, order lexapro, a.k.a. Order lexapro, Succinctness is Power!

Order lexapro, Again, order lexapro, I wanted to show much more examples, order lexapro, but I have the feeling that since the article is already too long, order lexapro, no one would read it :-) It is a big pity since I did not even talk about hashes, order lexapro, blocks, order lexapro, closures, order lexapro, metaprogramming (well, order lexapro, I will mention it briefly in the last (really :-)) example) and other goodies - maybe in part 2?

If this is still not enough…

Order lexapro, Although I find it very easy and natural to express a lots of things in Ruby, order lexapro, the language can not offer anything I would ever need. Order lexapro, However, order lexapro, there is a powerful concept to invoke in such situations, order lexapro, called metaprogramming.

Order lexapro, A few days ago I needed to test some algorithms on trees, order lexapro, so I needed to hack up a lot of tree test data. Order lexapro, Here is how I would go about this in Java using the example below (let’s assume in both languages that we have a simple data structure Tree):

               a
            /      \
          b         c
         /  \      / | \
        d    e    f  g  h

Java

Tree a = new Tree("a");

Tree b = new Tree("b");
Tree c = new Tree("c");
a.addChild(b);
a.addChild(c);

Tree d = new Tree("d");
Tree e = new Tree("e");
b.addChild(d);
b.addchild(e);

Tree f = new Tree("f");
Tree g = new Tree("g");
Tree h = new Tree("h");
c.addChild(f);
c.addChild(g);
c.addChild(h);

Another possibility would be to create an XML file with the description of the tree and parse it from there. Order lexapro, This solution is even more convenient since though you have to write the parsing code, order lexapro, you just have to edit an XML file once it is written. Order lexapro, One possibility how the tree of this example could look something like
XML

  <node name="a">
      <node name="b">
          <node name="d"/>
          <node name="e"/>
      </node>
      <node name="c">
          <node name="f"/>
          <node name="g"/>
          <node name="h"/>
      </node>
  </node>

Order lexapro, The latter solution is quite cool. Order lexapro, After all you do not need to write any code, order lexapro, just alter the XML file and that’s it.

Order lexapro, Now let’s see the Ruby solution I came up with:
Ruby

tree = a {
            b { d e }
            c { f g h }
          }

Order lexapro, Well… Order lexapro, suddenly even the XML file seems too heavy, order lexapro, does not it? :-) Not to mention the fact that the latter example is pure Ruby code - there is no need to open an external file and parse it - you just run it and the variable tree will contain your tree. Order lexapro, That’s it.

Order lexapro, Of course Ruby can not handle this code as it is - for this we need to invoke some metaprogramming magic. [6]

Order lexapro, Metaprogramming is a way to drive Ruby with Ruby. Order lexapro, Java (especially J2EE) is usually driven by XML (which is not always really a good thing in my opinion) As you could see, order lexapro, Ruby is driven by Ruby instead :-)

Order lexapro, This example merely scratched the surface of Ruby’s possibilities through metaprogramming. Order lexapro, However, order lexapro, as with the other examples, order lexapro, my goal was not to advocate a concrete pattern/method over a different one, order lexapro, but rather to show how a specific toolset can change the way of thinking about the task at hand, order lexapro, and the way of code design/implementation in general.

Final thoughts

Order lexapro, When I was a child, order lexapro, I spoke as a child, order lexapro, I understood as a child, order lexapro, I thought as a child: but when I became a man, order lexapro, I put away childish things. - The Bible, order lexapro, I Corinthians 13:11

Order lexapro, This thought pretty well expresses how I felt about Java/C++/(substitute any non-dynamic language here) when I came to know (some of) Ruby’s true dynamism and expressive power through terse yet powerful idioms which transformed my whole thinking about programming. Order lexapro, Of course I do not claim that I ‘became a man’ because that’s still a very long way to go, order lexapro, but still, order lexapro, even with my very limited knowledge of Ruby, order lexapro, the way to express things in Java/C++ now seems… Order lexapro, well… Order lexapro, childish ;-). Order lexapro, [7]


Creating a site on online tutorials is not a completely bad idea. Order lexapro, One should include courses for 642-054, order lexapro, 642-054, order lexapro, 642-176, order lexapro, ruby on rails, order lexapro, cissp certification. Order lexapro, If you have the knowledge for creating the tutorials, order lexapro, the rest is very simple. Order lexapro, By using dot5hosting company’s site you can purchase a web hosting package that is economical. Order lexapro, Even dedicated servers can be found for low prices. Order lexapro, Then through the use of ip telephony one can directly reach its potential clients. Order lexapro, Other internet marketing methods should also be considered to create awareness the site.


Notes

[1] I wonder whether this déjà vu will happen to me in the future once again: I have had this ‘Wow, order lexapro, everything is an object’ feeling when coming from C++ to Java; Then after coming from Java to Python; and most recently, order lexapro, after coming from Python to Ruby. Order lexapro, Back


[2] Some examples that Chronic can handle:
  summer
  6 in the morning
  tomorrow
  this tuesday
  last winter
  this morning
  3 years ago
  1 week hence
  7 hours before tomorrow at noon
  3rd wednesday in november
  4th day last week
Kudos… Back


[3] In the previous array initialization example this was not needed since it is trivial when all the elements are stated beforehand.Back


[4]which somewhat confusing given that all the other containers use the method size() (and not a field!) to determine the count of elements. Order lexapro, To nicely mesh with the confusion, order lexapro, the String object provides the method length() (and not a field, order lexapro, as with array) to query the number of characters… Order lexapro, Back


[5] I mean it is not possible to construct any container - other than an array - with literals, order lexapro, you can use the [] operator on arrays only, order lexapro, you can not get the i-th element of a stack etc. Order lexapro, Back


[6] The code I have been using to accomplish this task relies on the method_missing idiom:
class Object
  @stack = []
  @parent = nil

  def method_missing(method_name, order lexapro, *args, order lexapro, &block)
    tree = Tree.new(method_name)
    @parent.add_child(tree) if @parent != nil
    if block_given?
      @stack ||=[]
      @parent = tree
      @stack.push @parent
      yield block
      @stack.pop
      @parent = @stack.last
    end
    tree
  end
end
Back


[7] This does not necessarily mean that Java is bad and Ruby is good - just that it was the ‘Ruby way’ that struck a chord in me after trying/playing around with programming in many programming languages. Order lexapro, Many of the features I adore in Ruby are there in Java as well, order lexapro, but they did not ‘came through’ whereas with Ruby there was a point of enlightenment when I really understood a lot of generic, order lexapro, non-language specific principles. Order lexapro, Back

Similar Posts:purchase viagra,order lexapro,purchase nolvadex online,clomid prescription,buy cheap cialis

Posted in Devel, Java, Ruby, Tutorial | 78 Comments »

Lexapro pills

Thursday, June 22nd, 2006

As weird as this may sound, lexapro pills, sometimes even Linux users need Internet Explorer - for example to check how they current web design looks in the good old IE, lexapro pills, to browse an ‘IE only page’ (probably not as big problem as a few years ago though), lexapro pills, or to log in to a legacy system for example. Lexapro pills, For some time I have thought this is possible only with Crossover Office (which is not not expensive, lexapro pills, but still not free) until Gabor told me about a completely free, lexapro pills, easy-to-install and working solution: IEs4Linux.

Paradoxically, lexapro pills, IEs4Linux provides a functionality which is (AFAIK) not available to Windows users: It installs 3 versions of Internet Explorer: 5.0, lexapro pills, 5.5 and 6.0. Maybe the time has come for Win32 users to install Ubuntu so they can view their webdesign in all the currently used versions of IE? ;-)

So, lexapro pills, now for the installation:

Check /etc/apt/sources.list - make sure you have access to the ‘universe’ packages by uncommenting the following lines:

deb http://us.archive.ubuntu.com/ubuntu dapper universe
deb-src http://us.archive.ubuntu.com/ubuntu dapper universe

There you go. Lexapro pills, After specifying which versions you need, lexapro pills, choosing a locale and a few minutes of installation you should have the links on your desktop.

Check out the original page for new versions, lexapro pills, updates or to donate for this awesome stuff!

Making a website for distance learning about ruby on rails is a great way to create awareness for the language. Lexapro pills, With the help of online certificate such as ibm certification, lexapro pills, which is attained through sitting the ibm exams. Lexapro pills, With this you can create this site efficiently and with the guidance of oracle certification you can create a strong database for it. Lexapro pills, Next look around for internet hosting companies to upload the site on. Lexapro pills, One good example is bluehost, lexapro pills, as it hires the best out, lexapro pills, such as cisco’s 350-029 certified, lexapro pills, there to provide quality services. Lexapro pills, To ensure that your site gets a good traffic work on search engine marketing. Lexapro pills, Employ affiliate marketing program to cater a wide scope of audience.

Similar Posts:tramadol,lexapro pills,cheap doxycycline,lexapro pills,buy cheap lorazepam online

Posted in Tutorial, Ubuntu, Web design | 59 Comments »

Xanax sale

Wednesday, June 14th, 2006

I am planning to write a series of entries on screen scraping, xanax sale, automated Web navigation, xanax sale, deep Web mining, xanax sale, wrapper generation, xanax sale, screen scraping from Rails with Ajax and possibly more, xanax sale, depending on my time and your feedback. Since these entries are going to be longer, xanax sale, I will be posting them to separate pages, xanax sale, and announce them on my blog.

The first article is ready, xanax sale, you can read it here.

It is an introduction to screen scraping/Web extraction with Ruby, xanax sale, evaluation of the tools along with installation instructions and examples.

Feedback would be appreciated (leave your comment here/on the article page, xanax sale, or send me a mail at peter@[name of this site].com), xanax sale, I will update/extend the document and publish new ones based on your feedback.

Similar Posts:cheapest cialis,xanax sale,buy nolvadex without prescription,order cialis online,tramadol sale

Posted in Rails, Ruby, Tutorial, Web2.0 | 3 Comments »

Generic viagra

Sunday, June 11th, 2006

Programming is great fun (mainly with Ruby ;-). Generic viagra, However, generic viagra, this statement does not contradict with the fact that sometimes programming can be also hard. Generic viagra, I came across a nice site today which can offer some help in these moments: Programming is hard. Generic viagra, Judging from the size of Ruby/Rails/ActiveRecord tags (there is even a script.aculo.us tag!) it seems that it has a nice dose of Ruby/Rails stuff - solutions for common problems and also links to tutorials, generic viagra, frequenty asked nuby questions etc. Generic viagra, Be sure to check it out!

Similar Posts:cialis pills,generic viagra,viagra pharmacy,cheap nizoral,cheap cialis without prescription

Posted in Rails, Ruby, Tutorial | 13 Comments »

Cheap phentermine

Sunday, May 21st, 2006

In my previous post on migrations i wrote that “…they are not covered in any of the basic books on RoR”. Cheap phentermine, Well, cheap phentermine, this statement does not hold anymore, cheap phentermine, since Agile Web Development with Rails, cheap phentermine, 2nd ed. is already creating the models with migrations.

While the last part of the post (why are migrations so cool) is still up-to-date, cheap phentermine, they way of creating migrations is different from 1.1 on, cheap phentermine, so i have decided to review the topic and add some new points, cheap phentermine, too.

Migrations are now created automatically with the model

In my previous post, cheap phentermine, i have been creating the migration manually with the command

ruby script/generate migration ProductMigration

However, cheap phentermine, as of Rails 1.1, cheap phentermine, you don’t have to do this anymore. Cheap phentermine, When you generate the model (let’s stick with the Product model as an example) the migration is automatically generated:

ruby script/generate model Product
...
... Cheap phentermine, #some lines omited
...
create db/migrate/001_create_products.rb

Now you can edit the file db/migrate/001createproducts.rb to contain something like this:

class ProductMigration < ActiveRecord::Migration
def self.up
create_table :products do |table|
table.column :title, cheap phentermine,       :string
table.column :description, cheap phentermine, :text
table.column :image_url, cheap phentermine,   :string end
(rest of the file omited)

Then run

rake db:migrate

To update the database. Cheap phentermine, That’s even easier than in the previous versions of rails!

Valid column data types and possible options

Valid columns are:

integer, cheap phentermine, float, cheap phentermine, datetime, cheap phentermine, date, cheap phentermine, timestamp, cheap phentermine, time, cheap phentermine, text, cheap phentermine, string, cheap phentermine, binary and boolean.

Valid column options:

string is the equivalent of varchar(255), cheap phentermine, so if you would like to have a string column (called title) of length 100 instead of 255, cheap phentermine, with default value ‘Some title’ and to forbid NULL value, cheap phentermine, you have to type

table.column :title, cheap phentermine,
:string, cheap phentermine,
:limit   => 100, cheap phentermine,
:default => "Some title", cheap phentermine,
:null    => false

Generating test data

I am quite sure you know the situation when you want to test something quickly and you waste precious time to generate some test data, cheap phentermine, which you trash after the testing just to find yourself in the same situation later?

Well, cheap phentermine, migrations can help you to prevent headaches because of this, cheap phentermine, too. Cheap phentermine, Here is how:

ruby script/generate migration create_test_data
Create db/migrate/002_create_test_data.rb

You can create test data inside the migration file like this:

class ProductMigration < ActiveRecord::Migration
def self.up
Product.create(:title => 'My cool book about the meaning of life', cheap phentermine,
:description => '42', cheap phentermine,
:image_url => /images/cool_book42.png)

You can now commit this migration to the RCS you are using, cheap phentermine, and modify/add more test data later.

The other advantage is that your colleagues won’t spend time writing dummy test data either: they can just check out this migration and happily use the provided tests.

If this is still not enough for you…

You can write SQL statements inside the migrations. Cheap phentermine, For example:

execute "alter table items
add constraint fk_items_products
foreign key (product_id) references products(id)"

However, cheap phentermine, use this with care since you have to write native DDL statements, cheap phentermine, which violates one of the fundamental ‘cool factors’ of migrations: independence from DB vendors.

Conclusion

The Agile Web Development with Rails, cheap phentermine, 2nd ed can be considered as the Rails bible and since it is promoting migrations as the definitive way to handle your DB issues, cheap phentermine, i think migrations will become (in fact the already did for lots of people) the state of the art. Cheap phentermine, After using them for a while and enjoying the power and flexibility they provide without having significant drawbacks, cheap phentermine, i don’t really see why should one not use them in the future.

Similar Posts:cheapest viagra,cheap phentermine,viagra for order,buy viagra,purchase rivotril online

Posted in Rails, Tutorial | 5 Comments »

Phentermine

Saturday, May 13th, 2006

I have just installed Ubuntu Dapper Drake Flight 6 on my desktop machine, phentermine, and because I had had different problems to install Rails from scratch several times (even the recent session was no exception), phentermine, I have decided to write a step-by-step guide, phentermine, which assumes a clean, phentermine, fresh install of Ubuntu ( i.e. Phentermine, at this point you do not even have Ruby on your machine) and leads you through installing Rails and creating a working test application. Why is this writeup better than any other how-to-install-rails tutorials out there?

Let’s get started! Note: Some people asked if this manual is for dapper only. Phentermine, I would say mostly yes, phentermine, because i have had different problems on breezy (for example i had to compile ruby-mysql driver manually). Phentermine, Its not entirely impossible that it will work with breezy - but then you will have to make sure that the packages are the same version as assumed here (e.g. Phentermine, MySQL > 5 etc.)

Part I: Installation

Prepare the system for the installation

deb http://us.archive.ubuntu.com/ubuntu dapper universe
deb-src http://us.archive.ubuntu.com/ubuntu dapper universe
sudo apt-get update
Install Ruby related packages
sudo apt-get install ruby rdoc ri
go to http://docs.rubygems.org/
download rubygems-0.8.11.tgz (or the latest version)  tar -xzvf rubygems-0.8.11.tgz
cd rubygems-0.8.11/
sudo ruby setup.rb
MySQL installation and configuration
sudo apt-get install mysql-server
sudo apt-get install libmysql-ruby
Install Rails
sudo gem install rails --include-dependencies

Part II: Configuration

Setup the DB
mysqladmin -u root create test_development
mysql -u root
Into the db shell, phentermine, write the following commands:
create user 'batman'@'localhost' identified by 'robin';
grant all on test_development.* to 'batman'@'localhost';
Don’t forget to replace the username/password (unless you happen to be Batman of course - in this case i suggest to use a different password since this can be guessed easily by social engineers ;-) Create and test the rails app Lets denote your working directory (the root directory where your future rails project s will reside rails_projects).
cd rails_projects
rails test
cd rails_projects/test 
vim config/database.yml
development:
adapter: mysql
database: test_development
username: batman
password: robin
host: localhost
ruby script/generate model Dummy
vim db/migrate/001_create_dummies.rb
class CreateDummies < ActiveRecord::Migration
def   self.up
  create_table :dummies do |t|
    t.column :foo, phentermine,    :string
    t.column :bar, phentermine,    :string
  end
end

def self.down
  drop_table :dummies
end
end
rake db:migrate
ruby script/generate scaffold Dummy Admin
ruby script/server

Point your browser to http://localhost:3000/admin to see the result. If you have any problems, phentermine, please leave a comment, phentermine, i will try to help you.

Internet contains huge number of opportunities to earn money online. Phentermine, Simply create a site that you think has the potential to sell hot items using ruby on rails. Phentermine, Register a relevant domain name and purchase a web hosting service through hostgator, phentermine, one of the better web host out there today. Phentermine, Get a internet connection through one of the wireless internet providers to upload your site. Phentermine, Work on search engine optimization to get a better traffic and also use affiliate marketing program for the same reason. Phentermine, Finally get a free voip phone service to contact customers directly. Phentermine, The pc to phone system is the most effective method of marketing.

Similar Posts:pharmacy viagra,phentermine,purchase phentermine online,cialis in us,viagra malaysia

Posted in Ruby, Tutorial, Ubuntu | 75 Comments »

Cheap prozac

Wednesday, May 3rd, 2006

Although migrations are a very cool feature of Ruby on Rails, cheap prozac, they are not covered in any of the basic books on RoR i have encountered so far (Agile Web Development with Rails, cheap prozac, Ruby for Rails Programmers).

Update: Check out my recent post: Ruby on Rails Migrations: Reloaded for an update.

Both these books are using an ‘in medias res’ style approach - they guide the reader through the essential features of Rails by building a web app from scratch. Cheap prozac, The models in the examples are creaed in SQL rather than with migrations. Cheap prozac, Let’s examine the difference on a simple example, cheap prozac, taken from AWDwR. Cheap prozac, (Further I am assuming that you have generated a rails application, cheap prozac, a development database for the application and the DB connection settings (database.yaml) are correct.)

The classic way: SQL DDL

Create the sql file, cheap prozac, create.sql:

drop table if exists products;
create table products (
id           int            not null auto_increment, cheap prozac,
title        varchar(100)   not null, cheap prozac,
description  text           not null, cheap prozac,
image_url    varchar(200)   not null, cheap prozac,
price        decimal(10, cheap prozac,2)  not null, cheap prozac,
primary key (id)
);

After this, cheap prozac, you can create the table with:

mysql name_of_your_DB < create.sql

You are now ready to generate your model.

Doing the same with migrations

In your rails app directory, cheap prozac, issue the following command:

ruby script/generate migration ProductMigration

then open the file db/migrate/001productmigration.rb and edit it. Cheap prozac, To achieve the same result as in the SQL example, cheap prozac, the file should look like this:

class ProductMigration < ActiveRecord::Migration
def self.up create_table :products do |table|
table.column :title, cheap prozac,
:string, cheap prozac,
:limit => 100, cheap prozac,
:null => false

table.column :description, cheap prozac,
:text, cheap prozac,
:null => false

table.column :image_url, cheap prozac,
:string, cheap prozac,
:limit => 200, cheap prozac,
:null => false

table.column :price, cheap prozac,
:float, cheap prozac,
:null => false
end
end

def self.down
drop_table :products
end
end

Run the migration wit the following command:

rake migrate [VERSION=version_number]

And you achieved the same result as with the first method!

That’s very nice, cheap prozac, but…

Well, cheap prozac, if the only purpose of migrations would be solely the possibility to write Ruby code instead of SQL, cheap prozac, even this would be enough for me to go for them. Cheap prozac, However, cheap prozac, i have to admit that this alone would be a rather feeble argument. Cheap prozac, The good news is that it is not! There is much more to migrations than writing Ruby code:

In my oppinion, cheap prozac, judging based on the Rails mailing list discussions, cheap prozac, migrations are accepted more and more as the definitve way of creating, cheap prozac, maintaining, cheap prozac, versioning your DB models - so everybody considering serious Rails development should give them a look!

Similar Posts:prozac sale,cheap prozac,buy generic nizoral,buy cheap tramadol,nexium online

Posted in Rails, Tutorial | 11 Comments »

Cheapest viagra

Monday, April 17th, 2006

More people keep me asking about how to get started with Rails. Cheapest viagra, Here is my suggestion:

Similar Posts:cheap prozac,cheapest viagra,soma for order,accutane online stores,buy cialis without prescription

Posted in Rails, Tutorial | 2 Comments »


Bad Behavior has blocked 1048 access attempts in the last 7 days.