Sunday, November 6, 2011

Editing CSV Files













Before I start telling you about editing csv files, I would like to take a  moment to tell you about  a tool you may find useful.

 "Now, You Can Start Creating Your Very Own Minisite In Just A Few
Minutes
without Having To Hire An Expensive Web Designer!
Save Your Time
and Save Your Money Right Away!"

 Save time and money with a set of predefined templates. Learn more at Minisitebolt.

What are CSV Files?

CSV files are comma delimited files. They are used to move large amounts of data in tabular format, between applications, like a spreadsheet program such as Excel, and companies that are not connected.


In the past, most data was not stored online, and was only accessible on the computer the data was saved to, or the server that it was stored on.


Due to technological advances such as high speed, server side scripting languages like asp.net, and php, client side scripting languages like javascript, and the use of Ajax (Asynchronous JavaScript and XML)., more

applications are being designed for use on the Internet, via the browser of your choice.

Editing


Editing these files can be a challenge, if they are not saved in the right format. There are programs that can assist you; however, every program manipulates the data in a different way. You need to do your research well to find the right program for you and your data.


Computer programmers can build specialized programs to manipulate a csv, but for the common layman, csv file formats can be a challenge.


Client applications like spreadsheets, usually have the ability to save your data in a specified format like csv. Simply select, File - Save As, and choose the csv file format. This will allow you to easily save your spreadsheet file in a csv format.


Unlike the some of the commercial programs, like Microsoft Excel, your data may not be stored properly. I use an open source program called, Open Office 3.1. Unfortunately, the program stores my information with either an apostrophe or a quotation mark, and places them around each column, instead of between them.


Applications that can Assist in Editing CSV files


There are some applications that can assist you in editing csv file formats. One of thes programs is called
Ultra Edit by IDM Computer Solutions, at http://www.ultraedit.com/support/tutorials_power_tips/ultraedit/CSV_files.html.

Php Scripts


If you are a web developer, you should have access to the php scripting language.

I recently needed to manipulate a csv file to use it in a database. It was not in the correct format for me to use it.


The data was saved in the following format, "'column1' 'coloumn2'", I needed to reconfigure the file with a single

comma separating the columns.

Here is a sample of the text I was trying to manipulate:


AAA.TO' 'Allana Potash Corp'

AAB.TO'            'Aberdeen International Inc'
AAB.WT.TO'    'Aberdeen Intl Inc'
AAH.TO'            'Aastra Technologis'
AAV.TO'            'Advantage Oil & Gas Ltd'
AAV.DB.D.TO'    'Advantage Oil & Gas Ltd. 7.75% Debs'
AAV.DB.G.TO'    'Advantage Oil & Gas Ltd. 8.0% Debs'

To enable me to use it properly, I wrote a php script. It took me several hours, but I finally accomplished the task.


Since that time, I found out that it was all for nothing. I didn't spend allot of time going of the website that I downloaded it from, and could of saved allot of time and effort.


It is not perfect but is okay for my purposes. This code can serve as

the foundation for anyone who needs to manipulate csv files.

For anyone who is interested. Here is my code:


$text = file('tsx_list.txt'); //get file


foreach($text as $line) {


$trimmed1 = ltrim($line, "'");

$len_of_trimmed1 = strlen($trimmed1);
  //$trimmed3=(substr($trimmed1, 0, 12));
  //$trimmed3=(substr($trimmed1, 0, 7));
 
  if (substr($trimmed1, 6, 1) != "'")  //Will either be a apostrophe or a dot.
  {
    $part1=(substr
  }
  else{
    $part1=(substr($trimmed1, 0, 7)); //Store the first part of our new string.
  }
 
  //Check criteria to construct the second part of the new string.
 
  if (substr($trimmed1, 6, 1) != "'")  //Will either be a apostrophe or a dot.
  {
      $part2=(substr($trimmed1, 10,$len_of_trimmed1 - 1)); //Save long version
     
      $len_of_part2=strlen($part2);
      $part3=(substr($part2, 3, $len_of_part2)); //Refine part2 to take away first 2 characters.
      $trimmed2.=$part1;
      $trimmed2.=$part3;
      $trimmed2.="
";
      $trimmed2.="
";
  }
  else
  {
        $part2=(substr($trimmed1, 9, $len_of_trimmed1 - 1)); //Save short version
      $trimmed2.=$part1;
      $trimmed2.=$part2;
      $trimmed2.="
";
      $trimmed2.="
";
  }

}


echo $trimmed2;



?>




Conclusion


Editing CS Files can be a challenge, but doesn't need to be. When downloading data in csv format, you need to fully understand how the data is being formatted by the source. The source can be a website, or an application such as Excel, any client side application that can store a file in this format.


Wednesday, October 12, 2011

CSS Gradient Backgrounds for Dividers


















Until IE 9 you were not able to use gradients in IE. Only mozilla based browsers supported them.









To make gradients configure your style sheet to use these lines;

background: #999; /* for non-css3 browsers */

filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#cccccc', endColorstr='#000000'); /* for IE */
background: -webkit-gradient(linear, left top, left bottom, from(#ccc), to(#000)); /* for webkit browsers */
background: -moz-linear-gradient(top, #ccc, #000); /* for firefox 3.6+ */



The three lines I just mentioned will gradiate your background on most browsers. Try it and see what I mean.

Sunday, October 9, 2011

Rounded Corners

















IE didn't recognize rounded corners prior to version 9. In the past rounded corners were only available in mozilla based browsers, such as Firefox, or Opera.



If you wanted to make rounded corners in IE, you needed to create small images, and use a complicated set of dividers to form the area you wanted to make rounded.







Today, with IE 9.x you can create rounded corners with ease. Rounded corners syntax with CCS3 is border-radius. It is easily added, such as properties are to width or position:


.roundElement {
border-radius: 10px;
}


The following statement adds one rounded corner to each of the elements four corners. A specific border element can be added to each element individually using:


.pearElement {
border-top-left-radius: 7px;
border-top-right-radius: 5px;
border-bottom-right-radius: 6px;
border-bottom-left-radius: 8px;
}


I like to use the shorthand notation:


.oddRoundElement {
border-radius: 12px 5px 12px 5px;
/* or */
border-radius: 12px 5px;
}


Since rounded corner elements and border-radius was not standard, each browser implemented their own prefixed {prefix}-border-radius implementation. For more information see, http://davidwalsh.name/css-rounded-corners.

Friday, September 30, 2011

Note To Self About Page Layouts

When you are laying out a web page, consider what you need to do.
Design your page accordingly.

Always make sure you comment the end of your divider tags, or you may
spend hours, and hours trying to find the proverbial needle in a haystack.
One incorrectly placed tag on a page, a tag without a beginning,
or a tag with an incorrect syntax, will cause complete havoc.





Dividers will always work if placed in the right order, and done correctly.
If you are making an inside tag, do not use 100% height. For some strange reason,
the browser will ignore an inside divider with a height of 100%. If you need
to send dynamic content to an inside divider, either use paging or consider a
incorporating a scroll bar into the divider.

Laying out pages can be a chore, but if you take your time and pre-plan your layouts,
creating web pages can be a breeze.

Friday, September 23, 2011

Rules for Dividers

I've learned that there are many rules that apply to dividers. (Dividers separate area's of the screen.) Rules like those for inside and outside dividers (outside and inside dividers are used in setting rows, and columns).

When you work with dividers there will be many times that you will scratch your head, and ponder for hours. You will try one thing after another, until you get it right.




Inside dividers should be fixed widths, one column cannot be longer than the other; otherwise, you will have an overlap. When setting up rows and columns, the widths for a divider must be adjusted to account for borders.

Borders can offset the width of a divider by several pixels. Arrange your dividers carefully. A divider with a dynamic height will be handled different by the browser, than a divider with a fixed height.

There are many more rules that apply to dividers, than the ones I have mentioned in this blog entry. I will update this blog entry with new information, as I come across it.

Monday, September 19, 2011

Ajax Ready States

Ajax ready states tell the browser what to do depending in different scenarios. What
to do while processing, or when a connection is complete.

They are as follows;

0: not initialized.

This is the state of the connection before the open
command is called.

1: connection established.

This state occurs after you have called the open command, but
before you have called the send command.

2: request received.

This occurs when the request has been sent, and at
the headers are available.

3: answer in process.

Here the information is being processed. At this point
you can display a wait message to the user.

4: finished.

This is the state when the request has been completed. At this point
you clear the wait message, and assign some other information to the
user if you wish.

Ready states are very useful in handling information being sent, and received from the server. You can display wait messages, and perform other tasks while a request is being made.

As you develop interactive websites, and online applications, you will become familiar Ajax ready states.

Programming for the Web