CSV Splitter

A nifty command line tool to split up a csv file, based on column values.
http://csvfix.byethost5.com/csvfix.htm
It has many features, but I used it for it’s very efficent file splitting function.

The file_split command splits a CSV input stream into a number of files based on the values of specified fields in the CSV input stream. All the CSV records with the same values for those fields will be placed in the same file. By default, the created files are numbered, but you can also generate files based on the contents of the fields used to perform the split. Unlike most other CSVfix commands, this command does not write anything to standard output, or to any file specified by the -o flag.

Note that any existing files will be overwritten by this command, without warning. Use the -fd flag to locate the output files, and the -fp and -fx flags to name them.

-f fields (Required) : Comma-separated list of filed indexes on which to base the split.
-fd dir : Specifies the directory in which to place the results of the split. Defaults to the current directory.
-fp prefix : Specifies the prefix to use when constructing file names. Default is file_
-fx ext : Specifies the extension to use when constructing file names. The default is csv
-ufn : Use the contents of the field(s) specified by the -f flag to generate file names. No check is made that the fields contain valid filename components, and the command will fail if they do not.

The following example splits the cities.csv file based on the second field, which contains the country code.

csvfix file_split -f 2 data/cities.csv

This produces the following files, each of which contains the cities for a particular country:

file_0001.csv
file_0002.csv
file_0003.csv
file_0004.csv
file_0005.csv
file_0006.csv

With the same data, the following example:

csvfix file_split -f 2 -ufn data/cities.csv

uses the country code values to generate the file names, producing:

file_DE.csv
file_FR.csv
file_GB.csv
file_GR.csv
file_IT.csv
file_NL.csv

Here, file_DE.csv will contain German cities, file_FR.csv French cities, and so on.

Biff #bash bosh

Shell scripts can prove a very useful and quick way to get tedious tasks done. The shell script below creates multiple directories “1000000001” to “”1000000050”.

To create a shell script:-

# sudo nano createdirs.sh

Now add the code below and save

n=1000000001;
max=1000000050;
while [ "$n" -le "$max" ]; do
  mkdir "$n"
  n=`expr "$n" + 1`;
done

To run

# ./createdirs.sh

Use angular.js with WordPress

AngularJS And WordPress

1. Download zip file.
[wpfilebase tag=file id=1 /]
2. Install and activate the plugin.
3. Set wp-angularjs-include to true in Custom Fields on post edit page.

Sample test code:

<div>
  Name:
  
  <hr>
  <b>Hello <span style="color:#ff6600;">{{yourName}}</span>!</b>
<div />

Sample test code output (type anything into the input field to see “Hello …” string update:

Name:

Hello {{yourName}}!

Mock data with Behat

What is mocking for? Mocking allows you to isolate what you are testing, without  dependency on other areas of application development which are no complete. In Behat, You can easily specify mock data using the following format in your scenarios.  Be wary of “over-mocking” or you will end up with too much illusion, and a lot of re-factoring later on!

Scenario:
Given the following users exist:
| userid | username | password | email |
| 10001 | userone | sunshine1 | userone@email.com |
| 10002 | usertwo | sunshine2 | usertwo@email.com |

The example code below implements the scenario context:-

/**
* @Given /the following people exist:/
*/
public function thePeopleExist(TableNode $table)
{
$hash = $table->getHash();
foreach ($hash as $row) {
// $row['userid'], $row['username'], $row['password'], $row['email']
}
}

How does BDD work?

Take a common scenario from end-user on a website. They are on the homepage and want to contact the company. So they click the Contact Us link and are presented a form to fill in. When processed this form will either submit details to the company email address or reject because the end-user has not completed all the fields OR made some error in form (for example the email field). This is a very common feature of most websites. Continue reading

BDD: Is there a difference between programmer and tester?

To automate, you have to code. And if you are automating an application, the logical way to think about it is developing an application to test an application. And to do that from scratch – every time – would be laborious, and unnecessary as there are many common web features. This kind of thinking has been around in software development for decades – to program with reuse in mind. Continue reading