TILs - Fueling Curiosity, One Insight at a Time

At Codemancers, we believe every day is an opportunity to grow. This section is where our team shares bite-sized discoveries, technical breakthroughs and fascinating nuggets of wisdom we've stumbled upon in our work.

Published
Author
user-image
Vaibhav Yadav
Senior System Analyst
Local storage does not work right off the bat when we render a web page within an App. App Dev will have to ensure that DOM storage is enable for it to work.
Published
Author
user-image
Syed
Mocking useSWR directly in test cases is a little complicated and even not recommended at some places.
So the ideal way to do it is using a library Mock Service Worker. Here are the steps that helped me solve this.
1. Create a mock server using setupServer from msw/node:

JavaScript

const server = setupServer(
  rest.get(`/api/channels/C04UPJ9243E/members`, (req, res, ctx) => {
    return res(
      ctx.json({
        members: [{ name: "Sibtain", image: "abcd.jsp", id: 123 }],
      })
    );
  })
);


2. Start the server and after we run the test, close the server.

JavaScript

beforeAll(() => server.listen());
afterAll(() => server.close());


3. To ensure clean and isolated tests, reset the request handlers.

JavaScript

afterEach(() => server.resetHandlers());


Now our API connections are taken care of and we can render components and run the test cases.

JavaScript

test('render stuff, () => {
}


Resources: https://mswjs.io/
Published
Author
user-image
Ashwani Kumar Jha
Senior System Analyst
While writing Cypress test we generally create a cypress.env.json file to store the environment variables.


Code

{
  "BASE_URL": "https://company.dev.com/",
  "USER_EMAIL": "[email protected]",
  "USER_PASSWORD": "Test@12345",
}


To retrieve the value of our environment variable, we use the Cypress.env method in the test file.


Code

const baseUrl = Cypress.env('BASE_URL');


That's all we need to do locally to use the env vars in our Cypress test.

Now for CI, we can save these environment variables as Github action secrets.

To make these environment variables accessible from Github action secrets to our test, we need to keep a few things in mind.

• Add a value of empty string to the env vars and expose the cypress.env.json file.

Code

{
       "BASE_URL": "",
       "USER_EMAIL": "",
       "USER_PASSWORD": "",
  }


• We need to add CYPRESS_ prefix to the env vars in the yml file.

Code

env:
       CYPRESS_BASE_URL: ${{ secrets.BASE_URL }}
       CYPRESS_USER_EMAIL: ${{ secrets.USER_EMAIL }}
       CYPRESS_USER_PASSWORD: ${{ secrets.USER_PASSWORD }}


Happy testing!
Published
Author
user-image
Codemancers
If Postgres logical replication is enabled via pglogical extension, below query can be used to check the size WAL Folder.
select sum(size) from pg_ls_waldir(); (Response to the query is in Bytes)

This is the folder where the WAL logs are stored, which is utilized for postgres data replication from master to slave. In case there is any lag or problems with replication the logs will get accumulating in the folder, spiking the disk storage and can cause downtime of the database it self.
Published
Author
user-image
Ashwani Kumar Jha
Senior System Analyst
In the first server-side rendering (SSR) page render, the router.query may not be populated immediately. To handle this scenario, we can add a check to ensure that the redirection happens only on the client-side, once the router.query values are available.


Code

import { useEffect } from 'react';
import { useRouter } from 'next/router';

export const ResetPasswordPage = () => {
  const { push, query, isReady } = useRouter();
  const { username, code } = query as ResetPasswordPageQuery;
   ...
  useEffect(() => {
    if (isReady && (!username || !code)) {
      push('/login');
    }
  }, [isReady, username, code, push]);
  ...
};


Here the isReady property from useRouter is used to determine if the router is ready and router.query is populated.
This way, the initial SSR render won't trigger the redirection, and the user will be redirected to the login page only on the client-side if the necessary parameters are missing from the URL.
Published
Author
user-image
Sujay
Open PR from CLI
• brew install hub
• git config --global hub.protocol https
• hub pull-request (Will create PR for the current branch)
Published
Author
user-image
Ayush
Term called fuzzy searching
fuzzy searching (more formally known as approximate string matching) is the technique of finding strings that are approximately equal to a given pattern (rather than exactly).
Published
Author
user-image
Rishav


I learned how to use promise.all to combine multiple api calls.
Learned how to made api endpoint by using app directory and page directory in Next Js.

Learned how to implement slack bolt app with next js using the bolt http runner npm package

Learned how to use node-cron to schedule message

Published
Author
user-image
Ashwani Kumar Jha
Senior System Analyst
The Active Record Pattern popularised by Ruby on Rails goes against the modularity provided by Nest.Js.

Nest.js encourages the use of the Repository pattern.

Data Mapper/Repository pattern:

• Separates data access logic from business logic
• Data Mapper: Maps data between domain objects and the database
• Repository: Provides methods for querying and manipulating domain objects
• Promotes separation of concerns, testability, and maintainability
Active Record:

• Combines data access and business logic within domain objects
• Domain objects encapsulate database interactions
• Simplifies development by allowing direct manipulation of objects
• Can make separation of concerns and independent testing more challenging
Published
Author
user-image
Sujay
Etag HTTP Header
- Etag (also known as entity tag) is a unique identifier for a resource
- This is used to cache the resources that are unchanged
- When a request is recieved by server, it generates response and attaches Etag
- In the subsequent request, application requests for the same resource with If-None-Match header with the value of Etag received in previous step
- Server compares the value of If-None-match header with Etag identifier value on server
- If the values match server responds with 304(Not modified) status code with the empty body
- Application can use the cached response
Published
Author
user-image
Sujay
Get all TODO comments in rails application using rails notes
Published
Author
user-image
Rishav


1. Learned how to use the slack api.
2. Learned how to send message on user command through the slack bot.
3. Learned how to setup and use incoming web hook for slack bot.
4. Learned How to post message in channel using the incoming web hook.
5. Learned how to do post req using the axios.
Published
Author
user-image
Rishav


1. Learned how to make slack bot.
2. Learned how to use slack bot.
3. Learned how to add slack bot to the workspace and channel .
4. Learned how to use brew
5. Learned how to use ngrok and redirect the local host port to the ngrok url.
Published
Author
user-image
Rishav
1. i learned how to do filtering and sorting with the api by passing params.
2. i learned how to write test cases for the components like filtering and sorting.
3. i learned how to mock api using the jest.
Published
Author
user-image
Rishav
1.Tomorrow, I learnt how to utilise a single component to prevent code repetition and use that component in every component to prevent code repetition,
2. To make the API scalable, we need to create various methods to call it if I had many end points.
Published
Author
user-image
Codemancers
You can use cloudflared to expose apps running on localhost using a dedicated domain, and HTTPS
• For hosting using a random URL just run cloudflared tunnel --url http://localhost:<PORT>
• For an owned domain, there are a bunch more steps.
◦ Prerequisites:
▪︎ You need a domain name that you own. Can buy one for an year for <200 Rs
▪︎ Create a Cloudflare account. You will be asked to login to dash.cloudflare.com
▪︎ Follow the instructions including the installation instructions in https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide/local
Published
Author
user-image
Ashwani Kumar Jha
Senior System Analyst
TypeScript Pick utility allows us to create a new type by picking a subset of properties from an existing type. Instead of duplicating field declarations we can use Pick utility to extract new types.


TypeScript

type AdminUser = {
  id: number;
  name: string;
  email: string;
  phone: string;
  password: string;
  age: number;
  isAdmin:  boolean;
  ...
}



TypeScript

type BasicUser = Pick<AdminUser, 'id' | 'name' | 'email'>;


Published
Author
user-image
Rishav
today i learned how to use storybook in next js with typescript and i also build some story of the components and today i learn how next js work and i also fetch api data in next js with the typescript and i also write the test cases in next js by using the react testing library and jest and i learned how to write testcases in react js with the help of typescript

Showing page 23 of 42

Your competitors are already using AI.
The question is how fast you want to unlock the value.

Don't know where to start?

AI is everywhere but it's unclear which investments will actually move your metrics and which are expensive experiments.

Your data isn't ready

Most AI projects fail at the data layer. Pipelines, quality, access all need work before LLMs can deliver value.

Internal teams are stretched

Your engineers are shipping product. They don't have capacity to also become AI specialists with production-grade experience.

Legacy systems block everything

Aging, undocumented codebases make AI integration slow, risky, and expensive. They need to move first.

Don't worry. We've got you covered.

Start with the audit.