Latest Entries »

Running Python on GoDaddy


If you subscribe to GoDaddy hosting, you’ve likely noticed that they claim to support Python. However, if you are a noob to python and the web like myself, it’s unclear how to get started. So, below is a sample on how you can render a simple html page in Python under GoDaddy hosting.

1.) Create a new file with a .cgi extension (i.e. test.cgi – see: http://oscarvalles.com/test.cgi)
2.) Copy and paste the following text into your CGI file.

#!/usr/bin/python2.4
'''
This is a comment,
If you see this, CGI is not working
'''
print "Content-type: text/html\n\n"
print "<body bgcolor='000'>"
print "<font face='Courier New' color='white'>Test python page.  CGI extension </font>"
print "</body>"

Let the fun begin.

Non-invocable member System.Data.DataSet.Tables cannot be used like a method


After filling in your dataset with your data adapter, you probably want to transfer that information to a DataTable so that you can display it on a your page’s datagrid, use it in an export to .csv function or something to that nature. However during compile time you may receive the following error:

Non-invocable member ‘System.Data.DataSet.Tables’ cannot be used like a method

One of the reasons you may be receiving this error is due to the way you have the DataTable name enclosed.  It should be in brackets instead of parenthesis.

Code Example:

DataTable dtEmployeeList;
return dtEmployeeList = dsEmpTable.Table("Employees");

Instead change the parenthesis to brackets:

DataTable dtEmployeeList;
return dtEmployeeList = dsEmpTable.Table["Employees"];

Since methods headers consist of a method name followed by parenthesis, the compiler will read the first dsEmpTable.Tabe(. . . as an attempt to invoke a method.  Once you change it to brackets it should take care of the problem.

Rules for exponents


This article discusses the practical application of exponent rules and how they relate to business and finance scenarios.

A common use of exponents in business and personal finance is the investment of money at a fixed rate for a variable period of time.  For example, let’s say we have $10,000 we want to invest.  A CD yields a 6% annual rate, so we decide we want to invest it for 20 years since.  What will be it’s value when the CD matures?

You may already know that the formula to compute this simple interest calculation is A = P(1 + i). Where P = $10,000, i = the 6% interest rate and n is the 5 years you can invest your money for in the CD.

However, it is useful to understand the mechanics of the formula because many variables can come into play later.  For example, if you felt the yield was good and were given the option to roll over the CD 3 times, how would you write that as an equation and solve it?  Below are the common rules for exponents.

Below is the list of the rules for exponents:

  1. The Product Rule for exponents
  2. The Zero Exponent Rule
  3. The Quotient Rule for Exponents
  4. The Power of a Power Rule for Exponents
  5. The Power of a Product Rule for Exponents
  6. The Power of a Quotient Rule for Exponents

 

The Product Rule for Exponents:

When a is a real number and m and n are positive integers then the following applies:

am * an = am+n

  1. 54 * 53 = 58
  2. r2 * r4 = r6
  3. 2y3 * 5y9 = 10y12

 Note that neither bases or exponents are multiplied.  Exponents are added and similar bases remain as one.  This may seem a little odd when comparing example 1 and 3, but think about it this way, in example one, 5 is our base.  Just like we did not change r, in example 2, we do not change 5 from being 5.  However, in example 3, we can consider y as our base and multiply 2 and 5 to note that we now have 10 letter y to the 12th power (12 came from the adding the exponents 3 and 9).

 

The Zero exponent rule

Simply remember that any number to the zero power is 1.

Examples:

  1. 50 = 1
  2. (12xy)0 = 1
  3. 40 + 70 = 2

Example two illustrates the order of operations.  We do what is in parenthesis first, followed by exponents.  Therefore, any calculation could have taken place inside the parenthesis and resulted in any number, however when the exponent of 0 is introduced, the answer becomes 1.

The quotient rule for exponents

Similar to subtraction, the exponent in the denominator is subtracted from the exponent in the numerator.  This results in the base to the power of the difference in exponents.  When coefficients are present, you can reduce and eliminate them in the quotient as necessary.  Sometimes when doing this, you may be left with a fraction equation to work with in a simple form.

Example:

  1. x7 / x4 = x3
  2. 2x10 / 4x3 = (1/2)x3

The answer in the second example illustrates the fraction.  Since this article is being published on the web, the one-half was noted as 1 over two and enclosed in parenthesis.

The power of a power rule

WIth this rule, when an exponent is raised to another exponent, then both exponents are multiplied to become the new exponent.  The same treatment of coefficients applies to this rule as it did to the last one.

Examples:

  1. (23)3 = 29 = 512
  2. (x3)4 = x12
  3. 3x8(x3)6 = 3x26
  4. -10(r4)3 / 5r2 = -2r10

The power of a product rule

With n as a positive integer and a and b real numbers, then (ab)n – an * bn

Example:

2x4 = 24 * x4 = 16x4

Here, each variable and coefficient will break apart from each other, take the value of the exponent and simplify itself the best way possible before returning to you as a simplified equation.

 

The power of a quotient rule

(y/3)3 = (y3/33) = y3/27

The quotient rule applies when nonzero real numbers are used as the variables and the nonnegative integer is the exponent.

 

That concludes todays reference of the rules of expressions.  In the future we will revisit these methods under some real life work problems.

Various ways to solve for a linear equation


Linear equations can be presented to you in various ways and by the same token you can solve a linear equation a number of ways. The first step in solving a linear equation is determining the slope.
Here is a list of ways to arrive at the slope.
 
1.)    Given a graphed line, choose two points on the line. Count the rise on the y-axis over the run on the x-axis. Essentially, the slope, m, = rise/run.
2.)    Starting with the coordinates of two points on line (x1, y1) and (x2, y2) use the formula: m = (y2 – y1) / (x2 – x1)
3.)    Rewrite your equation in the form of y = mx + b. m, the coefficient of x, is your slope.
4.)    A line with an unknown slope that is parallel to a line with slope m1, has the same slope as that line.
5.)    A line with an unknown slope that is perpendicular to a line with slope m1 will have a slope equal to the opposite of the reciprocal of m1, that is -1/ m1.
 
 
Next, look at the data points that you have to work with. For example, if you are told that you have $150 to purchase bolts that cost $2 and washers that cost $3, then let x represent bolts and y represent washers. Therefore, your purchasing power is:
 
$150 = 2x + 3y.   You can find two sets of coordinates by setting y = 0 and solving for x and x = 0 and solve for y, which will give you (75, 0) and (0, 50) respectively. Given these two points, you can solve for the slope using item number two, listed above.   
 
m = (50 – 0) / (0 – 75) = -2/3
 
Once you calculate the slope, you will be ready to solve for your equation. 
To do that, use the following method where cp = coordinate point and m=slope:
 
(y – cpy) / (x –cpx) = m
(y – 50) / (x -0) = -2/3
 
Steps to solve for the equation:
 
1.)    (y – 50) / (x-0) = -2/3
2.)    y – 50 = -2/3x
3.)    y = -2/3x + 50
Voila, your equation!
 
Alternatively, and more even more quickly, you could have taken the original equation:
$150 = 2x + 3y
and taken the following steps to solve it:
 
1.)    3y = -2x + 150 (subtract 2x from both sides of the equation)
2.)    y = -2/3x + 50 (divide out the three on both sides of the equation)
 
That will give you the slope intercept form y = -2/3x + 50

Rules for overriding methods


In C#, when you have a method in a base class that you would like to use in a derived class but with some modifications you are overriding a method.  When overriding a method in a derived class you must have the exact same signature as the method you are going to override in the base class.  In addition, it is good practice to include the virtual keyword in the signature of the base class method that is to be overridden by a derived class method.

Example method in base class:

public virtual string setSpecies()
{<br />&nbsp;&nbsp; &nbsp;return &quot;Mammal&quot;; &nbsp;&nbsp;<br />}

 

Example – overridden method in derived class

public override string setSpecies()
{<br />&nbsp;&nbsp; &nbsp;return &quot;Reptile&quot;;<br />}