Skip to content

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.

  1. 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

  2. ChatGPT 4.0 has a limit of 40 messages per 3 hours while using some of the custom GPTs like DALL·E
  3. 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.
  4. 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
  5. 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
  6. Sachin KabadiSystem 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.
  7. Sachin KabadiSystem 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.
  8. Soniya Rayabagi
    * Ansible Provisioning :*
    Example : Setting up Ansible Provisioning for Nginx Installation on Vagrant:

    Step 1: Install Ansible on Your Machine :

    Python

    sudo apt-get update
    sudo apt-get install software-properties-common
    sudo apt-add-repository ppa:ansible/ansible
    sudo apt-get update
    sudo apt-get install ansible


    Step 2: Go to your server's /etc/hosts file and add the hostname and the IP address of the host:

    Python

    hostname    : vagrant 
    hostname -I : 10.0.2.15.


    Step 3: As Ansible works on the agentless architecture of using SSH to communicate with its hosts, set-up the ssh keys:

    Python

    ssh-keygen 
    cat ~/.ssh/id_rsa.pub
    ssh-copy-id root@10.0.2.15.


    Step 4: Add the Vagrant SSH Key inside authorized_keys:

    Python

    sudo nano ~/.ssh/authorized_keys


    Step 5: Configure Ansible Hosts , Edit the /etc/ansible/hosts file and add the hostname:

    Python

    sudo nano /etc/ansible/hosts
    vagrant


    Step 6: Verify Connectivity:

    Python

    ansible -m ping all
    
    output ---> 
    vagrant | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        },
        "changed": false,
        "ping": "pong"


    Step 7: Write Ansible Playbook for Nginx Installation:

    Python

    vi nginx-playbook.yml


    Step 8: Run the Ansible Playbook:

    Python

    ansible-playbook nginx-playbook.yml


    output :

    Python

    PLAY [Install and configure Nginx] *************************************************************************************************************************************************************************
    
    TASK [Gathering Facts] *************************************************************************************************************************************************************************************
    ok: [vagrant]
    
    TASK [Update apt package cache] ****************************************************************************************************************************************************************************
    changed: [vagrant]
    
    TASK [Install Nginx] ***************************************************************************************************************************************************************************************
    ok: [vagrant]
    
    TASK [Start Nginx service] *********************************************************************************************************************************************************************************
    ok: [vagrant]
    
    PLAY RECAP *************************************************************************************************************************************************************************************************
    vagrant                    : ok=4    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

  9. 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>
    }

  10. Mahesh BhosleDevOps 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""
  11. 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
  12. 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'))
  13. Ashwani Kumar JhaSenior 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.
  14. 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.
  15. 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.
  16. Mahesh BhosleDevOps 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
  17. Mahesh BhosleDevOps 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
  18. Ashwani Kumar JhaSenior 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.
  19. In order to check DNS settings and the resolved IPs, visit about:networking#dns in Firefox
  20. 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.

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.

Book a free discovery call