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
Sachin Kabadi
System Analyst
While testing request spec in rails, configure host in your environment(development/test) :-
Add below line in your "config/environment/test" file.

Ruby

config.hosts << "www.example.com"

Published
Author
user-image
Soniya Rayabagi
CIDR Block(Classless Inter-Domain Routing)
Example : CIDR block: 192.168.1.0/28
This CIDR block represents all IP addresses between 192.168.1.0 and 192.168.1.15. The "/28" notation indicates that the first 28 bits of the IP address are fixed (192.168.1.0), and the remaining 4 bits (from 0 to 15) can vary, resulting in 16 possible IP addresses in the range. This range allows for 16 IP addresses, from 192.168.1.0 to 192.168.1.15.
Published
Author
user-image
Sujay
pg_dump commands:
Standard pg_dump without DROP table queries:
pg_dump -h your-hostname -p your-port -U your-username -d your-database-name -f output-file.sql`` pg_dump with DROP table queries (clean dump): pg_dump -h your-hostname -p your-port -U your-username -d your-database-name --clean -f output-file.sql pg_dump for schema only: pg_dump -h your-hostname -p your-port -U your-username -d your-database-name --schema-only -f output-file.sql pg_dump for data only: pg_dump -h your-hostname -p your-port -U your-username -d your-database-name --data-only -f output-file.sql pg_dump for data only (no schema, INSERT commands only): pg_dump -h your-hostname -p your-port -U your-username -d your-database-name --data-only --inserts -f output-file.sql`
Published
Author
user-image
Satya
While using sidekiq-scheduler if your schedule file is named as sidekiq.yml make sure to add the schedule config entry.
i.e :scheduler: -> :schedule .
For eg:

Code

:scheduler:
  :schedule:
    fetch_user_info_from_slack:
      cron: '0 6 * * * Asia/Kolkata'
      class: FetchSlackUserInfoJob
      queue: 'default'
      description: 'This job fetches user info from slack and updates the database'

Published
Author
user-image
Soniya Rayabagi
AWS - ami
If you want to create two instances in different regions within the same Terraform file, using the same AMI, you should first ensure that the AMI is available in both regions. If it's available in both regions (i.e.- "us-east-1" and "us-east-2") , you can proceed to use the same AMI for both instances. Otherwise, you should use two different AMIs.
For example :

Code

provider "aws" {
  alias  = "us-east-2"
  region = "us-east-2"
}

resource "aws_instance" "instance" {
  provider      = aws.us-east-2
  ami           = "ami-id-1"
  instance_type = "t2.micro"
}

provider "aws" {
  alias  = "us-east-1"
  region = "us-east-1"
}

resource "aws_instance" "instance1" {
  provider      = aws.us-east-1
  ami           = "ami-id-2"
  instance_type = "t2.micro"
}

Published
Author
user-image
Soniya Rayabagi
Git rebase is a command to reapply commits from one branch onto another, effectively rewriting the commit history.
1. Use git rebase main to start.
2. Resolve conflicts manually in files.
3. Add resolved files git add <file>.
4. Continue rebase git rebase --continue.
5. Finally, force-push changes git push <remote> <branch-name> —-force.
Published
Author
user-image
Neehar
Using the command “git push origin feature-branch -f” forces the remote repository to match the precise state of the local repository. However, it should be used with caution because it has the ability to overwrite remote modifications and cause data loss.
Published
Author
user-image
Neehar
Using git rebase command allows you to modify the history of your repository by changing a sequence of commits. It lets you to reorganise, modify, and merge commits. Git rebase is commonly used for resolving conflicts.
Published
Author
user-image
Soniya Rayabagi
The <<-EOF and EOF are Terraform's heredoc syntax, This syntax enables the creation of multiline strings in Terraform configuration files without the need to manually insert newline characters (\ ).
Published
Author
user-image
Nisanth
To check if an instance is running using Terraform, you can use the following command:
terraform show
This command displays the current state of your infrastructure as recorded by Terraform. It will show information about the resources that Terraform has created, including details about the EC2 instance, such as its ID, IP address, and other attributes.
Published
Author
user-image
Nisanth
If we want to create an instance in different regions within the same Terraform file, we need to use provider aliases. In Terraform, a single file typically contains one default provider configuration for ‘aws.’ To work with multiple regions, we use provider aliases.
Instead of having two separate provider blocks, we add aliases to them. For example:

Code

hcl
provider "aws" {
  alias  = "us-east-2"
  region = "us-east-2"
}

resource "aws_instance" "example" {
  provider       = aws.us-east-2
  ami            = "ami-id"
  instance_type  = "t2.micro"
}

provider "aws" {
  alias  = "us-east-1"
  region = "us-east-1"
}

resource "aws_instance" "example1" {
  provider       = aws.us-east-1
  ami            = "ami-id"
  instance_type  = "t2.micro"
}


This way, we can create instances in different regions using a single Terraform file, and each instance is associated with its respective region through the use of provider aliases
Published
Author
user-image
Soniya Rayabagi
how to troubleshoot the visibility of an AWS EC2 instance.
discovered that instances may not appear in the console if deployed in a different region , verified instance existence by providing the correct region in the AWS console.
example:

Code

provider "aws" {
 region = "us-east-2"
}

Published
Author
user-image
Satya
if you are using ngrok to expose your localhost , you can serve that in a static domain.
Every time you start ngrok it will use the same domain name

Code

ngrok http --domain=<your-domain>.https://ngrok-free.app|ngrok-free.app <port>

Published
Author
user-image
Satya
setup tailwind css without using node.js
The below setup is for macOS arm64

Step1

Code

curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-macos-arm64
chmod +x tailwindcss-macos-arm64
mv tailwindcss-macos-arm64 tailwindcss


Step2

Code

./tailwindcss init // this will create tailwind.config.js file


Step3
Create input.css file and import the required tailwind base, components & utilities

Step4

Code

./tailwindcss -i input.css -o output.css --watch // this will generate a output.css file, so make sure to link it in your root file


For production add the tailwind watcher command with --minify flag

Code

./tailwindcss -i input.css -o output.css --minify

Published
Author
user-image
Hilda
ChatGPT 4.0 has a limit of 40 messages per 3 hours while using some of the custom GPTs like DALL·E
Published
Author
user-image
Soniya Rayabagi
touch filename : Used to create an empty file .
git remote : The command is used to manage remote repositories.
git reset HEAD~1 : Removes the most recent commit from the current branch without modifying the working directory.
git pull origin branch_name : Fetches changes from the specified branch (branch_name) on the origin remote repository.
Published
Author
user-image
Sujay
Activerecord validations & callbacks are not called when upsert_all or insert_all are used. They will be directly converted to raw sql queries and executed
Published
Author
user-image
Sachin
To launch a Rails app on https://fly.io|fly.io, you can follow these steps:

1. Make sure you have the flyctl command-line tool installed.

2. Open a terminal and navigate to the root directory of your Rails app.

3. Launch a new https://fly.io|fly.io application by running the following command:
flyctl launch

This command will guide you through the process of setting up your https://fly.io|fly.io application. You'll be prompted to provide a name for your app and
select the organization you want to associate it with. Refer below.

Ruby

Creating app in ~/list
   Scanning source code
   Detected a Rails app
   ? Choose an app name (leave blank to generate one): list
   ? Select Organization: John Smith (personal)
   ? Choose a region for deployment: Ashburn, Virginia (US) (iad)
   Created app list in organization personal
   Admin URL: https://fly.io/apps/list
   Hostname: list.fly.dev
   Set secrets on list: RAILS_MASTER_KEY
   ? Would you like to set up a Postgresql database now? Yes
   For pricing information visit: https://fly.io/docs/about/pricing/#postgresql-clu
   ? Select configuration: Development - Single node, 1x shared CPU, 256MB RAM, 1GB disk
   Creating postgres cluster in organization personal

   . . .

   Postgres cluster list-db is now attached to namelist
   ? Would you like to set up an Upstash Redis database now? Yes
   ? Select an Upstash Redis plan Free: 100 MB Max Data Size

   Your Upstash Redis database namelist-redis is ready.

   . . .

         create  Dockerfile
         create  .dockerignore
         create  bin/docker-entrypoint
         create  config/dockerfile.yml
   Wrote config file fly.toml

   Your Rails app is prepared for deployment.

   Before proceeding, please review the posted Rails FAQ:
   https://fly.io/docs/rails/getting-started/dockerfiles/.



4. Once the launch is complete, you can deploy your Rails app to https://fly.io|fly.io by running the following command:
flyctl deploy

This command will build a Docker image of your Rails app and deploy it to https://fly.io|fly.io. It may take a few minutes to complete the deployment process.

5. After the deployment is finished, you'll see a message indicating that your app has been deployed successfully. It will also display the URL
where your app is accessible.

You can use following cmd to open app.
fly apps open

That's it! Your Rails app is now running on https://fly.io|fly.io. You can access it using the provided URL.

6. If you make any changes to your app, you can redeploy it by running following command again.
flyctl deploy
Published
Author
user-image
Sachin Kabadi
System Analyst
To install https://fly.io|fly.io on macOS using Homebrew and authenticate with flyctl, you can follow these steps:

1. Open a terminal on your macOS machine.

2. Install Homebrew if you haven't already. Run the following command in the terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

3. Once Homebrew is installed, you can use it to install flyctl. Run the following command in the terminal:
brew install superfly/tap/flyctl

4. After the installation is complete, you can authenticate with flyctl using the auth login command. Run the following command in the terminal:
flyctl auth login

This will open a browser window where you can log in with your https://fly.io|fly.io account credentials. Once you log in, the authentication token will be saved on your machine.

5. After successful authentication, you can start using flyctl commands to manage your https://fly.io|fly.io resources.

That's it! You have now installed https://fly.io|fly.io on your macOS machine using Homebrew and authenticated with flyctl.
Published
Author
user-image
Sachin Kabadi
System Analyst
Install Tailwind CSS with Ruby on Rails

1. Create your project

Code

rails new my-project
  cd my-project


2. Install Tailwind CSS

Code

rails tailwindcss:install


This will generate tailwind.config.js file in the /config directory.

3. Configure your template paths
Add the paths of all your template files to your /config/tailwind.config.js file.

Code

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    './public/*.html',
    './app/helpers/**/*.rb',
    './app/javascript/**/*.js',
    './app/views/**/*',
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}


4. Add the Tailwind directives to your CSS
Add the @tailwind directives for each of Tailwind's layers to your application.tailwind.css file located in the ./app/assets/stylesheets directory.


Code

@tailwind base;
  @tailwind components;
  @tailwind utilities;


5. Start your build process

Code

./bin/dev


6. Start using Tailwind in your project
Start using Tailwind's utility classes to style your content.

/config/tailwind.config.js file

Code

const defaultTheme = require('tailwindcss/defaultTheme')

  module.exports = {
    content: [
      './public/*.html',
      './app/helpers/**/*.rb',
      './app/javascript/**/*.js',
      './app/views/**/*.{erb,haml,html,slim}'
    ],
    theme: {
      extend: {
        fontFamily: {
          helvetica: ['Helvetica', 'Arial', 'sans-serif'],
        },
      },
    },
    plugins: [
      require('@tailwindcss/forms'),
      require('@tailwindcss/aspect-ratio'),
      require('@tailwindcss/typography'),
      require('@tailwindcss/container-queries'),
    ]
  }


index.html.erb

Code

<h1 class="container mx-auto mt-16 px-5 font-helvetica flex">
    Hello world!
</h1>


https://tailwindcss.com/docs/guides/ruby-on-rails|Reference official website for more information.

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