Log in
Sign up
Overview Questions Answers

looper003

    Stats

    • 177 reputation
    • 75 questions asked
    • 75 answers
    • 27 selected answers
    Overview Questions Answers
    • Answers 75
    • NewestVotes
    Redirect to a new page in getInitialProps using Next.js?

    You can use res.writeHead() to do this. This will allow you to set a new location on the response header.

    To do this, you can update your getInitialProps() function to this:

    static async getInitialProps({ query, req, res }) {
      const apiResult = await getImageByFilename(query.filename, req);
    
      if (boolean) {
        res.writeHead(302, {
          Location: "/different-page"
        });
    
        res.end();
      }
    
      return {
        data: apiResult.data,
      };
    }
    

    If the given boolean value is true, you'll be redirected to the /different-page page.

    The 302 code indicates that it's a redirect.

    Answered 7 months ago by looper003
    Stop Nodemon from restarting when a specific file is updated?

    Nodemon has an --ignore flag you can add to the nodemon command.

    Ignore a file:

    nodemon ignore lib/data.json
    

    You can also do a pattern to ignore changes in all json files:

    nodemon --ignore '*.json'
    
    Answered 7 months ago by looper003 · Selected answer
    Get the current version of Docker installed on my macOS machine?

    docker -v command works as well.

    Answered 9 months ago by looper003
    Only show an element if it's NOT true in Handlebars?

    https://handlebarsjs.com/guide/builtin-helpers.html#unless

    Answered 9 months ago by looper003
    What does /* istanbul ignore next */ do?

    istanbul is a JavaScript code coverage tool.

    Some things are hard to test, so /* istanbul ignore next */ tells istanbul to skip and not include the next thing in your source code when calculating code coverage for your project.

    Answered 9 months ago by looper003
    Git error: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.

    Generate a personal access token in your GitHub account

    Go to the **Developer settings` section of your GitHub.com account and generate a new token.

    Make sure you save the token somewhere on your machine. You can only access it the one time in your GitHub account.

    Configure GitHub to use the token on your local machine

    Windows:

    1. Open Control Panel => User Accounts => Credential Manager.
    2. Find git:https://github.com.
    3. Click Edit.
    4. Replace the password with the GitHub Personal Access Token you generated.

    MacOS:

    1. Open Spotlight Search and search for Keychain Access.
    2. In Keychain Access, search for github.com.
    3. Update the internet password entry for github.com.
    Answered 9 months ago by looper003
    Run a Cypress test in all browsers besides Chrome?

    You can use the Cypress.browser.name value. It will return the name of the browser Cypress is currently using.

    const isChrome = Cypress.browser.name === "chrome"
    
    Answered 9 months ago by looper003
    List all outdated NPM packages installed to my project?

    The npm-check-updates package may work for you.

    Install it globally on your machine:

    npm install -g npm-check-updates
    

    Then run the ncu command inside your application:

    ncu
    

    This will list all the new dependencies you can update in your project.

    And you can update them with this command;

    ncu -u
    
    Answered 9 months ago by looper003
    Get the total number of lines of code in a git repository?

    Output the total number of lines in your Git repository:

    git ls-files | xargs cat | wc -l
    

    If you remove the cat portion, you'll get a full list of each file with it's total in the output as well:

    git ls-files | xargs wc -l
    

    You can also only include files with specific extensions:

    git ls-files | grep "\.js$" | xargs wc -l
    
    Answered 10 months ago by looper003 · Selected answer
    Reverse a string using JavaScript?

    This will reverse your string:

    string.split("").reverse().join("");
    

    Code breakdown:

    • split(""): converts the string into an array containing each letter in the word. i.e. ["e", "x", "a", "m", "p", "l", "e"].
    • reverse(): reverses the order of the array.
    • `join(""): converts the array of letters back into a string format.
    Answered 11 months ago by looper003 · Selected answer
    Previous123...8Next
    • Terms
    • Privacy

    © 2023 Chunkks