How to delete a WordPress.com website

If you are like me and you have a new hosting service for your blogs you may know that after moving from WordPress.com to WordPress.org you may want to delete that old website. Here is how to do it. 1- Open your web browser and navigate to the blog you want to delete, in my case https://kryptosit.wordpress.com 2- Click on …

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 remove documents from a capped collection in MongoDB

You can’t remove one or all documents from a capped collection in MongoDB. BUT! you can drop the collection! Execute the following command: db.getCollection(‘myCollection’).drop() The result for me is: true There you go, quick and easy. Sources https://docs.mongodb.com/manual/core/capped-collections/ https://stackoverflow.com/questions/33048282/how-to-remove-a-document-from-the-capped-collection

How to count documents of a collection in MongoDB

Today, I had to do this at work. turns out it is very easy. I am using Robomongo 1.0-RC1. I just double click on the collection that I want, in this case knives and I just execute the following query: db.getCollection(‘knives’).count() The result in my case is: 1911 Hope it helps! Sources https://docs.mongodb.com/manual/reference/method/db.collection.count/

How to create a strong password?

There are a few things you can do to create a strong password that will protect your account from being compromised. Use lower case, upper case, numbers, and symbols (check list of valid symbols, this could vary depending on the website / system) Use at least 12 chars to allow a wide key space Don’t use common words or easy-to-guess …

How to generate random bytes in Node.JS

Easy! I discovered this recently and it is interesting to me. Here is a quick example: const crypto = require(‘crypto’); console.log(crypto.randomBytes(1).toString(“hex”)); console.log(crypto.randomBytes(2).toString(“hex”)); console.log(crypto.randomBytes(4).toString(“hex”)); console.log(crypto.randomBytes(8).toString(“hex”)); console.log(crypto.randomBytes(16).toString(“hex”)); console.log(crypto.randomBytes(32).toString(“hex”)); console.log(crypto.randomBytes(64).toString(“hex”)); When you run this code you might see something similar to this: E:\NodeJS>node randomCrypto.js d8 dccd 0709fee2 67d6d7c51cc59f0d af19069e601e47a9141d27d7d828a9d0 f83b7547452099462061734791da57443cc60828de7dcb8f7494eedceb3c889c e2e4a1faaf4190898aaf4fa786e20fe076237854ae4628127cb2eda4bafd3000b42788e347ade94d0c98614a40586b71ded3044879f791adedd6c0d4bb22e9ac The argument passed to the function is the length in bytes, when …

How to activate ES6 in Visual Studio Code

I’ve been looking for this answer for several weeks. Here is how to do it. Go to File > Preferences > Settings (or press Ctrl + ,) Add the following code in the USER SETTINGS tab “jshint.options”: { “esversion”: 6 } I have JSHint installed, if you don’t, you can install it from Visual Studio Code directly. Sources https://stackoverflow.com/questions/29953293/is-there-a-way-to-turn-on-es6-es7-syntax-support-in-vscode

How to Sign data and Verify signature in Node.JS

Another example that occurred to me. Very useful. What will we need? Private key in PEM format Public key in PEM format To get those you will have use OpenSSL, please take a look at this post How to generate RSA public and private keys with OpenSSL. For this example I am using the following 2048 bit RSA key pair: …

How to generate RSA public and private keys with OpenSSL

Before anything, I assume that you already have OpenSSL installed in your PC. In case you don’t and you are a Windows you can download it from this URLs: http://slproweb.com/products/Win32OpenSSL.html http://gnuwin32.sourceforge.net/packages/openssl.htm I personally used the first one. After you are done with the installation follow this steps: Open a command line window and run the following command: openssl genrsa -out …

Elliptic Curve Diffie-Hellman and AES Example in Node.JS

Recently I learned how to generate shared secrets using ECDH in Node.JS, but I still had to know how to use this shared secret. Here is one application for it. Use the ECDH to generate a shared secret and then use that shared secret to cipher/decipher messages between both parties, in this case Joe and Zoe. Here is the code: …