Hi there 馃憢

Welcome to my dev journal. I mostly write about python and machine learning stuff.

Synchronising Clocks

Few days back, I encountered the following error on my website saral.club. botocore.exceptions.ClientError: An error occurred (SignatureDoesNotMatch) when calling the SendEmail operation: Signature not yet current: 20250505T152002Z is still later than 20250505T151830Z (20250505T151330Z + 5 min.) By the looks of it, the error message is descriptive enough to guide you that there is some kind of time mismatch in the signature. Before sending a request to aws, the botocore library signs the request using your access keys. The signature also includes a timestamp. And the error message is saying that the request I am sending is probably 5 minutes later (in future) then the current time (time on aws servers). Of course, the two clocks (one on my server and the other on aws鈥檚 server) cannot have the same exact time, so aws allows for some time skew (5 minutes). ...

May 6, 2025 路 3 min 路 485 words 路 Mohit Sharma

Time Saving Yaml Tricks

DRY: Don鈥檛 Repeat Yourself If you have a section that鈥檚 being repeated multiple times, you can create an anchor and then reference it. You use &name to create an anchor, and then *name to reference it. One example of it is defining environment variables for different services in docker-compose.yaml. env_vars: &env ENVIRONMENT: production LOGLEVEL: info AWS_REGION_NAME: us-east-1 services: api: environment: *env ... ... backend: ... ... environment: *env Reading environment variables While yaml doesn鈥檛 read environment variables, but if you pair it with parser, you can read the environment variables. The syntax depends on the parser you are using. The most common places, where I have a need for reading environment variables (or context variables) in yaml file is, cicd pipeline namely github action or circleci and docker-compose. ...

February 12, 2025 路 2 min 路 293 words 路 Mohit Sharma

How to set up a JavaScript/TypeScript project

Running a Javascript file Suppose you have a javascript file that you want to run from the command line. Install node or deno Run the file with node <filepath.js> or deno <filepath.js> or deno run <filepath.js> Running a TypeScript file Suppose you have a typescript file that you want to run from the command line. Install node. npm comes bundled with node. Install the typescript compiler with npm install -g typescript. Note that this will install the latest version of typescript compiler globally. Compile the file with tsc <filepath.ts> Run the file with node <comiled-filepath.js> Alternatively, you can install the ts-node package with npm install -g ts-node. This will install the latest version of ts-node globally. ts-node compiles the file on the file and executes it. ts-node <filepath.ts> Running a Javascript project The project directory must have a package.json file. This file is used by npm and can also be used to define additional information if you plan to publish the module to npm registry. Install the dependencies mentioned in the package.json file with npm install, more details about package.json The package.json file have a scripts section, this defines the commands that can be run with npm run <command>. In this section, you can define commands like start: node index.js; test: jest ., then if you run npm run test it will run the tests. Note, npm defines three commands which can be run without using the run command, npm start, npm test and npm stop. The start command defaults to using index.js file The package.json file has a main field, this is the file that is executed when you import the package in another file. By default, npm treats the imports as CommonJS modules, if you are using ES modules, you need to add the type key in your package.json with value module. Then all files must use import/export syntax. { name: "my-package", version: "1.0.0", main: "index.js", scripts: { start: "node index.js", test: "jest .", }, type: "module", dependencies: { jest: "^27.5.1", }, } Running a TypeScript project Using ts-node [!NOTE] You can avoid using ts-node and use tsx which supports TypeScript out of the box. No need to add additional support for esm modules ...

November 14, 2024 路 3 min 路 621 words 路 Mohit Sharma

All the ways to `git add`

I always get confused with, should I run git add ., or should I run git add --all, or should I run git add -A? Given all these commands, do a similar thing, confusion is bound to happen. Thankfully, it鈥檚 not just me. So I decided to take a deep dive into add command of git, to end this confusion once and for all. What does add even do? The add command adds your changes to staging area. Staging area is a buffer zone where you place your files before committing them. This buffer zone allows you to be selective with your commits, there are some files that you want to commit now and some files that you want to commit later. Staging area is also known as index. ...

October 24, 2024 路 3 min 路 560 words 路 Mohit Sharma

How to parse json in terminal using jq

A practical tutorial on jq So here鈥檚 the problem statement: Find the repository on github in which you have made most number of commits? And you need to do this on terminal (no python) Ofcourse, one can use python to find the answer, and it might be probably easy for you, if you have been using python for last many years. But let鈥檚 see if I can do this in terminal with jq and while doing so, let鈥檚 learn about it. ...

April 1, 2024 路 4 min 路 787 words 路 Mohit Sharma