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
Syed
In Dart, JSArray<Object> and ConstantStringMap<String, Object> are part of the dart:js library, which is used for interoperability between JavaScript and Dart. They provide ways to interact with JavaScript objects and arrays within Dart code.

1. JSArray<Object>: This represents a JavaScript array. It extends Dart's List class and allows us to interact with JavaScript arrays as if they were Dart lists. This means we can use methods like add, remove, length, etc., on a JSArray<Object> instance. This makes it easier to work with JavaScript arrays in Dart code.
2. ConstantStringMap<String, Object>: This represents a constant JavaScript object. Unlike JSArray<Object>, which allows us to modify the JavaScript array, ConstantStringMap<String, Object> is read-only. This means we can access properties of the JavaScript object, but we can't modify them. This is useful when we want to ensure that the JavaScript object isn't accidentally modified by Dart code.
Example:


Code

void main(){
  const alphabets = [a,b,c];
  const person = {'id': 1, 'name': "Sibtain"};


  print(alphabets.runtimeType); // JSArray<Object>
  print(person.runtimeType); // ConstantStringMap<String, Object>
}

Published
Author
user-image
Mahesh Bhosle
DevOps Engineer
journalctl command can be used to check the system log on the server. you can use the --since and/or --until options to specify a time range.
eg:
• To filter log between 1st Jan 2024 to 10th Jan 2024: journalctl --since "2024-01-01" --until "2024-01-10"
• To filter log between 5am to 6am for 1st Jan 2024: journalctl --since "2024-01-01 5:00:00"" --until "2024-01-10 6:00:00""
Published
Author
user-image
Ayush
While creating contracts using Dry Gem it is important to keep in mind that if a validation rule is independent of a key from schema then schema will not process those keys before executing the validation rule.

For Example


Ruby

class RoomAvailabilityFormContract < Dry::Validation::Contract
  params do
    required(:date_from).filled(:string)
    required(:date_to).filled(:string)
  end

  rule(:date_to) do
    date_from = Date.parse(values[:date_from]) 
    date_to = Date.parse(values[:date_to])

    if date_to && date_from && date_to <= date_from
      key.failure('date_to must be ahead of date_from')
    end
  end
end


Our expectation from above contract will be if either date_to or date_from is missing in the schema the rule should not be executed and error should be caught while schema processes the keys which are date_to and date_from

But it will only work in case of date_from because the validation rule is dependent on the date_from key so if we have date_to as nil the rule will still be executed and might cause other errors like in our trying to parse nil value which does not fulfills the purpose of this gem.

To not get into such errors we should make sure that the validation rules are dependent upon the keys that are validated in schema

So the fix in above code will be to include date_to

Ruby

rule(:date_from, :date_to) do
    date_from = Date.parse(values[:date_from]) 
    date_to = Date.parse(values[:date_to])

    if date_to && date_from && date_to <= date_from
      key.failure('date_to must be ahead of date_from')
    end
  end


now before implementing the rule the schema will first validate both the keys and throw error if the values are not abiding to the schema
Published
Author
user-image
Satya
we can raise error using to_raise method inside our webmock in the spec file.
for example:

stub_request(:post, "https://slack.com/api/users.info")
.with(
body: { "user" => "some_random_id" },
headers: {
'Accept' => 'application/json; charset=utf-8',
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Content-Type' => 'application/x-www-form-urlencoded',
'User-Agent' => 'Slack Ruby Client/2.2.0'
}
)
.to_raise(Slack::Web::Api::Errors::UserNotFound.new('user_not_found'))
Published
Author
user-image
Ashwani Kumar Jha
Senior System Analyst
In a web app, certain non-code files like EJS templates are not automatically included in the production build, causing runtime errors as the application can't locate these files.

NestJS provides a built-in solution through the nest-cli.json configuration file. This file allows us to specify non-TypeScript assets to be included in the build process. By defining a pattern for the files and specifying the output directory, we can ensure these files are copied to the correct location during the build process.

Example nest-cli.json:


Code

{
 "collection": "@nestjs/schematics",
 "sourceRoot": "src",
 "compilerOptions": {
 "assets": [
   { "include": "emails/templates/*.ejs", "outDir": "dist/src" }
 ],
 "watchAssets": true
 }
}


In frameworks that do not provide a built-in solution for including non-TypeScript files in the build process, we can use external tools to handle this. For example, in Hapi.js, we can use cpx to copy these files during the build process.
Published
Author
user-image
Soniya Rayabagi
Setting Up SSH Authentication in Git for GitHub

1. Generate SSH Key Pair:
ssh-keygen -t rsa -b 4096 -C "<mailto:[email protected]|[email protected]>"
cat ~/.ssh/id_rsa.pub
2. Start the SSH Agent:
eval "$(ssh-agent -s)"
3. Add SSH Key to the SSH Agent:
ssh-add ~/.ssh/id_rsa
4. Add SSH Key to GitHub Account:
5. Test SSH Connection to GitHub:
ssh -T <mailto:[email protected]|[email protected]>
6. Output:
Hi soniyaraibagi! You've successfully authenticated, but GitHub does not provide shell access.
Published
Author
user-image
Nisanth
Encountered an issue with a Docker container image, preventing to destroy the vagrant environment using
vagrant destroy. The error message indicated:

Code

An action 'up' was attempted on the machine 'default',
but another process is already executing an action on the machine.
Vagrant locks each machine for access by only one process at a time.
Please wait until the other Vagrant process finishes modifying this
machine, then try again.


To resolve this issue, I used the following steps:
1. Opened the “Activity Monitor” to identify the PID (Process ID) associated with the Vagrant Docker container.
2. Executed the following command in the terminal to forcefully terminate the Vagrant process:
kill -9 PID

This action allowed me to overcome the locking issue and proceed with the destruction of the Vagrant environment successfully.
Published
Author
user-image
Mahesh Bhosle
DevOps Engineer
The web-socket APIs in AWS API Gateway service use different integrations to send the incoming requests to backend service. Two of them being HTTP and HTTP_PROXY. key difference lies in how the communication between API Gateway and the backend service is handled. HTTP integration involves translating WebSocket requests into HTTP requests, while HTTP proxy integration forwards WebSocket requests directly to the backend service without modification
Published
Author
user-image
Mahesh Bhosle
DevOps Engineer
While using tfenv tool for using multiple terraform version, we can use TFENV_ARCH variable to set the system architecture. This helps a lot when we need to use terraform amd64 binary on the arm64 device.
eg: to use amd64 binary for terraform 0.14.0, we can use the following command: TFENV_ARCH=amd64 tfenv install 0.14.0
Published
Author
user-image
Ashwani Kumar Jha
Senior System Analyst
In Next.js, we can organize our routes into groups without affecting the URL path. This can be done by wrapping a folder's name in parentheses, like (group).

Let's say we have an e-commerce application, we might have different sections like "electronics", and "clothing". Even though these sections have different URLs, we can group them in our code using route groups.

app/
├─ (electronics)/
│ ├─ electronic1/
│ │ ├─ page.tsx
│ ├─ electronic2/
│ │ ├─ page.tsx
├─ (clothings)/
│ ├─ clothing1/
│ │ ├─ page.tsx
│ ├─ clothing2/
│ │ ├─ page.tsx

In this structure, the URL paths will be /electronic1, /electronic2, /clothing1, /closthin2 etc, regardless of the category they belong to.

While route groups don't affect the URL structure, they still allow us to create different layouts for each group by adding a layout.js file inside their folders.
Published
Author
user-image
Iffyuva
In order to check DNS settings and the resolved IPs, visit about:networking#dns in Firefox
Published
Author
user-image
Satya
we can interact with browser events like click on a element in rails using Stimulus
Make sure you have @hotwired/stimulus installed .
Generate a stimulus controller by running the below commands.

JavaScript

./bin/rails generate stimulus controllerName
./bin/rails stimulus:manifest:update


Here , say my controllerName is tooltip , this will create a controller called tooltip_controller.js in app/javascripts/controllers directory & also link the file in app/javascripts/controllers/index.js .

For eg: my functionality is i want to toggle the tooltip visibility so the controller code will look like this

JavaScript

import { Controller } from "@hotwired/stimulus";

// Connects to data-controller="tooltip"
export default class extends Controller {
  connect() {}

  toggleToolTip(event) {
    event.preventDefault();
    this.element.lastElementChild.classList.toggle("hidden");
  }
}


And in your view file we need to wrap our parent div with an attribute called data-controller="tooltip" so the code will look like this

JavaScript

<div class="relative" data-controller="tooltip">
        <%= link_to "#", id: "avatar-link", data: { action: "click->tooltip#toggleToolTip" } do %>
          <%= image_tag(your_image, alt: "Avatar", class: "...classnames") %>
        <% end %>
        <div class="..classnames hidden" id="tooltip-container">
          ... your tooltip contents
        </div>
</div>


so here on click of the image it will toggle the tooltip container , if you take a close look on -> data: { action: "click->tooltip#toggleToolTip" }
this is simply saying perform the click action on tooltip controller using toggleToolTip method defined above.
Published
Author
user-image
Nisanth
AWS DeepLens is a deep learning-enabled video camera designed for developers to get hands-on experience with machine learning. What makes it intriguing is that it brings machine learning capabilities directly to the edge. With DeepLens, you can build and deploy deep learning models on the device itself, allowing it to process and analyze video streams in real-time
Published
Author
user-image
Satya
we need to add chat:write scope in bot token scopes, so that our bot can send messages in the channel when it is mentioned.\r
Published
Author
user-image
Satya
with modern Sign in with Slack we need to request the OpenID scopes—openid, email, and profile.
Published
Author
user-image
Satya
writing integration specs using RSpec and Capybara.
Published
Author
user-image
Satya
we need to add the user scopes email & profile when we are using the slack openid.connect.userInfo api method.
Published
Author
user-image
Satya
slack events api performs the events within 3 seconds if any exception happens then it retries again when the app is mentioned again.
Published
Author
user-image
Satya
we can use event subscription in our slack app to listen to events like mentioning the app and then the app will perform the action based on the event. For eg: like the way i did here.
For more info , please refer to -> https://api.slack.com/apis/connections/events-api
Published
Author
user-image
Sujay
In Dart, metadata provides additional information about the code. It begins with the character @ followed by either a reference to a compile-time constant or a call to a constant constructor.

There are four commonly used annotations in Dart:

@Deprecated: This is used to indicate that a feature/method/class is deprecated and should not be used because it will be removed in future versions.
@deprecated: This is similar to @Deprecated, with the difference being that a message can be passed with @Deprecated.
@override: This is used to indicate that a method is intended to override a method from a superclass.
@pragma: This is used to provide additional information to the Dart compiler.

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