Posts
Running Mailcatcher
MailCatcher can be used in development where you do not have access to an SMTP server but need to see the email being sent - in HTML format.
I started installing mailcatcher (on MacOS 13.2, Apple Silicon, Ruby 3.1.0 - rbenv) with:
gem install mailcatcher
…and it said, “No.”
➜ mailcatcher git:(main) ✗ gem install mailcatcher Building native extensions. This could take a while... ERROR: Error installing mailcatcher: ERROR: Failed to build gem native extension.
Posts
NFS Server Hangs, NFS Client Hangs
I woke up this morning to a disk alert from a server.
Assuming it was a disk-full alert, I run a df -h and it hangs. I then Ctrl-C and try to list individual mount points to check which one is at fault, and it turned out to be an NFS mounted volume.
At this point, I just needed the server alert to go away and the NFS share was only being used for moving files so I attempt to unmount /mnt/nfs_share but that hangs too.
Posts
Deploy Pykmip With Terraform
This one is just a code snippet - deploying PyKMIP with Terraform.
terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 4.0" } } required_version = ">= 1.3" } provider "aws" { region = "eu-west-1" } resource "aws_key_pair" "kmipsrv_key" { key_name = "kmipsrv_key" public_key = file("./kmipsrv_key.pub") } resource "aws_instance" "kmip_srv" { ami = "ami-0333305f9719618c7" instance_type = "t2.micro" key_name = aws_key_pair.kmipsrv_key.key_name tags = { Name = "KMIP server", script-author = "nitin.
Posts
Ubuntu Apt Which Services Should Be Restarted
When installing packages (sudo apt install -y …) in Ubuntu Linux, you may get a prompt to select “Which services should be restarted?”. This can keep scripts from executing successfully, instead causing them to hang perpetually, waiting for user input.
This can be fixed by going to the needrestart config file anf editing the $nrconf{restart} line to:
$nrconf{restart} = 'l'; The default value of i is to interactively ask the user, a is to auto-restart, and l is to simply list the services.
Posts
Ruby Smtp Server
Building an SMTP server in Ruby is extremely simple because most of the building blocks are already available. EventMachine has an SMTP server at https://www.rubydoc.info/gems/eventmachine/EventMachine/Protocols/SmtpServer that you can customize by copying the code snippet from their documentation page and modifying the receive_message function to store the email somewhere - perhaps in a database.
Posts
Grep in Ruby
Here’s an attempt at building a grep-alternative in Ruby…
#!/usr/bin/env ruby # # Author: Katkam Nitin Reddy # Email: <redknitin@gmail.com> # Date: 2023-02-08 # Description: Replacement for grep with support for lookahead/lookbehind # require 'optparse' require 'colorize' def process(options) input = File.read options[:inputfile] unless options[:inputfile]=='-' input = ARGF.read if options[:inputfile]=='-' # input = STDIN.gets if options[:inputfile]=='-' # This returns only 1 line, so we use ARGF.read instead input.each_line do |iter_line| if not (mat = iter_line.
Posts
Add Google Analytics to Hugo
If you look at the HTML source code for this page in your web browser, you will see code for Google Analytics at the very end of the body tags. This was not copy-pasted; Hugo includes a built-in template to add Google Analytics to the site’s web pages.
I use the “ananke” theme, so I copied the file ./themes/ananke/layouts/partials/site-footer.html to ./layouts/partials (create the partials subdirectory if it doesn’t exist). Then, open the new site-footer.
Posts
Dont Fix What Isnt Broken
When a software vendor releases a new version of their product, one’s first instinct is to adopt the new version. Ideally, the upgrade should go through a change management process. Somebody has to look at the release notes for the new version, prepare a list of the changes, the benefits, how it will (negatively) impact the existing deployment, the risks involved, and how the risks will be mitigated.
If the only change between two versions is a trivial label change, then one shouldn’t be fixing what isn’t broken.
Posts
Mongo Ruby Field-Level Encryption
MongoDB makes Client-Side Field-Level Encryption easy to implement. Take a look at this code snippet:
require 'mongo' require 'securerandom' local_master_key = SecureRandom.random_bytes(96) kms_providers = { local: { key: local_master_key } } key_vault_client = Mongo::Client.new(['localhost:27017']) client_encryption = Mongo::ClientEncryption.new( key_vault_client, key_vault_namespace: 'admin.datakeys', kms_providers: kms_providers ) data_key_id = client_encryption.create_data_key('local') schema_map = { 'encryption_db.encryption_coll': { properties: { encrypted_field: { encrypt: { keyId: [data_key_id], bsonType: "string", algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" } } }, bsonType: "object" } } client = Mongo::Client.