mitmproxy2swagger

Came across an interesting library (or tool) – mitmproxy2swagger that reverse-engineers REST API just by running the web app and sniffing traffic in the background. Once you are done, the tool allows you to download a yaml file. Open up the file in Swagger and voilà! Beautifully formatted API endpoint. Can be useful to document API for your application.

Pretty fascinating.

Go 1.18 released with Generics support

Go 1.18 isn now generally available. This release supports generics which a lot of us have been waiting for. This is still the very first version to support generics and I believe this feature will gain more support and updates in the upcoming features.

From the Go blog:

In Go 1.18, we’re introducing new support for generic code using parameterized types. Supporting generics has been Go’s most often requested feature, and we’re proud to deliver the generic support that the majority of users need today. Subsequent releases will provide additional support for some of the more complicated generic use cases. We encourage you to get to know this new feature using our generics tutorial, and to explore the best ways to use generics to optimize and simplify your code today. The release notes have more details about using generics in Go 1.18.

Go Tutorial does an excellent job explaining how to use generics. I think they did a good job defining this functionally. The code is so much readable.

// SumIntsOrFloats sums the values of map m. It supports both int64 and float64
// as types for map values.
func SumIntsOrFloats[K comparable, V int64 | float64](m map[K]V) V {
    var s V
    for _, v := range m {
        s += v
    }
    return s
}

The [K comparable, V int64 | float64] tells me that you can either send either int or float values to this function.

It makes me wonder if there are product managers for programming languages or not? And, if yes, would love to talk to someone about their experience.

Learning golang – my journey

As a product manager by trade, I don’t need sit and learn programming languages as I’m not expected to site down and write code. But the engineering in me wants to keep building.

Looking at data is a big part of my day-to-day work. You might have a data analyst to help you with this, but the analysis of the data and understanding you get of your customer is not something you can delegate. Thus, most cases I take matter into my hands.

Now there is only so much SQL queries you can write and run daily. At some point in time you want to store these values and trend over time. Chances are you have system that will do the job for you, but when you don’t you take matters at hand.

Python was a go to choice, but I wanted to build a cli tool that would allow me to run cURL like commands to an API and capture some of the timing metrics as well. At times I would have 100’s of URL’s that I did like to check.

I also wanted to pull RUM data from our vendor tool for pages of my SaaS application and correlate that data that I pulled from the database.

I had Grafana and MySQL set up to view this data, but I needed something that would run my queries, cURL my API endpoints and pull data from 3rd party application into this MySQL database.

After talking to a few friends, I looked into golang as a means to do whatever automation I needed to do at my end. One of the biggest reason to consider golang was the concurrency – easy to understand and implement.

I have a full fledged system set up today that allows me to look into trends in my SaaS applications with multiple data sources contributing to these dashboards. Here are a few links I used to get myself started into golang.

First, head to golang.org and install the framework from the download page.

Go by Examplehttps://gobyexample.com
Literally from basics. I read this just to get a hang on their syntax and how to structure code.

The Go+ language for engineering, STEM education, and data sciencehttps://github.com/goplus/gop
Yet another library that cuts down the learning by focusing on the most basics of things. Really good library.

How to write go codehttps://golang.org/doc/code
When you first start writing go code and everything is in a single file; it woks like magic. When you start separating your layers, is when you get into trouble. This tutorial form Google was one of the best to get me started and understanding how to structure my code.

SOLID Go Design by Dave Cheney – https://dave.cheney.net/2016/08/20/solid-go-design
Once you get a hang of things, follow Dave Cheney’s blog. This will get you started in golang design patters and most important concurrency.

How to create a CLI in golang with cobrahttps://towardsdatascience.com/how-to-create-a-cli-in-golang-with-cobra-d729641c7177
I wanted to build a CLI tool and there is no better library then cobra and viper. I have no moved away from these libraries and build everything thats available in golang; but these libraries will get you started quickly and also help you understand how to build cli tolls and read settings from a config file.

Viper for config file settings – https://github.com/spf13/viper
Cobra for building a CLI tool – https://github.com/spf13/cobra

Lastly an example of golang CRUD using MySQL form scratchhttps://www.golangprograms.com/example-of-golang-crud-using-mysql-from-scratch.html
This will give you a basic understanding on pushing data into a database.

It is always good to refer to codebases as well to get an understanding of how to structure your code or to simply see deeding patters. Some code bases I looked into were Kubernetes and Elastic’s Beats.

Measuring your WiFi Quality

I have been using the router provided by my ISP provider (out of laziness) for the past few months. Those routers aren’t bad, but they do not work for every home environment. I live in a townhome and this router sits on the first floor. With all of us working from home; the connection has been spotty in some of our rooms. The download speed is great when you get a good connection but the stability is worst.

When it comes to networking, I know the basics and I know enough to understand the issue with my WiFi connection and that I need a stronger router. Before I got my Eero; I wanted to check my WiFi quality through out the house. Even if you have a stronger signal everywhere, one has to consider the noise. The amount of devices connected to WiFi one has these days is mind boggling. I counted 27 devices connected to my WiFi network including 9 WeMo switches, a ring doorbell and a Nest thermostat.

macOS has a utility to check your wifi connectivity – airport. Running this will show important metrics that you need to understand the quality of your WiFi Network:

$>/System/Library/PrivateFrameworks/Apple*.framework/Versions/Current/Resources/airport -I
     agrCtlRSSI: -40
     agrExtRSSI: 0
    agrCtlNoise: -93
    agrExtNoise: 0
          state: running
        op mode: station
     lastTxRate: 234
        maxRate: 867
lastAssocStatus: 0
    802.11 auth: open
      link auth: wpa2-psk
          BSSID: 1x:1x:1:1x:11:1
           SSID: XXXXXXXXXX
            MCS: 5
        channel: 48,80

Two numbers are most important here. agrCtlRSSI (Received Signal Strength Indicator) is the power of the received signal in the wireless network. It uses a logarithmic scale expressed in decibels (db) and typically ranges from 0 to -100. The close this number is to 0 the better quality of signal.

The second is Noise or agrCtlNoise; is the impact of unwanted interfering signal sources, such as distortion and radio frequency interference. This is also measured in decibels (db) from 0 to -120. The lower the value i.e closer to -120 means little to no noise in the wireless network.

Once you have these two values, you can now measure the Signal to Noise Margin (SNR Margin) with the simple formula agrCtlRSSI - agrCtlNoise.

Higher value means better WiFi Signals.

To truly monitor the quality of this, I wanted something that could track the wifi quality continuously. Not much could truly give me WiFi Quality so I had two choices. Write a simple shell script that could continuously run, capture the two metrics and provide me with the SNR Margin. Which would mean I had keep the terminal open and let that run.

Since I have been tinkering with golang, this was a good way to learn something new. I found a golang library getlantern/systray that allows you to run a golang app in the system tray. I then used mholt/macapp that allows me to build a macOS application. Now I have a continuous running application that update the WiFi signal every 15 seconds. You can download the code or the WiFiQuality.app on my GitHub.