teleren/devto huggingface dataset:
Next.js Codebase Analysis <> create-next-app <> index.ts explained - Part 1.18
Tags: opensource, nextjs, javascript, react
Published: 2024-02-12 21:12:54

Finally, I am past the prompts you see when you enter npx create-next-app. In this article, I will talk about the a code chunk from createApp function.

> Looking to practice and elevate your frontend skills? checkout https://tthroo.com for SaaS project based tutorials.

```
try {
    await createApp({
      appPath: resolvedProjectPath,
      packageManager,
      example: example && example !== 'default' ? example : undefined,
      examplePath: program.examplePath,
      typescript: program.typescript,
      tailwind: program.tailwind,
      eslint: program.eslint,
      appRouter: program.app,
      srcDir: program.srcDir,
      importAlias: program.importAlias,
    })
  }
```

My first thought is that program variable has been updated with the responses you provide and is further used in createApp function as an argument. 

I like the fact that it is a JSON object as an argument, a good thumb rule from clean code book is that your function can at most have 3 arguments, if you need more than 3 arguments, you might want to break down your function further or use an object like in this case.

## createApp function:

createApp is an async function export from [create-app.ts](https://github.com/vercel/next.js/blob/canary/packages/create-next-app/create-app.ts)

```
export async function createApp({
  appPath,
  packageManager,
  example,
  examplePath,
  typescript,
  tailwind,
  eslint,
  appRouter,
  srcDir,
  importAlias,
}: { 
  // this can be defined as type in the same file at the top 
  // But that's fine assuming this is only the place it is used.
  appPath: string
  packageManager: PackageManager
  example?: string
  examplePath?: string
  typescript: boolean
  tailwind: boolean
  eslint: boolean
  appRouter: boolean
  srcDir: boolean
  importAlias: string
}): Promise<void> {
  let repoInfo: RepoInfo | undefined
  // there is mode derived from typescript flag
  const mode: TemplateMode = typescript ? 'ts' : 'js'
  // nested ternary? nice.
  // so there is two kinds of templates,
  // one with router and the other without
  const template: TemplateType = appRouter
    ? tailwind
      ? 'app-tw'
      : 'app'
    : tailwind
    ? 'default-tw'
    : 'default'
```

## Conclusion:

I see that the argument type is defined next to argument without any explicit declaration of type somewhere at the top of the file, I would be okay with this assuming this type is not required else where in the codebase, otherwise I would write a type for this argument at the top of file and export it for reusability purposes.

Nested ternary, I don’t use that style much, but I can use it if the need be. I completely forgot we could do such a nested ternary, quite the reminder.

Looking to practice and elevate your frontend skills? checkout https://tthroo.com for SaaS project based tutorials.
Do you use AI tools for your work?
Tags: discuss
Published: 2024-02-12 21:01:35

Hey!
I'm Alex, and I'm really passionate about technology, especially when it comes to generative AI.

I've been working on something I'm pretty excited about – it's called the Bayesian Hub (https://bayesianhub.ai). Essentially, it's a collection of AI tools that I've put together to make life easier for myself and others like me who are into this stuff. But you know what? I think it can be even better.

So, I wanted to reach out and ask:
- Do you use AI in your work?
- If you do, what tools are your go-to's?
- How do you find these tools? Do you rely on recommendations, or maybe you stumble upon them in articles?

I'd love to hear your thoughts on the project, and any feedback you have would be awesome. Thanks in advance!
How to work with multiple PostgreSQL versions at the same time without losing your mind
Tags: postgres, docker, webdev
Published: 2024-02-12 20:55:45

# Using Docker to work with multiple PostgreSQL versions

How to work with multiple PostgreSQL versions at the same time without losing my mind?

That's what we are trying to answer here. With **Docker**.

## Docker PG Volumes

Data saved in a docker container are lost when that container is destroyed. We can save that data using docker volumes.

That's how we create a volume to use with a pg version 9.6:

```bash
docker volume create pgdata96
```

And that's how we create a volume for pg 13:

```bash
docker volume create pgdata13
```

## Docker PG Containers

I like to map each pg version with a similar port. I follow this simple pattern:

| version    | port |
|---------   |------|
| postgres96 | 54**96** |
| postgres12 | 54**12** |
| postgres13 | 54**13** |

This command will download, run and setup for us a container with a postgres 9.6:

```bash
docker run --name postgres96 -e POSTGRES_PASSWORD=123456 -d -p 5496:5432 -v pgdata96:/var/lib/postgresql/data postgres:9.6
```

And the same for a postgres 13:

```bash
docker run --name postgres13 -e POSTGRES_PASSWORD=123456 -d -p 5413:5432 -v pgdata13:/var/lib/postgresql/data postgres:13
```

Look how I mapped the ports.

## Create a DB

Let's create a database called **todolist** in the pg version 13:

```bash
docker exec -i postgres13 psql -U postgres -c "CREATE DATABASE todolist WITH OWNER=postgres;"
```

Or you can log in to the container e create it using *psql*:

```bash
docker exec -it postgres13 psql -U postgres
```

and then

```pgsql
$ CREATE DATABASE todolist;
```

## Start the container

When you restart your machine, or for some other reasons unknown, you can start the containers like this:

```bash
docker start postgres13
```

If you need to run other containers you can run like this:

```bash
docker start postgres13 redis memcached
```

That is no need to run the command `docker run` again.

## Restore a dump

That's how you can restore a local dump file into a database:

```bash
docker exec -i postgres13 psql -U postgres -d todolist -f dump.sql
```
HTML 2 Markdown Converter
Tags: html, markdown, converter, javascript
Published: 2024-02-12 18:32:30

In a significant development for digital content creators, developers, and technical writers, the release of a new HTML to Markdown converter is making waves across the digital landscape.

This cutting-edge tool, hosted at [htmlmarkdown.com](https://htmlmarkdown.com/), promises to transform the way we handle and convert digital content, making it more accessible, editable, and manageable than ever before.

The converter stands out for its commitment to CommonMark compliance, ensuring that conversions between HTML and Markdown adhere to standardized formatting rules. This feature is particularly important for those looking to maintain consistency and compatibility across different platforms and editors that support Markdown.

One of the most compelling aspects of this new tool is its array of customization options. Users can tailor their conversions to suit specific needs, with options for heading styles (Setext or ATX), horizontal rules (, -, or ), bullets, code block styles (indented or fenced), emphasis delimiters ( or ), strong delimiters ( or __), and even link styles (inlined or referenced). This level of customization is unprecedented and allows for a high degree of flexibility in content formatting.

Privacy and security are also at the forefront of the tool’s design. The converter operates entirely locally within your browser, using secure JavaScript. This means that none of the user's data is uploaded to the internet, ensuring complete privacy and security. It's a crucial feature for those handling sensitive or proprietary information, providing peace of mind that their content remains secure during the conversion process.

The HTML to Markdown converter is not just a tool; it's a solution designed to meet the diverse needs of a wide range of users. Whether it’s for content migration, documentation, educational material, blogging, or even technical writing, this tool offers a versatile and powerful resource. It simplifies the task of converting complex HTML structures into Markdown, saving time and ensuring consistency in formatting.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2qwmqq7fqwosnj0fpwgw.jpg)

For content creators and developers working with AI, such as ChatGPT, this converter plays a pivotal role. It allows for the easy transformation of complex HTML code into Markdown, facilitating clearer and more effective communication with AI for content generation. This feature is particularly beneficial when crafting texts with AI assistance, enabling a smoother workflow and higher-quality outputs.

In conclusion, the launch of the HTML to Markdown converter marks a significant milestone in content management and creation. Its focus on compliance, customization, privacy, and versatility makes it an indispensable tool for anyone involved in digital content creation. With its user-friendly interface and robust features, it is set to become a staple in the toolkits of content creators, developers, and technical writers across the globe.
Get Noticed: Tips for an Attention-Grabbing Marketing Plan Presentation
Tags: marketing, sales, presentation
Published: 2024-01-03 17:30:17

Are you tired of delivering lackluster [marketing plan presentations](https://simplified.com/ai-presentation-maker/sales-report)? This guide is your ticket to success. From grabbing attention with attention-grabbing opening techniques to incorporating engaging and interactive elements, you'll learn how to create a compelling narrative that keeps your audience hooked. With practical tips and strategies, you'll master the art of Q&A and leave a lasting impression
🪐Jupyter Notebook Cells: Shortcuts🎹
Tags: jupyter, datascience, data, python
Published: 2024-02-12 18:15:33

Every data geek and python programmer knows and uses Jupyter notebooks this day and age, as it is a very crucial tool and one of the most important skills every Data related role person needs in his carrer .

In this article i'll be sharing the most common and useful shortcuts that you need in your everyday coding life to be more productive, save time, or just to get rid of the mouse and impress people with your keyboard skills 🤷‍♀️.


## Cell type: 
There are three main types of cells on Jupyter : Code cells, Markdown cells, and Raw cells.
By default any new cell is a code cell, but it can be changed either with the dropdown on the toolbar or using shortcuts.

For a **code cell** to run python code:
 Press `y`

For a **Markdown cell** to display formatted text and media:
 Press `M`


## Cell mode:
There are two modes in jupyter notebook, Edit mode and Command mode.

For **Edit mode** to type code or text in the cell :
Press `return`

For the **command mode** to perform general actions on the cells in the notebook:
Press `ESC`

## Add/Delete Cells:
To **add** a cell above the selected cell : Press `a`
To **add** a cell bellow the selected cell: Press `b`
To **delete** the selected cell: Press `dd`


## Run Cells:
To **Run/Execute** the selected cells: 
Press `cltr`+`Enter` 

To **Run** the selected cell + **select** below : 
Press `Shift`+`Enter` 

To **Run** the selected cells + **add** cell below: 
Press `alt`+`Enter`

To **Run all** cells: 
Press `cltr`+`A` 
Press `cltr`+`Enter` 


## Modify Cells:
To Undo : Press `Z` 
To copy : Press `C`
To cut : Press `X`
To paste : Press `V`


There you go! try it out, Increase your efficiency and productivity when using Jupyter Notebook.

Happy coding!🏃‍♀️
Manipulando el DOM con Javascript
Tags: dom, javascript, desarrolloweb, manipulacion
Published: 2024-02-12 18:52:43

Javascript como lenguaje para la web es fundamental, porque genera la dinámica necesaria para que la usabilidad de la aplicación sea lo mejor posible.

Crear, actualizar o borrar elementos del HTML es una tarea común, cotidiana y fundamental que todo desarrollador web debe manejar.

En este contenido realizamos un landing page simple, todo construido con Javascript Vanilla a partir del clic en un botón.

{% embed https://youtu.be/5BEcb-Kkk-c %}
How to create a Popover using Tailwind CSS.
Published: 2024-02-12 18:48:15

`Popover` is a common UI element in web applications, providing a way to display additional information or options when interacting with a particular element. With `React` and `Tailwind CSS`, most of the time developers use an npm library for the Popover or Popover. You know, when we use an npm library, it increases the project build sizes.
In this article, I will create a reusable `Popover` component using `Tailwind CSS`. We will use click and hover triggers for the Popover.

The `Popover` component:

```
// @flow strict
"use client"
import { useEffect, useRef, useState } from "react";

function ReactPopover({
  children,
  content,
  trigger = "click"
}) {
  const [show, setShow] = useState(false);
  const wrapperRef = useRef(null);

  const handleMouseOver = () => {
    if (trigger === "hover") {
      setShow(true);
    };
  };

  const handleMouseLeft = () => {
    if (trigger === "hover") {
      setShow(false);
    };
  };

  useEffect(() => {
    function handleClickOutside(event) {
      if (wrapperRef.current && !wrapperRef.current.contains(event.target)) {
        setShow(false);
      }
    }

    if (show) {
      // Bind the event listener
      document.addEventListener("mousedown", handleClickOutside);
      return () => {
        // Unbind the event listener on clean up
        document.removeEventListener("mousedown", handleClickOutside);
      };
    }
  }, [show, wrapperRef]);

  return (
    <div
      ref={wrapperRef}
      onMouseEnter={handleMouseOver}
      onMouseLeave={handleMouseLeft}
      className="w-fit h-fit relative flex justify-center">
      <div
        onClick={() => setShow(!show)}
      >
        {children}
      </div>
      <div
        hidden={!show}
        className="min-w-fit w-[200px] h-fit absolute bottom-[100%] z-50 transition-all">
        <div className="rounded bg-white p-3 shadow-[10px_30px_150px_rgba(46,38,92,0.25)] mb-[10px]">
          {content}
        </div>
      </div>
    </div>
  );
};

export default ReactPopover;

```
In this component the trigger default value is click and you can pass hover as an attribute. When you click outside of the Popover, the Popover will be closed.

Use the Popover component:

```
import ReactPopover from "@/components/common/react-popover";

const Page = () => {
  return (
    <div className="w-screen h-screen flex justify-center items-center gap-4">
      <ReactPopover
        content={
          <p>This Content Will be render in Popover.</p>
        }
      >
        <button className="bg-indigo-500 px-4 py-1.5 border rounded text-white">
          Click me
        </button>
      </ReactPopover>
      <ReactPopover
        trigger="hover"
        content={
          <p>This Content Will be render in Popover.</p>
        }
      >
        <button className="bg-indigo-500 px-4 py-1.5 border rounded text-white">
          Hover me
        </button>
      </ReactPopover>
    </div>
  );
};

export default Page;
```
Developers - Consider Using Fake Phone Numbers for User Verification
Tags: javascript, beginners, programming, tutorial
Published: 2024-02-12 18:35:27


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0qk72c2saj2ithhl81s4.png)When we ask users for their personal phone numbers during app signups or verifications, it creates a privacy vulnerability - their confidential data now exists in yet another place, ripe for misuse or potential breaches. 

I know user phone verification can feel unavoidable at times. But I recently discovered a nifty tool that generates unlimited fake and disposable phone numbers developers can use instead, maintaining user security.

It's called the Fake Number Generator at phonesnumbersgenerator.com. Takes seconds to generate a phone number matching any region that works for SMS or calls. 

As someone passionate about ethical, privacy-focused development, this tool has been a game changer:

- Users avoid oversharing personal data
- Testing verification is easy  
- Added a layer of security for users
- Did I mention it's 100% free?

By using fake numbers in our projects, we prevent the dilution of user details across systems while still providing access and convenience. It's a simple switch that responsibly handles private information while letting us build freely.

Next time phone verification feels inevitable in your workflow, give this tool a look. Would love to spar around other ideas for maintaining security as well! But this one gets a strong thumbs up from me.
[Phone Number Generator](https://phonesnumbersgenerator.com/)
Roof Replacement Atlanta
Published: 2024-02-12 18:15:16

Consider [Roof Replacement Atlanta ](https://www.danleyroofers.com/roof-replacement-atlanta/ )for transformative solutions. Our expert team in Atlanta specializes in seamless replacements, ensuring your property receives top-tier roofing. Elevate aesthetics and functionality with our dedicated services for roof replacement Atlanta, combining quality craftsmanship and durable materials.
Update Gitlab On Prem Server Running in a Docker Container
Published: 2024-02-12 18:06:27

Problem: We had a Gitlab server with repos in it that needed to be updated which was running on prem inside a Docker container. Worse, the container is not versioned. If we restarted the Docker container for any reason, we would wind up with the latest version being run which is not the one which was run when the container was set up. This means losing all our work.

In this example, it's going to be assumed that one all ready has an instance of Gitlab server running in an official container using Docker and that one can start, stop, and connect to the running container.

Surprisingly, that while there is online guides on how to host Gitlab on prem in a Docker container, and there's an official Gitlab Docker container on Docker Hub, there were no instructions on how to update Gitlab inside a Docker container.

How to actually run Gitlab in a Docker container, is beyond the scope of this article.

NOTE: One caveat is that you can NOT make a backup on one version then restore it to another version. In this guide, we suggest backing up twice. 1st before one updates then after an update. That way if things go badly with the update, you still have your original repos in the original backup.

Solution.

1st Step is to backup the container in place so if things go badly, we can restore it:

1st we need to connect to the container:

```bash
docker exec -it $CONTAINER /bin/bash
```

Then backup:

```bash
mkdir -p /var/opt/gitlab/backups
/usr/bin/gitlab-backup create force=yes GZIP_RSYNCABLE=yes STRATEGY=copy CRON=1
cp /etc/gitlab/gitlab-secrets.json /var/opt/gitlab/backups
cp /etc/gitlab/gitlab.rb /var/opt/gitlab/backups
```

Update Gitlab:

In this example, we'll use 14.9.1, but you should pick the version that's right for you via an upgrade path. More information on this is here:

https://docs.gitlab.com/ee/update/index.html#upgrade-paths

```bash
apt update
apt install -y curl ca-certificates openssh-server apt-utils perl
curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | bash
apt update
apt install gitlab-ee=14.9.5-ee.0
```

Now backup again as per the steps above.

Finally, change the tag on the container. In this case, the tag should be 14.9.5-ee. then restart the Docker container.

Finally, restore the latest back which matches the new version:

```bash
BACKUPDIR=/home/git/data/backups
cd $BACKUPDIR
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
cp ${BACKUPDIR}/gitlab-secrets.json /etc/gitlab
cp ${BACKUPDIR}/gitlab.rb /etc/gitlab
GITLAB_ASSUME_YES=1 /usr/bin/gitlab-backup restore BACKUP=${BACKUPFILE}
/usr/bin/gitlab-ctl restart
```

You should be able to go to your Gitlab web page and find that latest version is running and that all your repos are restored.
Crack the Code: GitHub's Top JavaScript Repos Await You
Tags: javascript, webdev, programming, beginners
Published: 2024-02-12 18:02:44


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qlmc9rf7okgjb50ap9un.jpeg)Embark on a coding adventure! Dive into GitHub's hidden vault of **JavaScript** brilliance with me. 

These repositories are the keys to unlocking your potential. Ready to transform into a JavaScript maestro? 

**Let's go beyond the basics and embrace the extraordinary!**

If you want to become a JavaScript developer and hone your skills, then GitHub is like a gold mine for you.  

So, let me show the repositories that helped me and will also help you.

- [You Don’t Know JS](https://github.com/getify/You-Dont-Know-JS):   This is a series of books diving deep into the core mechanisms of JavaScript.

- [JavaScript Algorithms](https://github.com/trekhleb/javascript-algorithms):This repository contains JavaScript based examples of many popular algorithms and data structures.  

- [Clean Code JavaScript](https://github.com/ryanmcdermott/clean-code-javascript): It’s a guide to producing readable, reusable, and refactorable software in JavaScript.

That's all for now!  

If you enjoyed this post:  

→ Follow me @abneribeiro_  for more.    

→ Comment to add value or spark a conversation.  Thanks! 

→ **Unlock success with our** [FREE resources.](https://beacons.ai/abneribeiro)
Quick guide to secure/encrypt your properties in MuleSoft
Tags: security, encryption, mulesoft, mule4
Published: 2024-02-12 17:34:48

> **NOTE**
> _This post is to generate your encrypted values by manually using the JAR file. You can also use the [(unofficial) UI](https://secure-properties-api.us-e1.cloudhub.io/) or refer to [this article](https://help.mulesoft.com/s/article/How-to-implement-the-secure-properties-tool-inside-an-API-to-encrypt-or-decrypt-with-plain-text-password)._

Download the Secure Properties Tool Jar file from the [Mule docs](https://docs.mulesoft.com/mule-runtime/latest/secure-configuration-properties#secure_props_tool)

You can see in the docs how to encrypt your properties with different scenarios, but the following scripts are the ones I use the most.

## Encrypt one value at a time

I normally use the **Blowfish** algorithm and the **CBC** mode:

```shell
java -cp secure-properties-tool.jar com.mulesoft.tools.SecurePropertiesTool \
string \
encrypt \
Blowfish \
CBC \
your_secure_key \
"value_to_encrypt"
```

Then, just make sure to add `![]` in your properties file.

## Encrypt the whole file (per value)

If you don't want to do the previous script for all of the values, you can also run this instead:

```shell
java -cp secure-properties-tool.jar com.mulesoft.tools.SecurePropertiesTool \
file \
encrypt \
Blowfish \
CBC \
your_secure_key \
input_file.yaml \
output_file.yaml
```

This will automatically add the `![]` syntax to each value.
Video — Deep dive — Better Attention layers for Transformer models
Tags: opensource, datascience, transformers, artificialintelligen
Published: 2024-02-21 09:33:07

---
title: Video — Deep dive — Better Attention layers for Transformer models
published: true
date: 2024-02-12 17:26:46 UTC
tags: opensource,datascience,transformers,artificialintelligen
canonical_url: https://julsimon.medium.com/video-deep-dive-better-attention-layers-for-transformer-models-44aa5e8af5e3
---

### Video — Deep dive — Better Attention layers for Transformer models

The self-attention mechanism is at the core of transformer models. As amazing as it is, it requires a significant amount of computing and memory bandwidth, leading to scalability issues as models get more complex and context length increases.

In this video, we’ll quickly review the computation involved in the self-attention mechanism and its multi-head variant. Then, we’ll discuss newer attention implementations focused on compute and memory optimizations, namely Multi-Query Attention, Group-Query Attention, Sliding Window Attention, Flash Attention v1 and v2, and Paged Attention.

{% youtube 2TT384U4vQg %}