teleren/devto huggingface dataset:
FastAPI + Celery = ♥
Tags: python, fastapi, tutorial, showdev
Published: 2023-03-27 12:15:00


*Interested in Python FastAPI? Wondering how to execute long-running tasks in the background in Python? You came to the right place!*

---

## The use case

I learned about [FastAPI](https://fastapi.tiangolo.com/) and [Celery](https://docs.celeryq.dev/en/stable/getting-started/introduction.html) when confronted with a simple yet interesting use case:

![use case](https://derlin.github.io/introduction-to-fastapi-and-celery/assets/00-goal.excalidraw.png)

I had a Jupyter Notebook that connected to a database, ran some heavy processing on the data (using machine learning and everything), and saved aggregated data back to the database. 

Since notebooks are great for developing, the requirement was to **keep using notebooks for development but to be able to trigger the processing from an API call**. The notebook should **never be executed twice in parallel** though. In other words, the API should return an error if the notebook were already being executed. Note that the notebook would be provided once at deployment time: it won't change during the lifecycle of the app.

---

## The implementation

I was initially planning to use a simple [Flask](https://flask.palletsprojects.com/) app, but soon got into trouble. How can I (1) run the notebook in a background thread and (2) restrict its execution to one at a time?

This is how I discovered FastAPI and Celery. I implemented an MLP (_**M**inimum **L**ovable **P**roduct_) based on those technologies available on GitHub.

⮕ ✨✨ [github.com/derlin/fastapi-notebook-runner](https://github.com/derlin/fastapi-notebook-runner) ✨✨

---


## The tutorial

The use case was perfect for learning. This is why I cooked a complete tutorial based on it, along with schemas and explanations. The [tutorial repository](https://github.com/derlin/introduction-to-fastapi-and-celery) can be used as a base to follow along. Not only will you learn about FastAPI and Celery, but also [Poetry](https://python-poetry.org/), [ruff](https://beta.ruff.rs/docs/), and other nice tips and tricks.

⮕ ✨✨ [derlin.github.io/introduction-to-fastapi-and-celery](https://derlin.github.io/introduction-to-fastapi-and-celery/) ✨✨

Jump to the main sections:

* [Introduction](https://derlin.github.io/introduction-to-fastapi-and-celery/)
* [Poetry](https://derlin.github.io/introduction-to-fastapi-and-celery/01-poetry)
* [FastAPI](https://derlin.github.io/introduction-to-fastapi-and-celery/02-fastapi)
* [Celery](https://derlin.github.io/introduction-to-fastapi-and-celery/03-celery/)
* [Executing Notebooks](https://derlin.github.io/introduction-to-fastapi-and-celery/04-notebook/)
* [Finishing touches](https://derlin.github.io/introduction-to-fastapi-and-celery/05-more/)

---

I used the above website as a base for a talk at the [GDG Fribourg](https://gdg.community.dev/gdg-fribourg/) and figured some of you could also benefit from it. Don't forget to leave a :star:!
I tried to fish for compliments from Code GPT
Tags: gpt3, webdev
Published: 2023-03-25 15:58:59

Here's what Code GPT thinks about the quality of my React code:

```
Your code is quite well written and structured. However, there are a couple of things that you could consider to improve it:

1. Use meaningful variable names: Try to use descriptive variable names that reflect the purpose of the data that they hold. For example, instead of `exp`, you could name it `workExp` and instead of `k` and `n`, you could name it `index` or `keyIndex`.
2. Use arrow functions in JSX: You can use arrow functions to make the code more readable and easier to understand. For example, instead of using a regular function like `(exp, k) => {...}`, you can use an arrow function (`(workExp, index) => {...}`).
3. Apply consistent whitespace and formatting: Some parts of your code have inconsistent whitespace and formatting. For example, some tags have spaces between the tag name and the attributes, while others don't. To make your code more consistent and easier to read, apply the same formatting rules throughout the file.
```

Ruthlessly punishing me for my lazyness with meaningful variable names inside array methods! :sweat_smile:

PS. It got a little confused by my arrow functions for some reason? Not sure what is going on there. The whitespace and formatting comment is also strange, since I use a default formatter for react/tsx...
Crux Search Engine in Chrome
Published: 2023-03-24 10:39:14

In this Post We will be looking at Crux Search Engine In chrome, so without further ado lets get stared :)

## What Is Crux
Crux stands for chrome real user experience report , it is a report that is generated by the field data (real data that chrome gets from our devices :)and then this data is used for checking the CWB ([Core Web Vitals](https://web.dev/vitals/)) Of a site.

## Why do you want to see Crux Report Of A site
Crux report is very helpful in optimizing the core web vitals of a site , that report consists of core web vitals metrics such as FCP (first contentful paint), LCP(largest contentful paint) and CLS(content layout shift) by getting to know these metrics, you can start working on optimizing them, so no user feel like , your site sucks(slow) and click back button.

## How to Use Crux Search engine in Chrome

- Go into the Chrome setting with the help of three dot menus in top right of the chrome.
- After then tap on search engine settings
- Now tap on the "Manage search engines and site search" and now scroll down to "Site Search" and now click "Add" button and enter following details

```
Search engine: CrUX
Shortcut: crux
URL with %s in place of query: https://datastudio.google.com/c/u/0/reporting/bbc5698d-57bb-4969-9e07-68810b9fa348/page/keDQB?params=%7B%22origin%22:%22%s%22%7D
```
- Done , now just go back to search bar of chrome and type "crux" and press tab button and now you will be able to check the crux report by just typing the origin url.

Note:- As a rule of thumb, use whichever origin users see in the URL bar.
Bug name folder Windows 11
Tags: windows11, bugwindows1, foldernamebug, wsl
Published: 2023-03-24 12:41:26

For some reason, while installing an [Astro Project ](https://astro.build/) , i've inserted invalid name for the folder, and some way, the framework had done it a folder with a invalid name, ocurring a infinite loop in terminal, when you try to delete a folder with reference to "." , the system cannot find it and you cant delete this.

The solution is to enter in WSL in a linux distro, inside the same terminal and delete the folder :)

`cd /mnt/c/Users/user-name/source/repos/Project/target_folder$`

and 

`rm -r target_folder`

And solved it.

Maybe it can help someone out there, if some way you got invalid namefolders and can't delete them.
I finally got a DevOps role! Then I got laid off after less than a year.
Tags: devops
Published: 2023-03-27 16:30:52

So much has changed/happened since my last post in summer of '22 after I completed [Forrest Brazeal's Cloud Resume Challenge](https://cloudresumechallenge.dev/)! Two months after completing the challenge (through some heavy networking, luck, and perseverance), I was able to secure my first DevOps role at a great small series A startup. It was remote with great starting pay and benefits, with plenty of opportunity to learn and grow.

I was able to quickly put my skills to work, and learned so much from my teammates and others. I designed and built infrastructure, learned how to set up application monitoring, containerized applications, and got familiar with multiple tools and technologies. My new gig was everything I'd hoped and more. 

Five months later, my boss (Director of Engineering) was let go (bad sign). There were rumblings about the state of the company, but I kept my head down and learned as much as possible. Things seemed to be steady, but I did have a nagging feeling that things weren't going as well as they could be on the business front. 

Three months after my boss was let go, four out of six engineers on our team (including myself and my DevOps teammate) were laid off along with others on the business side (about half of the company). Ouch. I had JUST started to catch my stride in my new(ish) role, and the opportunity just evaporated. 

I'm almost two months in with my job search for a new DevOps role. Wish me luck!
Governments on GitHub
Tags: opensource, github, government, osdc
Published: 2023-03-24 20:34:17

---
title: Governments on GitHub
published: true
description: Local and national governments and their GitHub organizations
tags: opensource, github, government, osdc
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2023-03-24 20:31 +0000
---

I am doing some research into how various organizations handle open source and contribution to open source and I just bumped into this page listing various Government agencies around the world and [their GitHub organizations](https://government.github.com/community/). It's a goldmine.

The data I collected so far can be found [here](https://osdc.code-maven.com/open-source-by-organizations/)
Introduction To HTML
Tags: webdev, javascript, beginners, tutorial
Published: 2023-03-25 10:01:21




I wrote this article to help newbies that are about to enter into the world of web design.
You may think it's difficult, but it's not. It's very easy.
Just follow through to the end.

[Click to read!](https://link.medium.com/plW67Pu6ryb)
Python map(), filter() and reduce()
Tags: python, programming, tutorial, codenewbie
Published: 2023-04-02 04:17:28

[map(), filter(), and reduce() are built-in Python functions](https://www.programdoc.com/python/map-filter-reduce) that are used to perform data manipulation on iteratable of data such as lists, tuples, and sets.

## Lambda function
[Python lambda is a anonymous function](https://www.programdoc.com/python/lambda), declared using single line expression. It can be passed as arguments in function call. Using this with map, filter and reduce makes it easier to write the expression in a single statement and easier to understand.

## Map function
_Syntax_
```py
map(function, iterator)
```
The map() function will send the each values from the iterator to the function, it will return the processed value. map will returns an iterator containing the results of the processed values.

_Example:_
```py
# square the values of a list using map()
numbers = [1, 2, 3, 4, 5]
squared_numbers = list(map(lambda i: i ** 2, numbers))
print(squared_numbers) 


# Output: [1, 4, 9, 16, 25]
```

## filter function
_Syntax_
```py
filter(function, iterator)
```
The filter() function is similar to map but with one difference, it will return the new iterator based on the function return value. It returns an iterator containing the elements from a sequence for which a given function returns True.

_Example:_
```py
# filter even numbers from a list using filter()
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
even_numbers = list(filter(lambda i: i % 2 == 0, numbers))
print(even_numbers)


# Output: [2, 4, 6, 8, 10]
```

## reduce function
_Syntax_
```py
reduce(function, iterator)
```
The reduce() function will take first two values from the iterator sequence, pass it as a argument to the function, then it will take the return value from the function and pass the value along with the next value from iterator as a argument to the function, this will continue till the end of the sequence list. Finally will return a single value.

_Example:_
```py
# calculate the product of a list of numbers using reduce()
from functools import reduce
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
product = reduce(lambda i, j: i * j, numbers)
print(product) 


# Output: 3628800
```
Best smm panel service provider
Tags: bestsmmpanel, smmpanel, bangladeshsmmpanel, smmdepth
Published: 2023-03-25 11:51:24

**[An SMM panel](https://smmdepth.com)**, or Social Media Marketing panel, is a web-based platform that provides various services to help businesses and individuals boost their social media presence. SMM panels offer a range of social media services such as likes, followers, views, shares, and comments on popular social media platforms such as Facebook, Instagram, Twitter, TikTok, YouTube, and more.

SMM panels usually have a dashboard that allows users to select the desired service and enter the necessary information such as the username or URL of their social media account, the number of likes or followers they want to buy, and the payment information.

SMM panels are used by businesses and individuals to increase their social media presence and engagement, and ultimately, drive more traffic and sales to their website or products. However, it's important to use SMM panels responsibly and not engage in any unethical or spammy practices that could harm your social media reputation.
Terms used in Reinforcement Leaning
Tags: reinforcementlearning, machinelearning, datascience, deeplearning
Published: 2023-03-25 13:43:21

Every AI/ML/Data Science enthusiast knows the definition of Reinforcement Learning - it is a feedback-based machine learning technique in which an agent learns to behave in an environment by performing actions and observing their outcomes. For each good action, the agent receives positive feedback, and for each bad action, it receives negative feedback or a penalty. However, many are not familiar with the specific terms used in this definition. Let me explain them with an example.



Let's consider the example of a robot that is learning to navigate a maze. In this scenario:



🕵️Agent: The robot is the agent, which is the decision-maker that interacts with the environment. The agent can perceive the environment and take actions to achieve its goal.



🧀‍ꡌ‍ꡙ‍ꡚ‍🐁 Environment: The maze is the environment, which is the context in which the agent operates. The environment can provide feedback to the agent in the form of rewards or punishments.



🎬 Actions: The robot can take different actions such as moving forward, turning left, or turning right. These actions are the choices available to the agent.



🙂Feedback: The environment provides feedback to the agent based on its actions. The feedback can be positive, negative, or neutral.



🏆 Reward: The agent receives a reward when it takes an action that leads it closer to its goal. For example, if the robot moves towards the exit of the maze, it may receive a positive reward.



🚫 Punishment: The agent receives punishment when it takes an action that leads it further away from its goal. For example, if the robot hits a wall, it may receive a negative reward.



📜 Policy: The policy is the strategy used by the agent to select actions based on its current state. The goal of the agent is to learn an optimal policy that maximizes the long-term reward. For example, the robot may learn to follow the left wall of the maze to reach the exit.



📍 State: The state is a representation of the environment at a particular time, which includes information such as the location of the agent and other relevant information.



#datascience #machinelearning #ai #ml #reinforcementlearning
How to implement Dependency Injection in Laravel Livewire
Tags: php, laravel, livewire, programming
Published: 2023-03-26 10:32:53

I like to use Dependency Injection (DI) in my code. It helps me to keep my code clean and reduces code coupling.

## What is Dependency Injection

Dependency Injection is a design pattern that allows for the separation of concerns by removing the responsibility of creating objects and their dependencies from the class that uses them. Instead, these dependencies are provided or injected into the class by a third-party or a container.

Here's an example in PHP:

```php
class UserService {
    private $userRepository;

    public function __construct(UserRepository $userRepository) {
        $this->userRepository = $userRepository;
    }

    public function getUsers() {
        return $this->userRepository->findAll();
    }
}

class UserRepository {
    public function findAll() {
        // fetch users from the database
    }
}
```

In this example, the `UserService` requires a `UserRepository` object to fetch users from the database. Instead of creating the `UserRepository` object inside the `UserService`, we inject it via the constructor. This allows for better separation of concerns and makes the `UserService` more flexible, as we can easily swap out the `UserRepository` implementation without changing the UserService code. You can read more about how it works in Laravel [in documentation](https://laravel.com/docs/10.x/container).

## How to use DI with Livewire

When we use Livewire components, we can’t use the `__construct` method inside it because Livewire needs `$id` for a component.

I started to research and found this [thread on GitHub](https://github.com/livewire/livewire/issues/380). Some developers recommend using the `mount()` method like this:

```php
use Livewire\Component;
use Psr\Log\LoggerInterface;

class Foo extends Component
{
    protected LoggerInterface $logger;

    public function mount(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    public function render()
    {
        $this->logger->info('component rendered');
        return view('livewire.foo');
    }

    public function action()
    {
        $this->logger->info('action triggered');
    }
}
```

The problem with `mount()` DI is that it doesn't work in some cases. For example, when you click on the button and call `action()`, your `$this->logger` will be empty. This happens because the `mount()` method isn't called when the user interacts with the component.

The good news for us is that in [version 2.6 of Livewire](https://laravel-news.com/livewire-v2-6-0) developers added `boot()` hook. This hook will be called every time you use your component. Here's how you can use DI inside your Livewire component:

```php
class YourComponent extends Livewire\Component
{
    private SomeService $someService;
    private OneMoreService $oneMoreService;

    public function boot(
        SomeService $someService,
        OneMoreService $oneMoreService
    )
    {
        $this->someService = $someService;
        $this->oneMoreService = $oneMoreService;
    }
}
```
MatchTheRegex
Tags: regex, cybersecurity, picoctf, beginners
Published: 2023-04-01 14:32:08

# MatchTheRegex

**100 points**

AUTHOR: SUNDAY JACOB NWANYIM

Description
How about trying to match a regular expression
The website is running here.

*Note:* This challenge launches an instance on demand.

___

Looking inside the script tag we can see:

```html
<script>
	function send_request() {
		let val = document.getElementById("name").value;
		// ^p.....F!?
		fetch(`/flag?input=${val}`)
			.then(res => res.text())
			.then(res => {
				const res_json = JSON.parse(res);
				alert(res_json.flag)
				return false;
			})
		return false;
	}

</script>
```

The regex is supposed to be `^p.....F!?`, literally the first and only guess was `picoCTF`, when I entered it gave the flag:

> picoCTF{your flag}
ASDF is a single version manager for all languages
Tags: programming
Published: 2023-04-01 15:22:41

I had to manage multiple versions of NodeJS, so I installed Node Version Manager.

Then I had to also manage multiple versions of Python, so I installed PyEnv.

Then I had to manage multiple versions of Rust, Golang, Lua...

There must be a better way.

Enter `asdf`, a single version manager for all programming languages.

Homepage: https://asdf-vm.com/

Caveat:  It’s currently only available for MacOS and Linux.


![asdf on the terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3bmz2dbffgqg3awfbg7f.png)
command line game
Tags: python, games, programming, beginners
Published: 2023-04-02 07:59:54

Dive into a gameplay like never before.

### summary
The game is about akin to dungeons and dragons. There are two doors; the left door and the right door. One of the rooms/caves is empty. If you search further/look around you will encounter a sword.

The other room contains a dragon .If you choose to fight the dragon without a sword , chances of defeat are high.

### Give it a try
Would you like to give it a try?
https://github.com/symonkipkemei/command-line-game


### Pseudocode breakdown
Here is a sum of pseudocodes of how the game play works. I will go into the details later on.
1. get the player name
2. display message 
3. present them with two doors
4. if they choose the left door, they'll see an empty room, they can choose to look around, If they do so, they will find a sword. They can choose to take it or leave it.
5. if they choose the right door, they'll encounter a dragon,  they have the choice to fight it. If they have the sword from the other room, then they will be able to defeat it and win the game.
6. In both options they have an option to return to the previous room.
How To Deploy Jitsi Meet(video conference) on Ubuntu
Tags: jitsi, meet, jitsimeet, opensource
Published: 2023-04-02 10:20:06

####**Jitsi Meet is an open source video-conferencing application based on WebRTC.** 
A Jitsi Meet server provides multi-person video conference rooms that you can access using nothing more than your browser and provides comparable functionality to a Zoom or Skype conference call.

### Step 1 — System Hostname
```
sudo hostnamectl set-hostname jitsi.my_domain.com
```
Check that this was successful by running the following:
```
hostname
```
Next, you will set a local mapping of the server’s hostname. ```
nano /etc/hosts
```
add this line
```
127.0.0.1 <jitsi.my_domain.com>
```
### Step 2 — (Before Install) Must Configure Prosody XMPP Server

**ERROR:** I got an error in the jitsi-meet install.
`Jitsi-meet : Depends: jitsi-meet-prosody (= 1.0.6776-1) but 1.0.6644-1 is to be installed`

**Solution:** `Add the Prosody package repository`

To install the latest version, add the Prosody repository with the following command:
```
echo 'deb https://packages.prosody.im/debian focal main' | sudo tee /etc/apt/sources.list.d/prosody.list
```
Now, run the following command to download and import the Prosody public key.
```
wget https://prosody.im/files/prosody-debian-packages.key -O- | sudo apt-key add -
```
Next, update the local package index. Then, install 
```
sudo apt update
sudo apt install prosody
sudo apt install libunbound-dev liblua5.3-dev
luarocks install luaunbound
systemctl status prosody
```


### Step 3 — Install Jitsi

First, download the Jitsi GPG key with the wget downloading utility:
```
wget https://download.jitsi.org/jitsi-key.gpg.key
```
Next, add the GPG key you downloaded to apt’s keyring using the apt-key utility:
```
sudo apt-key add jitsi-key.gpg.key
```
Now, you will add the Jitsi repository to your server by creating a new sources file that contains the Jitsi repository. Open and create the new file:
`sudo nano /etc/apt/sources.list.d/jitsi-stable.list`. Add this line to the file for the Jitsi repository:
```
deb https://download.jitsi.org stable/
```
then install the jitsi-meet package:
```
sudo apt update
sudo apt install jitsi-meet
```

During the installation of jitsi-meet you will be prompted to enter the domain name.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/slsqtbl7xwnsubx679wg.png)

after that select let's Encrypt SSL. (et's Encrypt is a non-profit certificate authority) or select **no** if you don't need to jitsi-web-cloud in next option.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8yv5so8zv4mrv9cpcc0e.png)
 
**_Your Jitsi Meet server is now set up_**
Connectedminds
Tags: mobile, mentalhealth
Published: 2023-04-02 09:45:13

https://connectedminds.ai/

**A mental health app that helps you discover contentment, purpose & connection.**

Connect with your mind and start your journey with our mental well-being app that helps you discover health, contentment, purpose, and connection. Connected minds is the number one global mental well-being platform for everyone who cares about their mental health. The platform offers immense mental well-being content in the form of Podcasts, Articles, Posts, and Courses curated by our carefully hand-picked, licensed Psychologists, Therapists, and Counselors. Subscribed users can access all this unlimited mental well-being content.