teleren/devto huggingface dataset:
Pyenv to handle different versions of Python
Tags: python, tooling
Published: 2023-08-11 14:47:05

You may need to use different versions of Python on your computer, to make some programs work.

Today, I will explain how to use [Pyenv](https://github.com/pyenv/pyenv), a software that lets you manage all available python versions on your computer.

First, install the binary :
```bash
brew install pyenv
pyenv --help
```

Make sure you have all the [recommended packages](https://github.com/pyenv/pyenv/wiki#suggested-build-environment) in your environment.
If necessary, the most frequent cases of installation problems are listed [here](https://github.com/pyenv/pyenv/wiki/Common-build-problems).

Add Pyenv to your path : 
```bash
# pyenv init
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

# Restart your shell for the changes to take effect.
```

You can list the available versions of Python available for installation : 
```bash
pyenv install -l
pyenv install -l | less
```
Note that you will find versions packaged with Anaconda, Minicoda, Miniforge, Pypy, etc. The first versions of the list are not affected by any particular packages.

# Install Python 2.7 and select it
```bash
pyenv install 2.7.18
pyenv global 2.7.18
which python
python -V
pip -V
```

# Install Python 3 and select it
```bash
pyenv install 3.11.4
pyenv global 3.11.4
which python
python -V
pip -V
```

You can list the versions you have already installed and which version is currently selected :
```bash
pyenv versions
```

With Pyenv, you can easily **install and manage specific versions of Python** directly on your computer.

There are **similar tools** that I commonly use for **Terraform** ([tfenv](https://github.com/tfutils/tfenv)) and **NodeJS** ([nvm](https://github.com/nvm-sh/nvm)), this could be the subject of a future article of the same type. 

You can also see how to use the [virtual environments](https://dev.to/jdxlabs/use-the-virtual-environments-with-python-gld) in addition, to manage different versions of packages for your different projects.
Ruby Design Patterns | SINGLETON 👴🏼
Tags: webdev, ruby, rails, architecture
Published: 2023-08-11 13:30:54

## Overview
Singleton is a creational design pattern responsible for the fact that a class can only have one instance.

## Real World Example
As an example of today’s pattern, I chose the head of the Catholic Church, the Pope. However, I do not mean the Pope as a person, but as an institution. As we know from history the first Pope was St. Peter, and from that time to the present day, this office is held by various persons. However, it is impossible for more than one Pope to exist at the same time. This institution imposes in advance that this position may only be occupied by one person at a time.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nc6obg59ohcrgstyh4lj.png)

## Code Example
Let’s move the above example to the programming world and create a **Pope** class that can pray through the **pray!** method.

``` ruby
class Pope
  def pray!
    puts 'In nomine Patris, et Filii, et Spiritus Sancti...'
  end
end

pope = Pope.new
pope.pray! # => 'In nomine Patris, et Filii, et Spiritus Sancti...'

new_pope = Pope.new
new_pope.pray! # => 'In nomine Patris, et Filii, et Spiritus Sancti...'

pope == new_pope # => false
```

As we can see with the standard approach, we are able to create more than one instance of the Pope class. This is why we need to use the Singleton pattern to prevent creating more than one instance of a given class.

```ruby
class Pope
  @@instance = new
  
  def self.instance
    @@instance
  end

  def pray!
    puts 'In nomine Patris, et Filii, et Spiritus Sancti...'
  end
  
  private_class_method :new
end

pope = Pope.new # => NoMethodError: private method 'new' called for Pope:Class
Pope.instance.pray! # => "In nomine Patris..."
```

As you can see in the example above, we can’t directly create a class with the new method, which is now private, and we need to use the instance method instead. By comparing two instances to each other, we can make sure that they are the same instance.

```ruby
pope = Pope.instance
new_pope = Pope.instance
pope == new_pope # => true
```

Singleton pattern is so popular that there is a Singleton module in the standard Ruby library, thanks to which we will not have to focus on pattern configuration.

```ruby
class Pope
  include Singleton
  
  def pray!
    puts 'In nomine Patris, et Filii, et Spiritus Sancti...'
  end
end
```

This code works in exactly the same way as the code presented at the beginning of this article.
Quick OSX brew migration
Tags: brew, homebrew, osx, cli
Published: 2023-08-11 14:46:41

Looking for a quick way to migrate your `brew` installed packages? Well look no further. Homebrew (https://brew.sh/) has a quick command to export a `Brewfile` which can then be used to restore your packages on a new machine. 

Run the following to make the `Brewfile`

```sh
brew bundle dump
```

and

```sh
brew bundle install
```

to install on a new machine. Thanks to https://news.ycombinator.com/item?id=37084904 for the tip!
Docker essential commands
Tags: docker, linux, scor32k
Published: 2023-08-11 14:44:47

## Image Management

### Pull an Image from Docker Hub
```bash
docker pull image_name:tag
```
### List Downloaded Images
```bash
docker images
```
### Remove an Image
```sh
docker rmi image_name:tag
```
## Container Lifecycle

### Create a Container
```sh
docker run --name -d container_name image_name:tag
```
- **--name** -> give name to container
- **-d**  -> detach mode. Container will run in background.
### Container with Port Mapping
```bash
docker run -d -p 3000:5173 --name rc1 react-image
```
- **-p** -> Map port `3000` of host machine to `5173` port exposed by the docker container 
### Start a Container
```bash
docker start container_name
```
### Stop a Running Container
```bash
docker stop container_name
```
### Restart a Container
```bash
docker restart container_name
```
### Remove a Stopped Container
```sh
docker rm container_name
```
## Container Management
### List Running Containers

```bash
docker ps
```
### List All Containers (Including Stopped)

```bash
docker ps -a
```

### View Logs of a Container
```bash
docker logs container_name
```
### Access a Shell Inside a Container
```bash
docker exec -it container_name /bin/sh
```
- **it** -> runs the Docker image in interactive mode (keep Standard Input Stream)
- **/bin/bash** -> shell inside the container


## Networking

### List Docker Networks
```bash
docker network ls
```
### Create a Docker Network
```bash
docker network create new_name # new bridge netwok will be created
```

### Container with New Network
```bash
docker run -d --network=new_name --name secure image_name
```
## Volume Management
### Create a Volume
```bash
docker volume create volume_name
```
### List Volumes
```bash
`docker volume ls
```
### Attach a Volume to a Container
```bash
# docker run -v dirLocalDirectory:dirContainerDirectory -d -p 3000:5173 --name rc1 react-image
docker run -v $(pwd):/app/ -d -p 3000:5173 --name rc1 react-image
```

## Docker Compose (for Multi-Container Applications)
### Start Containers Defined in a Compose File

```bash
docker-compose up
```

### Stop and Remove Containers Defined in a Compose File
```bash
docker-compose down
```

### Rebuild Images each time
```bash
docker-compose up --build
```
## Cleanup
### Remove All Stopped Containers

```bash
docker container prune
```
### Remove All Unused Images
```bash
docker image prune
```

--- 
#### There are many more commands to go with, but these are some of the most basic and important ones.


If the article helps you, leave a like, follow, or anything 🙂.  
You can follow me on [LinkedIn](https://www.linkedin.com/in/abhishekpathak32/), [GitHub](https://github.com/scorcism), [Dev.to](https://dev.to/scorcism) and [hashnode](https://scorcism.hashnode.dev/).

**Bye**
Database Initialization and Creation for Testing in PostgreSQL 12.0 with Age (Part 3)
Published: 2023-08-11 14:42:44

Now that Postgres is installed on your system, it's time to create an age extension.

Use the following command to create the Age extension in PostgreSQL:

`CREATE EXTENSION Age;`

Load the extension:

`LOAD 'Age';`

Set the search path and variables:

`SET search_path = ag_catalog, "$user", public;`

This command will set the search path to include the Age catalog, current user's schema, and public schema. This will enable you to use Age functions and operators in your queries.

Now the PostgreSQL is configured, and ready to use

**Visit Apache Age's official website:** Apache-Age:-https://age.apache.org/

**Visit Apache Age's Github account:**
GitHub:-https://github.com/apache/age
Hero section with react and tailwindcss (medium hero copy)
Tags: react, javascript, tailwindcss, webdev
Published: 2023-08-11 14:42:12

Introduction:
In modern web development, creating visually appealing and functional user interfaces is essential to engage users. One crucial component of any website is the hero section — the first thing visitors see when they land on a page. In this tutorial, we’ll explore how to build a captivating hero section using React and Tailwind CSS. We’ll break down the code step by step to understand how to create a visually striking hero section that grabs users’ attention.

Prerequisites:
Basic understanding of React and JSX syntax
Familiarity with Tailwind CSS classes
Setting Up the Project:
Before we dive into creating the hero section, ensure you have a React project set up. You can use Create React App or any other preferred method.

Creating the Hero Component:
In this tutorial, we’ll create a separate component for the hero section to keep our code organized. Let’s get started.

Hero Component: Create a functional component named Hero that will represent the hero section of your webpage.

```
const Hero = () => {
  return (
    <div className="flex justify-between items-center bg-[#ffc017] py-10 lg:py-0 border-y border-black xl:border-hidden xl:rounded-xl">
      {/* Hero content */}
      <div className="px-10 space-y-5 lg:py-6">
        <h1 className="text-6xl md:text-7xl max-w-xl font-serif w-11/12 sm:w-9/12">
          <span className="underline decoration-black decoration-4">
            Medium
          </span>{" "}
          is a place to write, read and connect.
        </h1>
        <h2 className="w-9/12 font-normal">
          It's easy and free to post your thinking on any topic and connect with
          millions of readers.
        </h2>
        <button className="border border-black bg-white px-4 py-2 rounded-full font-medium active:scale-90 transition duration-100">
          Start Writing
        </button>
      </div>
      {/* Hero image */}
      <img
        className="hidden sm:inline-flex h-40 lg:h-80 xl:h-full"
        src="https://shubh73-medium.vercel.app/M.png"
        alt=""
      />
    </div>
  );
};
```
export default Hero;
Main App Component: In your main App.js file, import and use the Hero component.

```
import React from "react";
import Hero from "./Hero"; 
export default function App() {
  return (
    <div className="max-w-7xl mx-auto">
      <Hero />
    </div>
  );
}
```
Conclusion:
In this tutorial, we’ve successfully built a captivating hero section using React and Tailwind CSS. By breaking down the code step by step, we’ve learned how to structure the hero component and apply responsive design techniques to create a visually appealing layout. You can further customize the styles and content to match the branding and requirements of your project. This hero section will undoubtedly leave a lasting impression on your website’s visitors.
3 Book for Python Beginners
Tags: python, programming, beginners, books
Published: 2023-08-11 14:36:51

These three are my most favorite book, as a beginner for python these three book helped me to grasp the concepts and it was explained in a easy way. 

So, these are those three books!

**Python Crash course : Hands-On Projects for Rapid Progress**

_“Python Crash Course” is a best book for beginners because it offers a hands-on approach, combining theory with practical exercises, making it easy to learn Python. The book covers essential Python concepts and programming fundamentals, enabling beginners to quickly build real-world projects. Its clear explanations and engaging examples make it accessible and enjoyable for newcomers to programming. The book’s well-structured content and step-by-step learning path make it a go-to resource for those starting their Python journey._

---

**Python Cookbook : Unlocking the Power of Python**

“Python Cookbook” is one of the best books for beginners because for the following reasons,

It offers practical and real-world Python solutions that are easy to understand and apply.
The book covers a wide range of topics, providing a comprehensive introduction to Python programming.
It includes a collection of code recipes and examples that help learners grasp Python’s concepts and syntax.

---

**Head First Python: Engaging and Interactive Learning for Beginners**

_“Head First Python” is an good book for beginners because it uses a highly engaging and interactive approach, making learning Python fun and intuitive. The book employs visual aids, puzzles, and real-world examples to reinforce concepts and enhance understanding. It focuses on practical application, enabling learners to build projects and gain hands-on experience. Additionally, the book covers core Python topics and best practices, providing a solid foundation for aspiring programmers._

---

**Conclusion:**
These Three are the very best way to Get started with Python. They are more than enough for beginners to get the basic Syntax, Functions and workings in python.
Chụp ảnh và quay film màn hình chuyên nghiệp với ShareX
Tags: sep490, tools, productivity
Published: 2023-08-11 14:33:55

---
series: SEP490
---

Bạn nào quen mình lâu chắc sẽ biết mình thường dùng Greenshot để chụp ảnh màn hình + edit nhẹ & Cute Screen Recorder để quay film màn hình, thêm LiceAp để quay film màn hình thành Gif, 3 tool đó đều miễn phí 🤑 và nay có 1 tool còn xịn hơn, vừa chụp ảnh, vừa quay film thành mp4, vừa quay gif, vừa share, tất cả trong 1. đó là ShareX 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gbjmjg8jftnubrvld0ta.png)


Tool này rất mạnh mẽ, nên khi cài đặt vào cũng sẽ khá nhiều settings và sẽ hơi "ngợp" chút :D cơ mà làm chút là quen à :D 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8tl780oqkqste78lrsd5.png)
Ánh xạ tuyến tính là gì?
Published: 2023-08-11 14:32:23

Trong toán học, ánh xạ tuyến tính là một ánh xạ giữa các không gian vector mà ánh xạ tổng của hai vectơ là tổng của hai vectơ ánh xạ, và ánh xạ tích của một vectơ và một số là tích của vectơ và số ánh xạ. Các ánh xạ tuyến tính là một khái niệm quan trọng trong giải tích tuyến tính, hình học đại số và lý thuyết số.

Các ánh xạ tuyến tính có rất nhiều ứng dụng trong toán học và khoa học. Ví dụ, các ánh xạ tuyến tính được sử dụng trong:

Giải tích tuyến tính: Để giải các phương trình tuyến tính và các hệ phương trình tuyến tính.
Hình học đại số: Để nghiên cứu các đường thẳng, mặt phẳng và các đối tượng hình học khác.
Lý thuyết số: Để giải các phương trình Diophantine và các bài toán số học khác.
Máy học: Để phân loại dữ liệu và học máy.
Các ánh xạ tuyến tính là một công cụ mạnh mẽ có nhiều ứng dụng trong toán học và khoa học.

>>>Tham khảo: [https://ttnguyen.net/anh-xa-tuyen-tinh/](https://ttnguyen.net/anh-xa-tuyen-tinh/)

#ttnguyen #ttnguyenblog #daisotuyentinh #daisovahinhhocgiaitich #anhxatuyentinh
Day 24: Async vibes
Tags: day24, javascript, 100daysofcode
Published: 2023-08-11 14:30:00

Today will feel the async vibes! ⏰ with custom timer implementation


## Question
Implement polyfill function that simulates the `setTimeout` using callbacks.

```Javascript
window.mySetTimeout = function(callback, delay) {
  // Todo add your code
};

function delayedFunction() {
  console.log("Delayed function executed");
}

console.log("Start");
mySetTimeout(delayedFunction, 1000);
// Delayed function will be called after approximately 1000ms
console.log("End");
```
**NOTE:** 🤔 Attempting epic advanced-level question. Failure? Nah, fun exploration! Feel the process!😂


<img src="https://i.imgflip.com/7vgbp7.jpg" title="made at imgflip.com" />

Check the comment below to feel more. 🤣🤣🤣
Share Your Secrets for Staying Connected with Colleagues
Tags: discuss, carreer
Published: 2023-08-11 14:21:09

_This week we're chatting all things remote work, and we want to hear from you about your experiences, pros, cons, and advice for those transitioning or considering remote work options._

Let's dive into today's topic of conversation... 

> How do you maintain a sense of camaraderie and social interaction with colleagues while working remotely? Share creative ways you've connected with team members outside of work-related discussions and/or any virtual team-building activities that have helped strengthen team bonds.


Follow the DEVteam for more discussions and online camaraderie!

{% embed [https://dev.to/devteam](https://dev.to/devteam) %}
Step-by-step guide on installing AgensBrowser using a Docker image.
Published: 2023-08-11 14:15:56

**Introduction.**
AgensBrowser is a user interface which allows users to manage AgensGraph on a web browser. In this tutorial, you will install AgensBrowser using a docker image.

**Prerequisites.**
Before you proceed to the installation guide, make sure you have done the following,
- Installed Ubuntu.
- Installed AgensGraph.
- Installed Docker or use [this](https://docs.docker.com/engine/install/ubuntu/) tutorial.

**Installation Guide.**

1. Download the docker image by running the command below,
    ```docker pull bitnine/agensbrowser```

2. Create a docker volume where data can be persisted by running the command below.
    ```docker volume create --name myvolume```

3. Start the Container in different modes of your choice by running the command below.
    ```
    (Temporary mode)
    $ docker run -it bitnine/agensbrowser:v2.1.1 bash
    (Save mode)
    $ docker run -it -v myvolume:/home/agens/AgensGraph/data 
    bitnine/agensbrowser:v2.1.1 bash
    ```
4. Enter into the directory where AgensBrowser was installed.
    ```cd /home/agens/AgensBrowser```

5. Launch AgensBrowser by running the command below `/agensbrowser.sh`.
6. Visit this URL http://localhost:8085/index.html on the web browser to manage your AgensGraph database.

7. Stop the server by using the `exit` command.

**Conclusion**
AgensBrowser is a management tool for AgensGraph, it provides various features such as Rest API Integration, and it's quite useful for easy monitoring and management of AgensGraph.

**References**
https://hub.docker.com/r/bitnine/agensbrowser
https://hub.docker.com/r/bitnine/agensgraph
Enhancing Database Performance in PostgresPro with GIN Indexes
Tags: postgressql, agensql, apacheage, database
Published: 2023-08-11 13:34:27

**Introduction**
A popular open-source database management system known for its vast variety of indexing methods, notably the powerful Generalized Inverted Index (GIN), is PostgreSQL. The mechanics of GIN indexes are examined in-depth in this article along with their significant impact on PostgresPro database performance optimization.

**Understanding GIN Indexes**
GIN indexes are collections of inverted indexes designed specifically to handle complex data types including arrays, JSON, and full-text search. Each index item in this architecture represents a pair, with the key designating a term extracted from the indexed data and the value acting as a pointer to the matching row holding that word. In particular, GIN indexes perform exceptionally well in queries with many conditions, quickly locating rows that match all supplied query requirements.

**Operations in PostgresPro**
GIN indexes are implemented in PostgresPro using a multi-tiered design. A collection of index entries are stored in each tier in logically organized blocks of the same size. These entries, which have a common prefix, are found in these blocks. The Generalized Search Tree (GiST), a powerful search method used only by PostgresPro, makes it easier to traverse the GIN index. This complex algorithm speeds up the process of finding relevant blocks that include index items that meet the specified requirements.

**Advantages**

- Enhanced Query Performance
- Efficient Support for Array and JSON Data Types
- Flexibility in Indexing
- Improved Handling of Complex Queries

**Conclusion**
The potential of GIN indexes as a strong indexing method holds the key to dramatically improving PostgresPro's database speed. The execution of complex queries is enhanced by these indexes' extensive support for complex data types like arrays, JSON, and full-text search. PostgresPro users can unlock scalability, speed up query processing, and improve overall database performance by utilizing the features of GIN indexes.
Back to php-fpm, unpopular opinion
Published: 2023-08-11 13:16:05

Everyday there are a lot of trendy technologies and tools out there, when it comes to PHP the trendy concept is "Async PHP" where there are some packages/extensions tells us that it provides a truly **async** functionality but in php, that is right, but there is something more important we didn't answer, which is "What is the actual problem we're trying to solve here?".

You're trying to solve performance issues by re-inventing the wheel, PHP-FPM has already been built years ago to provide a FastCGI process manager that manage PHP processes and gives you a lot of scalability options, you can easily scale it to handle multiple requests at a time by configuring how many processes you want to be available, which we can map it to "workers", it also enables you to configure the maximum time a worker takes to finish a request, if it exceeded that time, it would be terminated instantly!, as well a lot of security problems it solves.

If your request life cycle is designed to take 1 second, then it will take 1 second, it isn't a language only problem it is about how you're writing the control flows, database queries, external network calls, ... etc.

Just try to write a "Hello World" in both PHP and nodejs without any framework, you will find that the're very close to each other, this post isn't about benchmarking but it is about PHP-FPM only.

All new tools claims the async world, already do the above mentioned concepts already but in another way which doesn't solve the main problem "the community and the ecosystem" which isn't a problem at all!

But you may find another problem which is "simplcify" how to simplify the production runtime, I don't want to write a nginx.conf, php-fpm.ini and php.ini in addition to my original application configurations, I'll say, "You're right", that's why there are many tools out there to do so instead of you, something like [PHOO](https://github.com/alash3al/phoo) which is being used and tested in production, is doing a lot of magic for you:
- Configures, spawns and control the PHP-FPM process transparently for you.
- Offloads the HTTP requests and proxies them to the FastCGI workers handled by the FPM process.
- Serves static files for you.

All what you need is `phoo serve -r ./public` to serve your laravel project without any extra lines of configurations.


Let's back to basics, any old stuff isn't build for old days, but it is proven to work over years/decades, so let's make use of the old but gold tools.

The above words are just my personal opinion which doesn't mean "PHP is the best" but it means that each tool is designed to do somethings better than others, and thinking about the main problem you're trying to solve is the main problem you should focus on, as not all the apps/websites out there focuses on 1ms response time only! that's why the productive frameworks exist, if you need raw performance go and write everything from scratch.