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
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.
Published
Author
user-image
Ashwani Kumar Jha
Senior System Analyst
\r
The groupBy method introduced in ES12 can be used to group elements based on the values returned by the specified callback function. This can be useful when we want to categorize items into distinct groups.\r
\r
For example, consider a list of transactions and we want to group them by the account type:\r
\r
\r

JavaScript

const transactions = [\r
 { account: 'savings', amount: 12, date: '2023-01-01' },\r
 { account: 'checking', amount: 200, date: '2023-01-01' },\r
 { account: 'savings', amount: 500, date: '2023-02-01' },\r
 { account: 'checking', amount: 300, date: '2023-02-01' },\r
];

\r
We can use groupBy to group these transactions by their account type:\r
\r

JavaScript

const groupedTransactions = Object.groupBy(transactions, ({ account }) => account);

\r
The output will be:\r
\r

JavaScript

{\r
 savings: [\r
 { account: 'savings', amount: 12, date: '2023-01-01' },\r
 { account: 'savings', amount: 500, date: '2023-02-01' }\r
 ],\r
 checking: [\r
 { account: 'checking', amount: 200, date: '2023-01-01' },\r
 { account: 'checking', amount: 300, date: '2023-02-01' }\r
 ]\r
}

Published
Author
user-image
Rishav
To see all commits on all branches that have not yet been pushed we can use this git cmd

Code

git log --branches --not --remotes

Published
Author
user-image
Sujay
In Flutter, widgets are the building blocks of your UI (similar to components in React), and there are mainly 3 type of widgets based on how they handle state: Stateless, Stateful, and Inherited widgets

Stateless Widgets:
- Stateless widgets are immutable i.e. their configuration cannot change once they are created. They represent parts of your UI that don't depend on any mutable state.
- Stateless widgets rebuild when their parent widget or the widget hierarchy above them rebuilds and when an Inherited widget it depends on changes

Stateful Widgets:
- Stateful widgets are mutable and holds some internal state that can change over time. They are used when a part of your UI depends on dynamic data or user interactions.
- Stateful widgets rebuild when their internal state changes. State updates are handled using setState() which also triggers a rebuild of the widget and its subtree. They can also rebuild when their parent widget or the widget hierarchy above them rebuilds.

Inherited Widgets:
- Inherited widgets are a special type of widget used to share data or state across an entire widget subtree without having to pass the data explicitly to every widget in the subtree (concept of Inherited widget is similar to Context API in React)
- Whenever the value inside Inherited widget changes, the widgets dependent on this widget get rebuilt.
Published
Author
user-image
Sujay
Difference between dynamic and Object type in dart\r
dynamic : dynamic is incredibly flexible. It tells Dart compiler to skip the type checking at compile time while type checking happens at run time. This is helpful when working with data of uncertain types.\r
\r

Code

\r
dynamic value = 42;\r
value = 'Sujay';\r
print(value.isEven); // Error thrown during runtime\r

\r
\r
Object : Object is the root class for all other classes. Its like a container like that can hold any value. Since Object is generic, you won't have access to specific methods or properties of value without type casting\r
\r

Code

\r
Object value = 42;\r
print(value.isEven); // throws compile time error\r

Published
Author
user-image
Vaibhav Yadav
Senior System Analyst
When running a javascript/typescript file during build time that requires environment variables importing dotenv config gets the job done. Alternate approach is to have values in package.json that goes against the idea of having the environment variables as secrets and hidden from the repository code.
Published
Author
user-image
Ashwani Kumar Jha
Senior System Analyst
In a web application, there can be scenarios where certain data needs to be fetched conditionally. For eg, in application with multiple user roles, there might be a specific role for which certain data is not needed. In such a case, we might want to avoid making unnecessary API calls to fetch that data. However, due to React's rules of hooks, we cannot directly conditionally call a hook which fetches data.

If you're using a library like react-query and if you do not want to create a wrapper component to fetch the data, react-query provides a good solution. react-query has an enabled option for its useQuery hook. We can conditionally enable or disable the query based on our needs.


JavaScript

const { data, isLoading } = useQuery(
 ['user', userId], 
 fetchUserData, 
 { enabled: isAuthenticated }
);


Here the useQuery is only executed if isAuthenticated is true. If isAuthenticated is false, the query is skipped.
Published
Author
user-image
Sujay
Use environmental variables in flutter

- Install flutter_dotenv package
- Create a .env file in the root of your project
- Add your variables to the .env file
- In order for the package to load .env file, add it to asset bundle in pubspec.yaml


Code

flutter:
    assets:
      - .env (path to the file where env is stored)


- Load the contents of env into flutter, by adding this is main.dart

Code

void main() async {
    await dotenv.load();
    runApp(const MyApp());
  }


- Access the env variable like this dotenv.env['APP_ENVIRONMENT']
Published
Author
user-image
Satya
below are the generator helper methods used to perform various actions in files and directories
• copy_file
• create_file
• insert_into_file
• inside
• gsub_file
Published
Author
user-image
Satya
generate generator by doing bin/rails generate generator initializer .
This will create the below files for you

Ruby

create  lib/generators/initializer
create  lib/generators/initializer/initializer_generator.rb
create  lib/generators/initializer/USAGE
create  lib/generators/initializer/templates
create  spec/generator/initializers_generator_spec.rb

Published
Author
user-image
Soniya Rayabagi
How we can Set up Puma as Systemd service in Ubuntu 18 for Rails application, The main purpose is ,
• to ensure it starts automatically on boot,
• can be managed easily with systemd's service management commands,
• It also allows for better process management, automatic restarts in case of failure, and logging capabilities,
• few set of commands used to create puma.service file and getting it started:
for file creation : /etc/systemd/system/puma.service
sudo systemctl daemon-reload
sudo systemctl enable puma
sudo service puma start
sudo service puma status
Published
Author
user-image
Nisanth
Retrieving Command History with FZF
Command: To view the command history, we can use the following command:
history | fzf
Note: Ensure that you have FZF installed before. It provides an efficient way to navigate through past commands.
Published
Author
user-image
Mahrukh Mir
Components:
Components are user interface elements that can be reused throughout the design file. They make design more consistent and allow for more rapid modifications.
Components can be made from a layer , groups or frames.

• Generally, there are two sorts of components:
1. Main Component: It is normally built first and is responsible for specifying several UI styles in the UI element.
2. Instance Component: This is the single occurrence main component.
When the main component is modified. It is automatically applied to the instance component. However, modifications to Instance components must be made manually.

The changes we make to the instance component are referred to as override. When we override an instance component and afterwards make modifications to the main component, the override does not change.
Published
Author
user-image
Ayush
Lambda
A lambda is a way to define a block & its parameters with some special syntax.
You can save this lambda into a variable for later use.
The syntax for defining a Ruby lambda looks like this:

Ruby

say_something = -> { puts "This is a lambda" }

Published
Author
user-image
Ayush
Scopes
Scopes are custom queries that you define inside your Rails models with the scope method.
Every scope takes two arguments:
1. A name, which you use to call this scope in your code.
2. A lambda, which implements the query.
It looks like this:


Ruby

class Fruit < ApplicationRecord  
   scope :with_juice, -> { where("juice > 0") }
end


Published
Author
user-image
Satya
RSpec double is a method provided by the RSpec library for creating test doubles, also known as mocks. Test doubles are objects that stand in for real objects in your system during tests.
Published
Author
user-image
Satya
if we are using tailwindcss-rails gem we don't need cssbundling-rails gem because tailwindcss-rails gem is a standalone version of Tailwind CSS that integrates with rails asset pipeline. It's a simpler and more direct alternative for rails applications because it doesn't require Node.js at all.

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