I’m introducing a text / code generation tool that you will fall in love with. If you’re a developer or someone who works with text or tabulated data you need this tool.
It’s called Nimble Text and it’s awesome. Here’s how the developer of Nimble Text describes it:
You can be more awesome at your job by keeping this tool always within reach.
NimbleText is a text manipulation and code generation tool available online or as a free download. It magnifies your ability to perform incredible feats of text and data wrangling.
So it’s a bold claim to say this will make you better at your job. Sounds crazy right?
I have been using this for years (since 2011-2012) and I can tell it’s certainly made me more effective.
Download it and follow along.
If you look at the screen that comes up when you first run it, you can get a really good idea of how it works.
You paste in some data, usually in columns and rows (Comma, tab separated, etc.) You put in your pattern ($0, $1, etc represents the columns) For each row of data it will substitute the values and display the results.
in the sample above, you can see rows of data that appear to be last name, first name, company name.
So let’s look at the top row. In our substitution pattern we’re creating an email and it shows $1 (2nd column, starts at 0) which we know is a first name. Then we have a period, and then $0 which we know is the last name, then @ $2 .com which we assume will make Initech.com.
One of the coolest parts of this is that the pattern doesn’t need to be line by line and you don’t need to be a Regex expert to do this.
Here’s another example of how you can quickly add quotes around CSV values. This is using data from Mockaroo.
So we take this CSV file and dump it in the input:
Then we use this simple pattern, which puts quotes around all the values:
We press generate, and get this:
It’s that easy! But this is isn’t really impressive, because you probably aren’t doing a ton of CSV format conversions on a daily basis. But there’s a lot of potential here.
So there are tons of things you can do with this that are explained on their website. You can do cool things like remove leading trailing and leading spaces or convert spaces to tabs. I love using things like converting to Camel Case and I’ve done weird stuff with Base64 encoding.
I won’t repeat what’s already been written there. I’ll tell you how I’ve been using it all these years.
Let’s take our sample data set:
And we’ll see what we can do with it.
Create JSON
Let’s say I want to make JSON out of this. I would put in a pattern like this:
{
"id": $0,
"first_name": "$1",
"last_name": "$2",
"email": "$3",
"gender": "$4",
"ip_address": "$5"
}
Nimbletext then prints this out:
In multiple rows for as many items as I have. Very cool, and easy.
So as a C# Developer sometimes I’d generate fake data and then use it for Unit testing. With our sample data, I would create a class like this:
public class Person
{
public string Name { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Gender { get; set; }
public string IPAddress { get; set; }
}
Then, let’s say I want to create a collection of these objects. I then enter a pattern like this into Nimble Text:
new Person { Id = $0, FirstName = "$1", LastName = "$2", Email = "$3", Gender = "$4", IPAddress = "$5" },
Then, I click “calculate” and get this:
Which generates a nice set of mocked objects for testing:
I have done this countless times over the years. Once you get it into your regular workflow, mocking up data takes seconds.
You can even make SQL statements like this:
Pattern:
$ONCEINSERT INTO Person (id, first_name, last_name, email, gender, ip_address) VALUES
$EACH($0, "$1", "$2", "$3", "$4", "$5"),
The $ONCE variable prints the first statement, then $EACH loops through after that. So you get this in return:
Easy as pie! Anything you can do with JavaScript you can do with Nimble Text.
So this is odd but something I’ve had to do in the past, and Nimble Text works great for it. Here’s how you create an HTML table for our sample data:
$ONCE<table>
$ONCE<tr><th>ID</th><th>First Name</th><th>Last Name</th><th>Email</th><th>Gender</th><th>IP Address</th></tr>
$EACH<tr><td>$0</td><td>$1</td><td>$2</td><td>$3</td><td>$4</td><td>$5</td></tr>
$ONCE</table>
This tool will help you become a better, more effective developer. You can use it for all kinds of code generation. I’ve done some crazy things with the Keywords and Functions in this program. You can write code to generate code.
I’ve seen the most benefit with time savings. Things like mocking data or processing CSVs are boring and tedious. When you’re doing boring tedious things you make mistakes. So once you work this tool into your workflow you’ll work faster with fewer mistakes.
Once it becomes a part of your routine you won’t want to work without it.
Download it, try it out, and let me know what you think!