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
Mohammad hussain
System Analyst
The JavaScript console isn’t just console.log. It provides specialized methods for different scenarios:
console.error() → logs errors in red.
console.warn() → highlights warnings.
console.table() → formats arrays or objects as tables.
console.group() / console.groupEnd() → groups related logs for better organization.
💡 Using these methods makes debugging clearer and more structured than relying only on console.log.
#Javascript
Published
Author
user-image
Syed Sibtain
System Analyst
How to deploy to fly.

1. Initial Setup

Code

# Initialize the app

fly launch

# This creates:
# - fly.toml (basic configuration)
# - .dockerignore
# - Dockerfile


2. App Creation

Code

# Create app in specific organization

fly apps create ui-delta-c9s --org c9s-staging


3. Configuration Setup

Code

# Set required secrets
# Example

fly secrets set RAILS_MASTER_KEY=$(cat config/master.key) --app ui-delta-c9s
fly secrets set SECRET_KEY_BASE=$(openssl rand -hex 64) --app ui-delta-c9s
fly secrets set RAILS_ENV=production --app ui-delta-c9s


4. Database Setup

Code

# Option 1: Create new database
fly postgres create --name ui-delta-db --region sin

# Option 2: Attach to shared cluster
fly postgres attach postgres-fire-9606 -a ui-delta-c9s


5. Customize fly.toml as required for the project

6. Deploy

Code

fly deploy --app ui-delta-c9s


#fly #deploy
Published
Author
user-image
Syed Sibtain
System Analyst
The Problem:
https://Fly.io|Fly.io databases use internal networks (.flycast domains) that aren't publicly accessible, so we can't connect directly from external tools like DBeaver.

Solution:
Use https://Fly.io|Fly.io's proxy to create a secure tunnel:

Code

fly proxy 5433:5432 --app


How It Works:
• Local port 5433 → Remote database port 5432
• Creates a secure tunnel through https://Fly.io|Fly.io's network
• Keep the proxy running while using external tools
• Allows external tools like DBeaver to connect via localhost:5433
#database #fly
Published
Author
user-image
Syed Sibtain
System Analyst
The Problem: When comparing images for UI testing, we needed to implement a fuzz factor to ignore small colour differences (like anti-aliasing, compression artifacts, or minor rendering variations). This is crucial for UI screenshots where a 1-2 pixel difference shouldn't count as a "failure."

Command Line approach

Code

# This works but is fragile
magick compare -metric AE -fuzz 10% image1.png image2.png NULL: 2>&1

# Problems:
# - Shell command parsing issues
# - Error handling is difficult
# - Output parsing is brittle
# - Cross-platform compatibility issues
# - Hard to debug when things go wrong


The Mini Magick Solution

Code

# Step 1: Create difference image
difference_image = first_image.composite(second_image) do |c|
  c.compose "difference"
end

# Step 2: Apply fuzz factor using threshold
thresholded_diff = difference_image.dup
thresholded_diff.combine_options do |c|
  c.normalize
  c.threshold "10%"
# This acts as our fuzz factor!
end

# Step 3: Get statistics
mean_value = thresholded_diff.identify do |c|
  c.format "%[fx:mean]"
end

# Step 4: Convert to percentage
percentage = mean_value.to_f * 100


Key Insight: Fuzz Factor = Threshold
- In ImageMagick: fuzz 10% tells it to ignore differences below 10%
- In MiniMagick: threshold10% does the same thing by setting pixels below 10% to black

#ruby #image
Published
Author
user-image
Syed Sibtain
System Analyst
* The Problem:* I had an existing Elixir app with a users table that used password_digest field, but Devise expects encrypted_password by default.

Devise's Default Password Field:

Code

# Devise expects this by default:
class User < ApplicationRecord
  devise :database_authenticatable
  # Uses 'encrypted_password' column automatically
end


Our Existing Schema:

Code

# Uses password_digest
create_table :users do |t|
  t.string :password_digest, null: false  # ← Different field name!
  # ... other fields
end


The Override Solution:

Code

# Devise calls: user.encrypted_password
# Our override returns: user.password_digest

class User < ApplicationRecord
  devise :database_authenticatable, :registerable, :validatable

  # Tell Devise to use our existing password_digest field
  def self.encrypted_password_column
    :password_digest
  end

  # Override the getter method
  def encrypted_password
    read_attribute(:password_digest)
  end

  # Override the setter method  
  def encrypted_password=(value)
    self.password_digest = value
  end
end


So we can simply override Devise's password field by:
1. Telling Devise which column to use (encrypted_password_column)
2. Creating getter/setter bridges (encrypted_password methods)
3. Using read_attribute to avoid method conflicts
#devise #auth
Published
Author
user-image
Syed Sibtain
System Analyst
What does model: resource actually do in form_with?

model: resource is the bridge between our form and the data object. It makes forms smart - they remember values, show errors, and handle the complex Rails form lifecycle automatically.

Example:

Code

<%= form_with model: resource, as: resource_name, url: session_path(resource_name), local: true, class: "space-y-6" do |f| %>


model: resource tells Rails:
• Which object to bind the form to
• Where to get field values from
• Where to send validation errors to
• What HTTP method to use (POST for new, PATCH for existing)
In Devise Context:
resource is a Devise helper that returns:
• New User object (for signup) - User.new
• New User object (for signin) - User.new (usually empty, not pre-populated)
Without model: resource:
• Form fields are always empty
• No automatic error handling
• Manual parameter naming required
• No automatic HTTP method detection
#CU6U0R822 #devise
Published
Author
user-image
Satya
To understand network sockets locally, you can try this simple demo with two terminal tabs:
1. In the first tab run ns -l 1234 : This starts a small server process that listens for TCP connections on your computer’s address (localhost / 127.0.0.1) at port 1234.
2. In the second tab run ns localhost 1234 : This connects a client to the server on 127.0.0.1:1234 , creating a TCP connection between the two processes.
Now type text in one terminal and press Enter you’ll see the same text appear in the other terminal and vice-versa. 🚀

#sockets
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

Showing 2 to 5 of 82 results

Ready to Build Something Amazing?

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