Markdown cheat sheet for Visual Studio Code

Here is a cheat sheet that I found somewhere that will work with Visual Studio Code MD files: “# README” <!– M A R K D O W N   C H E A T  S H E E T –><!– Headings –># Heading 1## Heading 2### Heading 3#### Heading 4##### Heading 5###### Heading 6<!– Italics –>*This text* is italic\*This text\* is not italic_This text_ is italic<!– Strong …

How to pack NodeJS project into a tarball?

Today I needed to install my brand new NodeJS-developed CLI application in my computer. Important! Don’t forget to add this to your package.json file:  “bin”: {    “skynet”: “./bin/skynetApp.js”   }, It’s basically the name of the command and the NodeJS file it will execute, in this case the command name is skynet and every time this is typed in a terminal window it …

Check property of JSON response in Postman

In the Tests section of any request you can check if the JSON response contains or doesn’t contain a specific property like this: // Verify that header object is NOT returned pm.test(“Verify that header:{…} object is NOT returned”, function () {  pm.expect(pm.response.json()).to.not.have.property(‘header’); }); // Verify that data object is returned pm.test(“Verify that data:{…} object is returned”, function () {  pm.expect(pm.response.json()).to.have.property(‘data’); …

Base64 URL Safe Encoding / Decoding (RFC-7515)

A few days back I was required to encode some string in base 64 URL safe. After some research I found that there are several variants of base 64. The one implemented in the code below corresponds to RFC-7515. Here is the code: function encodeBase64Url(str) { let s = new Buffer(str).toString(‘base64’); // Regular base64 encoder s = s.replace(‘=’, ”); // …

How to Encode / Decode to / from base64 in Node.JS

Today I ran into this basic problem. A quick search on google gave me the answer, I tested it, it worked, and the rest is history. Here is the code. let plainText = “Hello World!”; console.log(“Plaint text = ” + plainText); // Encoding to base64 let base64 = new Buffer(plainText).toString(‘base64’); console.log(“Encoded to base64 = ” + base64); // Decoding from …

How to Encrypt / Decrypt with AES in Java 1.8

Here I have created a class that does it in two different ways, the first one is, when you create the key, and the other is when you are given the key, valid key sizes are 128, 192, and 256 for AES algorithm. There is some steps to follow before executing the code provied, if you don’t probably this class …

How to fold / unfold all regions in Visual Studio Code

With JSON files of around 900 lines, this option is very useful to have an organized view. I highly recommend to check the links, there is a lot of things you can do with Visual Studio Code, my version is 1.10.2, and the following shortcuts are working. Ctrl+K Ctrl+0 Fold (collapse) all regions Ctrl+K Ctrl+J Unfold (uncollapse) all regions Sources …

How to generate X.509 certificate in Java 1.8

Here is how to do it, the simplest way, to generate the base64 string. No complications with KeyStores or things like that. I must say that I found this code in several places over the Internet. When I tried to run it I had some exceptions, I solved them, at the time of this writing, the following code works with …

How to generate SHA256HMAC in Node.JS

Today I had to do this for my job (hash some info) and I think is a good opportunity to share the knowledge. Here is the code, you can simply copy it and paste it in a file called SHA256Hmac.js and run it. let crypto; try {     crypto = require(‘crypto’); } catch (err) {     console.log(‘crypto support is disabled!’); …

How to convert byte array to hex string in Java 1.8

If you like cryptography you might know that sometimes you have a byte array which you wish to convert to hexadecimal string. In java, to this day, I haven’t found yet a native class that does it, I’ve spent several minutes on the Internet looking for something like the Base64 class. Turns out Apache commons has a class called Hex.java …