CSV Splitter

A nifty command line tool to split up a csv file, based on column values.
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:


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:


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

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

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:

  <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:


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!

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']

Transfer entire directory via SSH (Linux)

Transfer entire directory via SSH (Linux)

scp -r login@server:/remote/directory/ /local/directory/

Search/Replace in Linux

Search and replace on multiple files in multiple directories is really easy in Linux:-

find *enter directory here* -type f -exec sed -i 's/*enter search string here*/*enter replacement string here*/g' {} ;


find /home/jaffamonkey/testfiles -type f -exec sed -i 's/I am a nerd/I am a geek/g' {} ;

Using PhantomJS with Behat

Firstly, to install phantomjs you need to install it’s dependency, NodeJS:-

sudo npm install -g nodejs

Then install PhantomsJS (I would recommend using npm as it installs it correctly, including updating bin path):-

sudo npm install -g phantomjs

Continue reading