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
Ashwani Kumar Jha
Senior System Analyst
Filtering API logs with path params in OpenSearch

When querying logs in OpenSearch Dashboards, paths with dynamic segments (like IDs) often don’t match with the usual search bar syntax because the field is mapped as text instead of keyword.

Problem:
• Queries like

Code

json.req.url: "/api/bankAccounts/*/debit"


return no results.
.keyword may not exist (json.req.url.keyword) if the field wasn’t mapped that way at ingestion.
Solution:
Use Query DSL with a wildcard or regexp query.

Wildcard query (matches any value in the middle):

Code

{
  "query": {
    "wildcard": {
      "json.req.url": {
        "value": "/api/bankAccounts*/debit"
      }
    }
  }
}


Regex query (restricts the middle part to numbers):

Code

{
  "query": {
    "regexp": {
      "json.req.url": "/api/bankAccounts/[0-9]+/debit"
    }
  }
}


#opensearch #logs
Published
Author
user-image
Mohammad hussain
System Analyst
You can mark methods as deprecated in Rails using ActiveSupport::Deprecation. This warns developers that a method will be removed in future versions.


Code

class User < ApplicationRecord
  def full_name
    "#{first_name} #{last_name}"
  end

  # Mark full_name as deprecated
  deprecate :full_name, deprecator: ActiveSupport::Deprecation.new("2.0", "MyApp")
end



Code

DEPRECATION WARNING: full_name is deprecated and will be removed from MyApp 2.0


💡 Might be especially useful in larger codebases, where many developers might be using the same method and you want to safely signal that it will be removed without breaking things immediately.
#Rails
Published
Author
user-image
Nived Hari
System Analyst
In Prisma, there’s a big difference between directly setting a foreign key and using connect when creating related records.

Code

// ❌ Directly setting the foreign key
users: {
  create: {
    userId: testUser.id,
  },
}

// ✅ Using relation API
users: {
  create: {
    user: {
      connect: { id: testUser.id },
    },
  },
}


Direct assignment just writes the raw foreign key value — Prisma doesn’t check if the user actually exists.
connect uses Prisma’s relation API, validates that the record exists, and safely links them.

#prisma
Published
Author
user-image
Ashwani Kumar Jha
Senior System Analyst
Nx has a built-in command to remove libraries

Nx provides the @nx/workspace:remove generator that can remove a library from our workspace.

The command:

Code

npx nx g @nx/workspace:remove


What it does automatically:
• Deletes the library folder and all its files
• Removes the project from nx.json and workspace configuration
• Checks for dependencies and warns if other projects still use it
We can use --forceRemove flag if we want to remove a library even when other projects depend on it (though this can break the build).
#nx #monorepo
Published
Author
user-image
Nived Hari
System Analyst
WITH (NOLOCK) is often used to speed up queries by avoiding shared locks, which means the query won’t block other reads or writes. This can improve performance on busy systems, but it comes at the cost of data accuracy.

When using NOLOCK, SQL Server may:
• Read uncommitted (dirty) data that could later be rolled back.
• Return missing or duplicate rows due to page splits and concurrent writes.
• Show inconsistent values within the same row if columns are updated mid-read.
In short: NOLOCK trades reliability for speed. It’s fine for dashboards, reports, or monitoring where approximate numbers are acceptable, but it should be avoided for financial or critical business logic where accuracy is essential.

#sql
Published
Author
user-image
Sudeep Hipparge
Prisma --create-only

npx prisma migrate dev --create-only --name <migration_name>

Creates a migration file with the SQL changes but does not apply them to the database.

Why this is useful:

Safe inspection – lets you review the generated SQL before running it, especially helpful for destructive operations like drops or PK changes.

Manual adjustments – you can tweak the SQL (e.g., add a USING clause for type casting or backfill data before dropping a column).

Separation of responsibilities – you can generate migrations while DBAs/ops review and apply them in controlled environments.

Key takeaway:

👉 --create-only is like a dry run for migration generation – you get the recipe, but the dish isn't cooked yet 🍳.

#postgres
Published
Author
user-image
Mohammad hussain
System Analyst
Rails has a built-in way to reduce repetition in associations—with_options.
When multiple has_many relationships share the same option (like dependent: :destroy), repeating it clutters your model:


Code

class Account < ApplicationRecord
  has_many :customers, dependent: :destroy
  has_many :products,  dependent: :destroy
  has_many :invoices,  dependent: :destroy
  has_many :expenses,  dependent: :destroy
end


Using with_options, you can group them under one block:


Code

class Account < ApplicationRecord
  with_options dependent: :destroy do
    has_many :customers
    has_many :products
    has_many :invoices
    has_many :expenses
  end
end


This makes the intent clearer—all these associations share the same rule.
It's easier to read, less error-prone, and keeps your model DRY
#Rails
Published
Author
user-image
Ashwani Kumar Jha
Senior System Analyst
Next.js Typed Routes

Next.js now provides TypeScript support for route parameters and navigation, helping catch routing errors at compile time rather than runtime.

Next.js automatically generates route types based on our file structure in the app directory.

For example, if we have:

Code

app/
  users/
    [id]/
      page.tsx
  posts/
    [slug]/
      page.tsx


The generated types will understand routes like /users/123 and /posts/my-post-slug.


Code

import { useRouter } from 'next/navigation'
import Link from 'next/link'

// TypeScript knows about our routes
const router = useRouter()
router.push('/users/123') // ✅ Valid
router.push('/invalid-route') // ❌ TypeScript error

// Link component is also typed
<Link href="/posts/my-slug">My Post</Link> // ✅ Valid
<Link href="/wrong-path">Invalid</Link> // ❌ TypeScript error


#nextjs #typescript
Published
Author
user-image
Adithya Hebbar
System Analyst
How LLM's temperature affects AI output:

LLM models use a parameter called temperature to control randomness in generated responses.
temperature: 0 → deterministic output (same input = same output)
temperature: 1 → default setting, balanced creativity
temperature > 1 → more random, creative, but less reliable

Tip: Use lower temperatures when you need reliable, consistent responses, and higher temperatures for creative or exploratory tasks.
#llm
Published
Author
user-image
Mohammad hussain
System Analyst
Traits in FactoryBot allow you to define reusable pieces of attributes that can be mixed into factories to create variations of objects without duplicating code.


Code

FactoryBot.define do
  factory :user do
    name { "John Doe" }

    trait :admin do
      role { "admin" }
    end
  end
end

create(:user, :admin)


Here, :admin is a trait that overrides or adds attributes (role: "admin").
You can pass traits to create, build, or attributes_for to easily generate variations.
#CU6U0R822 #RSpec

Showing 3 to 5 of 83 results

Ready to Build Something Amazing?

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