Writing is hard work. A clear sentence is no accident. Very few sentences come out right the first time, or even the third time. Remember this in moments of despair. If you find that writing is hard, it’s because it is hard.
– William Zinsser, On Writing Well
Editing is the hardest part of writing and one that I skip the most. I try hard not to skip editing, but often I end up being lazy to do the hard work. I try to cover this up with some tools to make it faster. It is hard for one tool to get it all right. So it’s best if you have a range of tools under your belt to support you with writing.
The Hemingway Editor highlights hard to read sentences, adverbs, complicated phrases, etc. The writing app uses different colors to highlight the various issues as shown below. The editor also shows a summary of the text including the reading time, total words, sentences etc. The app also shows a Readability Grade using Automated Readability Index.
The Hemingway Editor is available for free on the web with lesser features. The web application does not let you save your work. You are always at risk of loosing the work if you are authoring on the site.
The Windows/Mac applications supports a larger set of features but for a price. The desktop application works without an internet connection, allows publishing to Wordpress/Medium. It also supports to exporting to different formats (word, pdf, html, markdown etc.).
I use the Hemingway Editor (on the web) occasionally and find it useful at times. It’s good to double check for any issues before publishing the post. Hope this helps you as well in your writing.
How to sign a PDF using Azure Key Vault? - This is one of the questions that I often get regarding Azure Key Vault. In this post, we will explore how to sign a PDF using a certificate in Azure Key Vault. Signing a PDF has various aspects to it which are covered in depth in the white paper - Digital Signatures for PDF Documents. We will be using the iText library to sign the PDF. iText is available as a Nuget package library. The below image shows the elements that composes a digital signature on the left and actual contents on the right.
Signing with a Local Certificate
When the certificate (along with the private key) is available locally, signing the PDF is straightforward. You can load the certificate as an X509Certificate from the local certificate store using the thumbprint. Make sure that the certificate is installed with the Exportable option as shown below.
The PrivateKeySignature is an implementation of IExteralSignature that can be used to sign the PDF when the private key is available. The below code signs the Hello World.pdf using the certificate from the local store and saves that as Local Key.pdf.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Certificates in Azure Key Vault
You can manage certificates in Azure Key Vault as a first class citizen. Azure Key Vault supports creating new or uploading existing certificates into the vault. Key Vault provides an option to specify whether the private portion of the certificate is exportable or not. Let us see how we can use the certificate from the vault in both these scenarios.
To create a self-signed certificate in the vault use the below PowerShell script. In this case, the private key is exportable. Executing the below script adds a self-signed certificate into the vault.
Creating a certificate, in turn, creates three objects in the vault - Certificate, Key, and Secret. The certificate represents the certificate just created, the Key represents the private part of the certificate, and the Secret has the certificate in PFX format (just as if you had uploaded a PFX as a Secret). Since the certificate created above is exportable, the Secret contains the Private portion of the key as well. To recreate the certificate locally in memory, we use the below code
1 2 3 4 5 6 7 8 9 10 11 12
The certificate is encoded as Base64String in the Secret. We create an in-memory representation of the certificate and mark it as Exportable. This certificate can be used the same way as the local certificate. Since the private key is part of it, the PrivateKeySignature can still be used to sign.
Non Exportable Certificate
To create a non-exportable certificate when creating the certificate use KeyNotExportable flag flag as below.
Executing this creates three objects in the vault as above. But since we marked the secret as non-exportable, the Secret will not have the private part of the key. We can create an in-memory representation of the certificate, but we cannot use the PrivateKeySignature as the certificate does not have the private key. We need to use the Key created along with the certificate to Sign the PDF bytes. For this we need a custom implementation of IExternalSignature - KeyVaultSignature.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
KeyVaultSignature uses the key vault library to connect to the vault and use the specified key to sign the passed in PDF bytes. Since the key is the private part of the certificate, it will be validated by the public key. Below code shows how to use the KeyVaultSignature in the signing process.
1 2 3 4 5 6 7 8 9 10 11
Once you install and trust the public portion of the certificates, you can see the green tick, indicating that the PDF is verified and signed.
The sample code for all three scenarios is available here. I have used ClientId/Secret to authenticate with Key Vault for the sample code. If you are using this in a production environment, I will recommend using certificate to authenticate with Key Vault. iText supports creating PDF stamps and more features in the signing process, which is well documented. Hope this helps you to secure your PDF files.
Merging conflicts can be a pain when working in large teams and code bases change fast. Every time you sync with the main code base you need to make sure that you integrate the updates with your work in progress. It’s great when the changes get automatically merged by the source control systems. But when things need to be manually merged is where a good tool can be of help.
Beyond Compare allows you to quickly and easily compare your files and folders. By using simple, powerful commands, you can focus on the differences you’re interested in and ignore those you’re not. You can then merge the changes, synchronize your files, and generate reports for your records.
The Text Compare viewer is the one that I use most frequently to compare or merge different versions of code. Beyond Compare makes it easy to spot the code differences and gives the capability to copy the code from one version to another. One can also copy portions of changes and merge just that instead of all the changes. The 3-Way Text Merge feature is also useful, especially when you are using Git.
Beyond Compare is one of the tools that I use almost daily. Check it out if you have not already.
When it comes to mobile phones, I used to be a gadget freak and buy the latest phone as soon as it arrives in the market. But not after I got the Nexus 5. It’s been well over three years now and not even once did I want to switch over to something else. The phone never slowed down over these years, and the battery lasted enough for the day. I broke the Nexus screen a couple of months back and was forced to switch over to a new phone. I didn’t have to do much market research or phone comparisons this time; as I just knew which one to pick up.
The Pixel is the first phone in the Google Pixel hardware line and is a successor to the Nexus range of devices. The Pixel runs Android-Nougat with some features exclusive to it. The Pixel is very much comparable to the Nexus, with improved hardware and latest software. Below are some of the key features that I like about the phone.
Fingerprint sensor The fingerprint sensor on the back allows you to unlock the phone and specific apps and also authorize purchases. 1Password is integrated with the sensor which enables me to unlock it using the sensor. I no longer need to type in my long master password every time I use 1Password.
Camera Pixel takes brilliant photos in bright light, low light, and any light. The camera is awesome and at times is a good replacement for your DSLR. With Pixel, Google also provides unlimited original quality storage for all photos and videos.
Google Assistant Pixel is the first phone with the Google Assistant built-in. It helps you manage tasks, find content on phone and the internet, perform actions, etc. just like Siri or Cortana. I have not used the assistant much and yet to find some valid use cases.
Some of the apps that I use regularly are
- Todoist: My ToDo List
- Feedly: For all my RSS feeds
- Pocket: For offline reading and read later
- 1Password: Password Manager
- Buffer: To schedule articles to all social networks
- Rescue Time: Automatically tracks where I spent time on mobile
- Strava, Runtastic & Garmin Connect: Tracking my runs and exercises
- Kindle: Reading kindle books
- Twitter, Whatsapp, Messenger, Instagram, Skype & Yammer :Social Networking apps
- JotterPad: Write articles for blog in markdown format
- Google Indic Keyboard: Writing in my native language
- Gmail & Outlook: Emails
- Youtube: Videos
I am using the Spigen Neo Hybrid case for Pixel. It adds extra weight to the phone, but I am used to it from my Nexus as well. The Neo Hybrid provides military grade protection and protects the phone from most falls.
Overall I have found the Pixel a good phone and recommend it to anyone looking out for a new phone now. The Samsung Galaxy S8 is also of the same range (slightly costlier) and worth considering if you are not too particular about having a vanilla Android experience. Which phone do you use?
Grammarly is a writing platform that helps you polish your writing. Grammarly scans your text for mistakes based on pre-written rules and suggests modifications. A detailed explanation is given on the suggestions made and helps improve your writing over a period.
Grammarly makes sure everything you type is clear, effective, and mistake-free.
With the chrome plugin, Grammarly is there everywhere that you write on the web. It hides away neatly to a corner without getting in the way of your writing.
You can author text either in the website, or have Grammarly watch your back as you type anywhere in Chrome with the plugin, integrate it with Microsoft Office or use the Windows app. Check out the apps section to get more details. You can try Grammarly for free and check for critical grammar and spelling mistakes. With the premium version you get a lot more features and grammar rules. Currently, I am on the premium version and recommend it.
Try Grammarly for free and see if it helps you as well.
Aesthetics of code is as important as the code you write. Aligning is an important part that contributes to the overall aesthetics of code. The importance of code aesthetics struck me while on a recent project. Below are some the code samples that I came across in the project. Traversing this code base was painful to me as the code was all over the place.
1 2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 6 7
The code has too many alignment points that attract the eye which makes it hard to read in the first place. When in isolation this might still be fine to read, but with such a style across the code base, it soon becomes a pain for your eyes and your mind. When refactoring code, it becomes even harder as you need to put in the extra effort to make sure that this fancy alignment is maintained. Let’s take a look at how even changing a property name (Company to CompanyName) or function name(ConnectToServer to Connect) will affect the current formatting.
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
As you can see above the formatting is now all over the place, and you need to format them into place manually. Again when in isolation this might seem like a few press of spacebar. But when the property/function that you rename is used in multiple places this soon becomes a problem. Such code formatting introduces maintenance overhead and soon falls out of place if something gets missed.
Better Ways To Format Code
Left aligning code is one of the key things that I try to follow always. Keeping the code aligned to the left makes it easier to read (assuming that you are programming in a language written from left to right). Since we read from left to right having most of the code aligned to the left means that you have more code visible. Left aligning also means that you would almost avoid the need to scroll the code editor when reading through the code horizontally.
Let’s take a look how left aligning the above code will look like.
1 2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 6 7 8
1 2 3 4 5
As you can see above left aligning makes it much easier to read and also reduces the number of alignment points. This is also refactoring friendly as there are no specific space patterns that need to be maintained. As for the parameters in a single line VS parameters in multiple lines (as above), I prefer the multi-line approach, as it keeps the code further aligned to the left and also reduces the chance of getting a horizontal scroll bar. You can use Column Guides to remind yourself to keep the code within the acceptable horizontal space.
Code formatting is an important aspect of coding. It is important that as a team you need to agree on some standard practices and find ways to stick to it. You can use styling tools, Code Reviews, etc. to make sure it does not get missed. It takes a while for any new practices to set in, but soon it will be of second nature and easy to follow.
Fiddler is an HTTP debugging proxy server application and captures HTTP and HTTPS traffic. It is one of the tools in my essential toolkit list. Fiddler allows debugging traffic from PC, MAC, Linux and mobile systems. It helps inspect the raw requests and responses between the client and the server.
Some of the key features that I often use in Fiddler are
Inspect Request/Response Look into the request and response data to see if all the required headers/attributes are set, and the data is sent as expected
Compose Web Requests Manually compose requests to send to server and test endpoints.
AutoRespond to Requests Intercept requests from the browser and send back a pre-defined response or create a delay in response to the actual client.
Statistics Fiddler statistics give an overview of the performance details of a web session, indicating where the time is spent in the whole request/response cycle.
Modify and Replay a Request Fiddler allows modifying the request by editing its contents and replay the message to the server.
Export and Import Fiddler makes it easy to share captured traces with different people. All captured traffic or selected requests can be exported and shared with others. The exported saz file can be opened in Fiddler to view back all the session details.
These are some of the features that I use on a regular basis. Fiddler supports a lot more and is extensible to support custom requirements as well. I find it an indispensable tool when developing for the Web. Get Fiddler if you have not already.
The project that I am currently working on using Team Foundation Version Control(TFVC) as it’s source control. After using Git for a long time it felt hard to move back to TFVC. One of the biggest pain for me is losing the short commits that I do when working. Short commits help keep track of the work and also quickly revert unwanted changes. Branching is also much easier with Git and allows to switch between work without much hassle of ‘shelving -> undoing -> pulling back the latest as with TFS.’
The best part with git is that you can use it to work with any folder in your system and does not need any setup. By just running ‘git init’ it initializes a git repository in the folder. Running init against my local TFVC source code folder, I initialized a git repository locally. Now it allows me to work locally using git - make commits, revert, change branches, etc. Whenever I reach a logical end to the work, I create a shelveset and push the changes up the TFVC source control from Visual Studio.
If you want to interact with the TFVC source control straight from the command line, you can try out git-tfs - a Git/TFS bridge. For me, since I am happy working locally with git and pushing up the finished work as shelvesets from Visual Studio I have not explored the git-tfs tool.
Hope this helps someone if you feel stuck with TFVC repositories!
One of the traits of a good unit test is to have just one Assert statement..
Consider Assert failures as symptoms of a disease and Asserts as indication points or blood checks for the body of the software. The more symptoms you can find, the easier the disease will be to figure out and remove. If you have multiple asserts in one test - only the first failing one reveals itself as failed and you lose sight of other possible symptoms.
When a test with multiple asserts fails, it is hard to tell the exact reason of test failure. To get more details on the actual failure we either have to debug the tests or look into the stack trace.
Tests With Multiple Assertions
Many times we end up needing to assert on more than one properties or behavior. Let’s look at a few such examples and see how we can refactor the tests. I have excluded the actual code that is getting is tested here as it is easy to understand what that will look like from the tests. (Drop a comment otherwise)
Example 1: In the below test we have a Name class that represents FirstName and LastName of a user. It exposes a Parse method to make it easy for us to create a Name object from a string. Below are some tests for the Parse method. The test has multiple assertions to confirm that the first and last name properties get set as expected.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Example 2: The below test is for the Controller class to confirm that the CustomerViewModel passed to the Post method on the controller saves the Customer to the repository. The assert statement includes multiple properties of the customer object, which is just a shorthand version of writing multiple such assert statements on each of those properties.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Example 3: The below test ensures that all properties are set when transforming from DTO to domain entity (or any such object transformations at system boundaries). The test asserts on every property of the class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Semantic Comparison Library
SemanticComparison makes it easier to compare instances of various objects to each other. Instead of performing a normal equality comparison, SemanticComparison compares objects that look semantically similar - even if they are of different types
Using SemanticComparison, we can compare two objects and compare their properties for equality. It allows including/excluding properties when comparing objects.
Example 1: The Name is a perfect case for being a Value Object. In this case, the class will override Equals, and it will be easier for us to write the tests. Converting to a Value Object is one of the cases where we use tests as a feedback to improve code. But in cases where you do not have the control over the class or do not want to make it a value object, we can use SemanticComparison to help check for equality as shown below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Example 2: Using SemanticComparison we can remove the need of asserting on each of the properties. In the below case since the Customer Id is set to a new Guid in the ToCustomer method, I ignore the Id property from the comparison using Without. When the expected objects gets compared against the actual all properties except Id will be compared for equality. Any number of properties can be excluded by chaining multiple Without methods.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Example 3: Using SemanticComparison we can remove the asserts on every property and also set custom comparisons. The StartDate and EndDate on the persistence entity are converted into a DateRange object (Period). By using the With method in combination with the EqualsWhen method we can set custom comparison behavior that needs to be performed when comparing objects. The same test will hold true even if we add new properties and will force mapping to be updated if any of the property mappings is missed. Here we also see how SemanticComparison can compare two different types.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Using SemanticComparison library, we reduce the dependencies on the actual implementation and extract that into a more generic representation. Fewer dependencies on the actual implementation code/properties make the tests more robust and adaptable to change. Hope this helps you get started with Semantic Comparison and improve on your test assertions.
If you are looking to get a case for your phone, then check out cases by Spigen. I have been using Spigen cases for over three years, and I totally recommend it.
Spigen cases are made with premium materials and are slim, sleek and simple. Spigen provides various models that match different needs. The cases provide Military Grade Protection and protect the phone from most falls.
The first Spigen cases I got was for my Nexus 5. The Neo Hybrid lasted for over three years. With the Spigen cases, the Nexus was well protected. It did fall from my hands many times, and every time the case protected it well enough. A couple of months back the Spigen case broke, and I had been using the phone without a cover since then. Unfortunately, during one of my morning runs the phone fell from my hands while slipping it into the armband. Without the Spigen to protect it, the Nexus screen broke at the corners.
A month back I switched over to Google Pixel as the Nexus was becoming unusable with the broken screen. I got the Spigen NeoHybrid for Pixel. The case provides dual layer protection with TCU and PC bumper and comes with fingerprint resistance. The precise cutouts give easy access to all buttons and fingerprint sensor.
If you are looking to a get a case, check out if Spigen has one for your model!