XxDesmusxX.NET Simplicity is underrated.

15May/08Off

Baby’s First Ruby App

So I've begun to learn Ruby (for work), and I thought I might share a little bit of my progress so far. Progress might be an exaggeration considering how basic this application actually is, but at least I'm slowly but surely moving in the right direction anyway.

So here's the 1st part of it:

   1:  #GET INPUT
   2:  puts "Please enter a number"  
   3:  STDOUT.flush  
   4:  num1 = gets.chomp.to_i
   5:   
   6:  puts "Please enter another number"  
   7:  STDOUT.flush  
   8:  num2 = gets.chomp.to_i
   9:   
  10:  puts "Please pick the type of operation:
  11:  (A)dd
  12:  (S)ubtract
  13:  (M)ultiply
  14:  (D)ivide)"  
  15:  STDOUT.flush  
  16:  oper = gets.chomp
 

So here we're asking the user for 2 numbers, cleaning up the input, and then storing it into 2 variables (num1 and num2). We then ask the user to select which type of mathematical operation they'd like to perform (addition, subtraction, multiplication, or division).

The 2nd part:

   1:  #SELECT THE OPERATION
   2:  if oper == ("a" or "A")  
   3:          add(num1, num2)
   4:      elsif oper == ("s" or "S")
   5:          subtract(num1, num2)
   6:      elsif oper == ("m" or "M")
   7:          multiply(num1, num2)
   8:      elsif oper ==  ("d" or "D")
   9:          divide(num1, num2)
  10:  end

So here we're deciding what we're going to do with our 2 variables (num1 and num2) based on the users selection. If they enter "a" or "A" (for example) we will then execute the method called "add" on line 3. Speaking of these methods...

The 3rd and final part:

   1:  #DEFINE THE METHODS
   2:  def add(num1, num2)  
   3:    sum = num1 + num2
   4:    puts "#{num1} + #{num2} = #{sum}"
   5:  end  
   6:   
   7:  def subtract(num1, num2)
   8:      if num1 > num2  
   9:        diff = num1 - num2
  10:        puts "#{num1} - #{num2} = #{diff}"
  11:      else
  12:        diff = num2 - num1
  13:        puts "#{num2} - #{num1} = #{diff}"
  14:      end
  15:  end  
  16:   
  17:  def multiply(num1, num2)  
  18:    prod = num1 * num2
  19:    puts "#{num1} X #{num2} = #{prod}"
  20:  end  
  21:   
  22:  def divide(num1, num2)  
  23:      if num1 > num2  
  24:          div = num1 / num2
  25:          puts "#{num1} /  #{num2} = #{div}"
  26:      else
  27:          div = num2/num1
  28:          puts "#{num2} /  #{num1} = #{div}"
  29:      end
  30:  end 

Each one of these methods (starting on lines 2, 7, 17, and 22) perform a particular set of functions based on the variables that are being passed in (num1 and num2). These methods are called based on the earlier code (part 2) that selected which method applied based on which of the mathematical operations the user selected. The 2 numbers that the user entered are passed into that method, some type of calculation is carried out, and then the result is displayed to the user. In the case of subtraction and division, I elected to add an additional step that would determine which of the 2 entered numbers was larger, and then it would order the calculation accordingly so as to not return a negative number (but this is purely optional).

To recap, and provide a plain English flow of how this happen in this simple little application: the user enters 2 numbers, and then they select a mathematical operation. Based on that operation we go through a series of checks to match which operation was selected, the 2 numbers entered by the users are passed to the method, and then we enter the applicable method. The method then performs the necessary calculations and displays the output to the user.

Pretty simple, not exactly rocket science, but it's a start at least. I wanted to play with conditional statements a bit, as well as creating and calling my own methods. Next up will be to continue to experiment with arrays and hashes.

12May/08Off

Review: The Hobbit (or there and back again)

The Hobbit

The Hobbit by J.R.R. Tolkien

ISBN: 0618260307
This book is available on Amazon

The Hobbit is a prequel to the infamous The Lord of the Rings trilogy. This won't be your naive run-of-the-mill "this book rocks!!" type of reviews. To be quite honest, I found this novel to be rather bland and uninspired. It felt quite drab and lacking any kind of compelling plot when compared to the action packed extravaganza that the LOTR's trilogy provided. It's tough for me to recommend this famous book to anyone considering I so thoroughly loathed reading this, but perhaps if the potential victim hadn't already been spoiled by the wonderful journey that is the LOTR trilogy then they might find it exciting.

Rating: ★★★☆☆ 

Tagged as: Comments Off
4May/08Off

A New Chapter: Things to do this Summer

I thought I'd briefly update what I plan to accomplish this summer. The semester is finally finally done and over with (see my recent post regarding the ridiculous amount of things I needed to finish in the past 3 weeks).

  • Reinstall Windows Home Server (WHS). Never mind, not going to reinstall.
  • Read “Head First SQL.
  • Read “A History of God”. Never mind, this looks to be quite boring.
  • Read “The Hobbit or There and Back Again”. DONE
  • Have some type of relaxing vacation.
  • Decide if I will keep my web hosting.
  • Reinstall XP on my desktop because Vista sucks (even with SP1).
  • Rewrite my current blog theme from scratch (it’s using tables right now…ick!). Never mind, not applicable any more.
  • Update my laptop to Vista SP1 (why not reinstall XP? don’t ask). DONE
  • Work related: apparently I'm going to be learning Visual Basic this summer. We'll see.
  • Work related: I also may be learning Ruby on Rails (jRails specifically). We'll see.
25Apr/08Off

Going to Brooklyn, and the past 2 weeks

I'm taking a break from packing up for my trip to Brooklyn this weekend (to see HER), so I thought I'd briefly summarize the past few weeks of my life. I'm sure I'll forget to include a few things, but here's the short list of everything I'd completed (or things that remain to be completed) recently:

  • History and systems -- 6 page thoughtful response to The Metaphysical Club
  • History and systems -- 15-20 page research paper discussing the Mind/Body Problem (dualism, materialism, idealism)
  • Philosophy -- paper discussing the validity of knowledge, and what we can truly know for certain
  • Philosophy -- paper discussing the types (or type, depending on your opinion) of substances in the world.
  • Cognitive psychology -- 5 page paper discussing how I would improve the human memory system.
  • Cognitive psychology -- test on decision making, creativity, artificial intelligence, general intelligence, and problem solving.
  • Math -- investment project examining the effects of initial investment, length of investment, and interest rate as individual factors that effect the final amount of money.
  • Math -- 12 page paper briefly discussing the historical foundations of cryptography and it's modern versions (on a very basic level, I didn't get into all the really ugly details).
  • Math -- present a brief poster and presentation on what I learned about cryptography. We're talking 2-3 minute presentation; not a big deal.
  • Psychology of personality -- 5 page paper relating Alfred Adler to events in my own life. We had to pick a personality theorist that we felt we could relate with.
  • Psychology of personality -- test on existential psychology, humanistic psychology, Gestalt psychology, and object relationism.
  • Independent research -- running out study looking at evaluative conditioning
  • Independent research -- writing a 12 page paper investigating the possibility that the resistance to extinction in evaluative conditioning that has been observed may in fact be due to alternative explanations.

Oh yeah, and I've been crazy busy at work. They essentially gave me a project to complete that involes making significant changes to an application written in Visual Basic 6 (yes, I know it's really old), but the problem is that I don't have any knowledge/experience with Visual Basic 6. This wouldn't be that much of a problem considering that I could probably learn Visual Basic 6, but the really humorous part of this project is that it's supposed to be completed in 10 days. So yeah...learn a new language, make the changes, test the changes, and roll it out to the users in 10 days. Um, no thanks.

Anyways, my point is that virtually everything on that list above is now completed. Perhaps that might explain why I've been absent from writing non-Twitter related blog posts for nearly a month.

Did I mention I'm leaving to go see HER (the infamous her) in just over 3 hours? :)

4Apr/08Off

Interesting Links 4.4.08

An interesting collections of links, primarily aimed at CSS this time. I can't wait for this semester to be over with so I can get back to some web design. I am so behind in terms of things I want/need to read at this point.

Tagged as: Comments Off
7Mar/080

Interesting Links 3.7.08

I apologize, but I am far too lazy to write a blurb about each one of those links. I'll just leave it at this: IE8 Beta 1 is a step in the right direction, TeamViewer kicks ass for remote computer support, and the 6 animals that can destroy you is hilarious to read.

Tagged as: No Comments
17Feb/080

Redux: Things to do when this semester is finally over

Posts in this series:

  1. Things to do when this semester is finally over.
  2. Redux: Things to do when this semester is finally over
  3. A New Chapter: Things to do this Summer

My list of "things to do once the semester is over" keeps growing in length so I thought I'd just I'd add them on:

  • Reinstall XP on my desktop because Vista sucks (even with SP1).
  • Rewrite my current blog theme from scratch (it's using tables right now...ick!).
  • Update my laptop to Vista SP1 (why not reinstall XP? don't ask).