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
Soniya Rayabagi
models generating a model and migration , running a migration, CRUD records in the database different ways.
Connecting MVC the goal is to show information that's in the database.
Published
Author
user-image
Soniya Rayabagi
models generating a model and migration , running a migration, CRUD records in the database different ways.
Published
Author
user-image
Ayush
Critical Rendering Path

In each HTTP request that browser makes for an HTML page, the server returns the data into bytes, these bytes are then converted to Characters, Tokens, Nodes, and finally DOM (Document Object Model).

Once the DOM is generated, the parsing of the page starts, the HTML contains CSS code or links, JavaScript code or links, media elements such as images, etc, each of them is then parsed separately and plugged together to create a render tree, which is then converted to the layout and then is painted on the screen at the refresh rate of 60 frames per second.

This complete process is called a critical rendering path. Optimizing the critical rendering path helps to load the web page faster and without glitches or janks.
Published
Author
user-image
Soniya Rayabagi
views-and-controllers all the major stages a request goes through when it enters a Rails app. Like adding route to handle requests , generating controller , worked on first view template .
Published
Author
user-image
Soniya Rayabagi
rm -rf .git by running this command you are essentially deleting the entire Git repository, including all the commit history, configuration files, and any other Git-related data, from the current directory as it permanently removes the Git version control .
Published
Author
user-image
Satya
In fly if your machine has stopped , we can restart the machine by redeploying the app.
Published
Author
user-image
Syed
Dart has three types of variables, var, final and const
1. var is used for dynamic typing, allowing the type of the variable to be inferred at runtime.
2. final is used to declare a variable that can only be assigned once. It must be initialised when declared, and its value cannot change.
3. const is used to declare a compile-time constant. It must be initialised with a constant value, and its value cannot change.
Published
Author
user-image
Ashwani Kumar Jha
Senior System Analyst
In TypeScript, type annotations are removed when transpiling to JavaScript. This make us believe that type information is lost in JavaScript runtime. However, TypeScript offers a compiler option called emitDecoratorMetadata that, when enabled, emits metadata about the types used in our code. This metadata is accessible at runtime using reflect-metadata library.
Libraries like class-transformer and class-validator leverage this metadata to transform plain JavaScript objects into instances of specific classes and validate them against certain rules. Even though TypeScript types don't exist at runtime, the information about those types does, this provide us a more structured and safe way of working with data in JavaScript.
Published
Author
user-image
Codemancers
One liner for adding a delay in Typescript: await new Promise((r) => setTimeout(r, 2000));
Published
Author
user-image
Sujay
Difference between const and final in Dart
• Even though both const and final cannot be reassigned, there is a subtle difference between them.
const variables are used for compile-time constants whereas final variables are used for run-time constants.

Code

const current_time = new DateTime.now() // DON'T do it as the value is computed at run time
const name = 'Rahul' // DO it as the value is known at compile time


• When reading from database or reading from a file, the values won't be known at compile time. Use final in such cases
Published
Author
user-image
Soniya Rayabagi
figured out how we can use gitignore to add the .DS_STORE files into it by deleting the ds.store file first , and then using echo ".DS_Store" >> .gitignore to add the .ds_store file.
Published
Author
user-image
Soniya Rayabagi
Using git url to clone repo instead of https will not ask password on every git push/pull
Published
Author
user-image
Soniya Rayabagi
figured out how we can use gitignore to add the DS.STORE files into it by deleting the ds.store file first and using echo ".DS_Store" >> .gitignore to add the file.
Published
Author
user-image
Soniya Rayabagi
Using git url to clone repo instead of https will not ask password on every git push/pull
Published
Author
user-image
Rishav
I've have a radio input in a React Hook form and attempted to pass a boolean value, however when i submit the form, i receive the typeof value as a string. Knowing that RHF has valueAsNumber to convert it as number. I thought that setValueAs was a generic way to allow any conversion but I can't make it work.

I learn how to extract a boolean value from a RHF radio input.

The setValueAs approach, which I have previously tried, only functions with text input (such as type="text" or type="number"). Even if the value for a radio button is a string, it doesn't function.

In order to fix it, a Controller component can be used.

Solution:-


Code

<Controller
            defaultValue={false}
            control={control}
            name="booking_for_someone"
            render={({ field: { onChange, onBlur, value, ref } }) => (
              <label className="booking-for-someone">
                <span className="f-semibold">{t("I'm Booking For")}</span>
                <div>
                  <input
                    type="radio"
                    onBlur={onBlur}
                    onChange={() => onChange(false)}
                    checked={value === false}
                    inputRef={ref}
                    id="myself"
                  />
                  <label
                    htmlFor="myself"
                   >
                    {t("Myself")}
                  </label>
                </div>
                <div >
                  <input
                    type="radio"
                    className="w-16 h-16 rounded-full accent-blue"
                    onBlur={onBlur}
                    onChange={() => onChange(true)}
                    checked={value === true}
                    inputRef={ref}
                    id="someone-else"
                  />
                  <label
                    htmlFor="someone-else"
                   >
                    {t("Someone Else")}
                  </label>
                </div>
              </label>
            )}
          />


Thanks 🙂
Published
Author
user-image
Ashwani Kumar Jha
Senior System Analyst
Unsubscribe Feature when Email Service Provider is AWS SES

AWS SES List Management

• AWS SES provides built-in feature for managing email subscribers and their subscription preferences. This includes creating contact lists and topics, and enabling unsubscribe functionality directly in our emails.
• We need to create separate topics for different types of emails: To handle different types of emails like verification links, subscription updates, marketing etc. we can create separate topics for each type of email. This allows us to manage the subscription preferences for each type of email separately.
• We need to Include the {{amazonSESUnsubscribeUrl}} placeholder in our emails: AWS SES will automatically replace the {{amazonSESUnsubscribeUrl}} placeholder in the email with the actual unsubscribe URL.
• When a user clicks on this link, they will be taken to an unsubscribe landing page hosted by AWS, where they can choose to opt-out of receiving emails for a specific topic or all topics.
• AWS SES will handle the process of updating the user's subscription status when they opt-out of a topic. The next time when our system tries to send an email to that user for the opted-out topic, AWS SES will not allow the email to be sent.
• Ensure important emails are not affected: To ensure that users can still receive important emails like OTP verification and password reset emails, even after they opt-out of other emails, we can use separate contact lists and topics for these types of emails or we should not pass ListManagementOptions in these emails.

Code

{
  "Destination": {
    "ToAddresses": ["[email protected]"]
  },
  "Message": {
    "Body": {
      "Html": {
        "Charset": "UTF-8",
        "Data": "<body> // Email content... <p>If you no longer wish to receive our emails, please <a href=" {{amazonSESUnsubscribeUrl}}">unsubscribe</a></p></body>"
      }
    },
    "Subject": {
      "Charset": "UTF-8",
      "Data": "Email subject"
    }
  },
  "Source": "[email protected]",
  "ListManagementOptions": {
    "ContactListName": "contact_list_name",
    "TopicName": "Marketing"
  }
}


Published
Author
user-image
Ayush
in ruby if we have a variable called a = “HELLO” and then we assign it to a new variable
b = a
it does not create a deep copy of the string "Hello" stored in a. Instead, it creates a new variable b that references the same string object in memory as a. Both a and b will point to the same memory location, which means they will hold the same value and any changes made through one variable will be reflected in the other.

so if we do

Ruby

b.upcase!


it will return

Ruby

puts a  # Output: "HELLO"
puts b  # Output: "HELLO"


If we want to create a separate copy of the string, we can use the dup method or string manipulation methods to create a new string object with the same content.
Published
Author
user-image
Satya
copying mysql dump file to local database.
Note: please create your db first if you don't have one

Code

mysql> use your_local_db;
mysql> source your_db_backup_dump.sql;

Published
Author
user-image
Ashwani Kumar Jha
Senior System Analyst
When sending an email, a short snippet which is taken from the first few lines of our email content is shown right next to the email subject. This is called the preview text and can be a powerful tool for increasing the open rate.

However, the first few lines of our email might not always provide an accurate summary of what our email is about and this become important when working with HTML email template where first few lines might include elements like image alt text or navigational links.

To solve this problem, MJML have the mj-preview tag. This tag allows us to customize the preview text that appears in the recipient's inbox.


Code

<mjml>
  <mj-head>
    <mj-preview>Check out our latest deals!</mj-preview>
  </mj-head>
  <mj-body>
    <!-- email content -->
  </mj-body>
</mjml>


Published
Author
user-image
Nisanth
When we create a branch and make numerous commits to it, and later decide to start fresh by removing those previous commits, we can do this by following these steps in the terminal:
1. Delete the branch locally:
git branch -D <branch name>
2. Recreate the same branch from the ‘main’ branch:
git checkout main
git checkout -b <branch name>
3. Commit and push your changes:
git commit -m "Your commit message"
git push origin <branch name> -f
By using the -f flag in the ‘git push’ command, you force-push the changes to the branch on the remote repository. This erases the previous commits from the branch, giving you a fresh start with your new commit.”

Showing page 21 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.