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. 1. i learned how to do filtering and sorting with the api by passing params.
    2. i learned how to write test cases for the components like filtering and sorting.
    3. i learned how to mock api using the jest.
  2. 1.Tomorrow, I learnt how to utilise a single component to prevent code repetition and use that component in every component to prevent code repetition,
    2. To make the API scalable, we need to create various methods to call it if I had many end points.
  3. Codemancers
    You can use cloudflared to expose apps running on localhost using a dedicated domain, and HTTPS
    • For hosting using a random URL just run cloudflared tunnel --url http://localhost:<PORT>
    • For an owned domain, there are a bunch more steps.
    ◦ Prerequisites:
    ▪︎ You need a domain name that you own. Can buy one for an year for <200 Rs
    ▪︎ Create a Cloudflare account. You will be asked to login to dash.cloudflare.com
    ▪︎ Follow the instructions including the installation instructions in https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide/local
  4. Ashwani Kumar JhaSenior System Analyst
    TypeScript Pick utility allows us to create a new type by picking a subset of properties from an existing type. Instead of duplicating field declarations we can use Pick utility to extract new types.


    TypeScript

    type AdminUser = {
      id: number;
      name: string;
      email: string;
      phone: string;
      password: string;
      age: number;
      isAdmin:  boolean;
      ...
    }



    TypeScript

    type BasicUser = Pick<AdminUser, 'id' | 'name' | 'email'>;


  5. today i learned how to use storybook in next js with typescript and i also build some story of the components and today i learn how next js work and i also fetch api data in next js with the typescript and i also write the test cases in next js by using the react testing library and jest and i learned how to write testcases in react js with the help of typescript
  6. A modal is a popup that when appears on the screen we cannot interact with any other element on the webpage apart from the modal.
    On other hand a dialog is a popup that when appears on the screen we can still interact with other element on the webpage


    JavaScript

    <dialog>
    <!-- Dialog Content -->
    </dialog>


    By default a dialog element will be hidden unless you add the open attribute to your dialog


    JavaScript

    <dialog open>
      <span>You can see me</span>
    </dialog>


    It is not advised to use the open attribute directly, though, as that only allows you to open a non-modal dialog. Instead, you should use the show() and showModal() JavaScript methods.


    JavaScript

    const dialog = document.querySelector("dialog")
    dialog.show() // Opens a non-modal dialog
    dialog.showModal() // Opens a modal


    To close a dialog element you just need to use the close() method.
    Alternatively, if your dialog element is a modal you can use the Esc key to close it.


    JavaScript

    const dialog = document.querySelector("dialog")
    dialog.close() // Closes the dialog

  7. today i learned
    1. All the basics of typescript and i also implement for fetching the api
    2. i learned tailwind css and also implement styles in the component using tailwind css.
    so basically today i learn how typescript work, how to implement typescript, how it is useful in development and how to use and implement tailwind css.
  8. When we have conflicts between main and production, we cannot open PR directly. We do the following:
    1. git fetch and then go to production -> git checkout production
    2. Create a new branch from production -> git checkout -b <branchname>
    3. Pull latest changes from main -> git pull origin main or git merge main
    4. Resolve conflicts
    5. Push the changes and create a pull request with base branch as production
    6. And chill 🙂
  9. Today I learned

    1 Fetch data from Api.
    2 How to use axios for Fetching Api.
    3 How to use storybook.
    4 Learned jest for writing test cases.

  10. Code

    git reset --hard origin/master
    says: throw away all my staged and unstaged changes, forget everything on my current local branch and make it exactly the same as origin/master.
    
    You probably wanted to ask this before you ran the command. The destructive nature is hinted at by using the same words as in "hard reset".


  11. So if we want to mock the useRouter hook in NextJs, we can use vi for it.
    The "vi" library's function vi.mock allows us to simulate the behaviour of the useRouter hook. The mock function returns an object that mimics the Router object's properties and methods.


    Code

    vi.mock("next/router", () => ({
        useRouter: () => ({
          replace: vi.fn(),
        }),
      }));


    replace: a mock function that simulates the behavior of the replace method of the Router object.
    If we do not use it, the test might fail and we get the following error.
    Error: NextRouter was not mounted.
  12. userEvent is considered to be a more reliable and secure way of triggering events in the browser because user events are events that are triggered by a user's interaction with the webpage and reflect the actual user behavior on the page.
    However, fireEvent is a means of programmatically activating an event (dispatching DOM events) in the browser, which can be less dependable.

    Reference: https://testing-library.com/docs/user-event/intro/#difference-to-fireevent
  13. userEvent is more reliable and easy to use rather than fireEvent.
    userEvent provides wide range of browser events options and it is like interacting with events same as we interact in browser
  14. Vaibhav YadavSenior System Analyst
    Postgres query uses || as string concatenation instead of +
  15. Ashwani Kumar JhaSenior System Analyst
    We can type JSON into https://app.quicktype.io/ and it generates TypeScript type.

    Can be helpful in defining types for api response (usually while integrating third party apis where large amounts of data is returned).
  16. Codemancers
    you can whitelist IPs and ranges in nginx. When we have separate virtual hosts these are saved in /etc/nginx/sites-enabled. The rules look like allow xx.xx.xx.xx/range(32); and deny all;. Further we can make sure nginx passes some headers to the app using the rules proxy_set_header Host $http_host;.
  17. Vaibhav YadavSenior System Analyst
    We can use the following where clause to filter users based on their age using a Postgres query
    (CURRENT_DATE - INTERVAL '18 years')::date < TO_DATE(T3.DATE_OF_BIRTH, 'YYYY-MM-DD')
  18. Ashwani Kumar JhaSenior System Analyst
    As a Next.js app can be executed on both the server and the client side. When the app is rendered on the server, there is no access to the browser-specific features like localStorage, as it is a feature of the client-side browser environment.

    So let's say, if we try to use localStorage in a Next.js app, we may encounter issues when the app is being server-side rendered.

    To avoid this problem, we can check if localStorage is available before using it in our Next.js app.


    Code

    if(typeoflocalStorage!== 'undefined') { 
    // Use localStorage here
    }


    This way, our app will only use localStorage when it is available, and avoid errors when it is not.
  19. Bring the suspended server to foreground using fg command. Say the server is running and we want to install a package

    Code

    1. Ctrl+Z
    2. yarn add jsonwebtoken
    3. fg


    And the server resumes

Showing page 24 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