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
Sudeep Hipparge
How to Revoke (Undo) a Git Rebase

If you’ve run a git rebase and need to undo it due to issues, here’s a simple way to revert back:

1.Check your reflog to find the commit before rebase started:

Code

git reflog


Look for the commit hash just before the rebase (usually marked with rebase started).

2.Reset your branch back to that commit:

Code

git reset --hard <commit-hash>


This will reset your branch to the exact state before the rebase.

Important:
• Use git reset --hard with caution, as it will discard any uncommitted changes.
#Git
Published
Author
user-image
Sudeep Hipparge
React Query

It simplifies data fetching, caching, syncing, and updating — without manually managing loading or error states.
Here’s a small snippet I worked on today:


Code

import { useQuery } from '@tanstack/react-query';
import axios from 'axios';

const fetchOrganisations = async () => {
  const { data } = await axios.get('/api/organisations');
  return data;
};

const Users = () => {
  const { data, isLoading, error } = useQuery(['organisations'], fetchOrganisations);

  if (isLoading) return <p>Loading...</p>;
  if (error) return <p>Error fetching organisations</p>;

  return (
    <ul>
      {data.map(organisation => (
        <li key={organisation.id}>{organisation.name}</li>
      ))}
    </ul>
  );
};


💡 What I love:
• Built-in caching
• Automatic background refetching
• Easy-to-use API with powerful features
#CCT1JMA0Z #FrontendDevelopment
Published
Author
user-image
Sudeep Hipparge
Typescript as const turns everything into readonly.


Code

const user = {
  role: 'admin',
} as const;

user.role = 'editor'; // ❌ Error: Cannot assign to 'role' because it is a read-only property.


💡 as const is great for making values literal and immutable — useful in Redux, Enums, etc.

#Typescript #CCT1JMA0Z
Published
Author
user-image
Sudeep Hipparge
JavaScript: Object.groupBy()

Grouping data used to be messy — relying on Array.reduce() with verbose logic. But JavaScript's new Object.groupBy() method has made things incredibly elegant and easy!

With just one line, you can group array items based on any property.
It’s clean, readable, and production-friendly.

📌 Example:


Code

const products = [
  { name: "T-shirt", category: "clothes", price: 50 },
  { name: "Apple", category: "food", price: 5 },
  { name: "Shoes", category: "clothes", price: 35 },
  { name: "Orange", category: "food", price: 7.5 },
  { name: "Blueberry", category: "food", price: 4.5 }
];

const grouped = Object.groupBy(products, product => product.category);

console.log(grouped);


💡 Output:


Code

{
  clothes: [
    { name: "T-shirt", category: "clothes", price: 50 },
    { name: "Shoes", category: "clothes", price: 35 }
  ],
  food: [
    { name: "Apple", category: "food", price: 5 },
    { name: "Orange", category: "food", price: 7.5 },
    { name: "Blueberry", category: "food", price: 4.5 }
  ]
}


Cleaner. Less boilerplate. Much easier to read.

#CCT1JMA0Z #WebDevelopment
Published
Author
user-image
Vaibhav Yadav
Senior System Analyst
Using Makefile for tedious commands

A Makefile can be used to automate a commands, simplifying the execution process. Here’s a concise example:


Code

.PHONY: run-script

# Target to run a long command
run-script:
    @echo "Running a long command..."
    sleep 5  # Simulate a long-running command
    @echo "Command completed."


Running the Makefile
1. Create a Makefile: Save the above content as Makefile in your project directory.
2. Run Make: In your terminal, navigate to the project directory and execute:

Code

make run-script


Benefits
• Simplicity: Easily run a long command without remembering the syntax.
• Automation: Reduces manual effort and potential errors.
#cli #automation #makefile #commands
Published
Author
user-image
Sudeep Hipparge
💡 Why is [] == ![] true in JavaScript?

It all comes down to type coercion and how JavaScript evaluates expressions using the == (abstract equality) operator.

Here’s the breakdown:
![] evaluates to false because an empty array is truthy, and the ! operator negates it.
So the expression becomes: [] == false
When comparing an object (like[]) to a boolean with==, JavaScript converts both sides to numbers:
+[] → 0
+false → 0
So:

Code

[] == ![]  
=> [] == false  
=> +[] == +false  
=> 0 == 0  
=> true


Hence, [] == ![] evaluates to true.

#CCT1JMA0Z
Published
Author
user-image
Adithya Hebbar
System Analyst
How Dependency Injection Works in NestJS

NestJS uses Dependency Injection (DI) to manage the creation and lifecycle of classes like services, repositories, and providers. It leverages TypeScript's metadata to resolve dependencies automatically.

🚀 How It Works:

Declare Providers: Services and other classes are marked with @Injectable() to make them available for dependency injection. They are then registered as providers in a module.

Code

// user.service.ts
@Injectable()
export class UserService {
  getUsers() {
    return ['Alice', 'Bob'];
  }
}


Register Providers in a Module

Code

// user.module.ts
@Module({
  controllers: [UserController],
  providers: [UserService],
})
export class UserModule {}


Use the Service via Constructor Injection

Code

// user.controller.ts
@Controller('users')
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Get()
  findAll() {
    return this.userService.getUsers();
  }
}


NestJS reads the constructor types and injects the required instances for you. No manual instantiation needed!

Benefits:
• Decouples components
• Simplifies testing with mocks
• Promotes cleaner, modular code

#nestjs #dependencyinjection #typescript
Published
Author
user-image
Sudeep Hipparge
How to Revoke and Amend the Most Recent Git Commit Message.
To undo the most recent commit, unstage the changes, and update the commit message, follow these steps:

1. Revoke the latest commit and unstage the changes.
git reset HEAD~1

2. Stage the changes again.
git add .

3. Create a new commit with the updated message
git commit -m "New commit message"
(If you just want to change the previous commit message) - git commit --amend

4. Force-push the new commit to the remote repository
git push origin <branch-name> --force

> ⚠️ Use --force cautiously, especially on shared branches, as it rewrites history.
Published
Author
user-image
Nived Hari
System Analyst
pgvector provides native support for vector similarity search in PostgreSQL. It supports three types of distance metrics, each useful depending on the use case:
<=> Cosine distance – Measures the angle between two vectors (ignores magnitude). Great for comparing meaning in text (e.g., NLP). Smaller angle = more similar.
<#> L2 (Euclidean distance) – Measures the straight-line distance between two vectors. Takes both direction and size into account. Good when actual value differences matter (like in image or audio data).
<-> Inner product – Measures how much two vectors point in the same direction and how large they are. If vectors are normalized (length = 1), it works like cosine similarity. Great for ranking similarity when vectors are preprocessed.

#pgvector #PostgreSQL #VectorSearch #Embeddings
Published
Author
user-image
Puneeth kumar
System Analyst
ClickHouse DB

It is a column-oriented database management system designed for online analytical processing (OLAP). It's optimised for real-time analytics on large volumes of data and is known for being fast, highly scalable, and efficient for read-heavy workloads like metrics, logs, events, and other analytical data.

Key features are -
1. Columnar storage : Stores data by columns instead of rows, enabling efficient compression and faster reads.
2. Works super fast : Designed to process billions of rows per second per server.
3. SQL-compatible.
4. Materialized views : For real-time aggregation and data transformation.
#databases #click_house_db #analytics

Showing 5 to 7 of 82 results

Ready to Build Something Amazing?

Codemancers can bring your vision to life and help you achieve your goals