teleren/devto huggingface dataset:
Changing the PublishedContent for the current request in Umbraco
Tags: umbraco, dotnet
Published: 2024-05-28 15:44:56

Using Umbraco's [notifications](https://docs.umbraco.com/umbraco-cms/reference/notifications) handlers it is possible to override the PublishedContent being loaded for the current request.

The example below assumes you have a maintenance mode you can toggle in you Backoffice. When enabled, every page request to your website should display the maintenance page.

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

Start by creating a `MaintenanceHandler.cs` file:

```c#
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Notifications;

namespace Adventures
{
    public class MaintenanceHandler : INotificationHandler<RoutingRequestNotification>
    {
        public void Handle(RoutingRequestNotification notification)
        {
            var request = notification.RequestBuilder;

            var website = request.PublishedContent?.Root();
            if (website == null) return;

            var isInMaintenanceMode = website.Value<bool>("maintenanceMode");
            if (!isInMaintenanceMode) return;

            var maintinancePage = website.Value<IPublishedContent>("maintenancePage");
            if (maintinancePage != null)
            { 
                // If maintinance is enabled and the page exists 
                // we set the content for the request and change the template
                request.SetPublishedContent(maintinancePage);
                request.TrySetTemplate(maintinancePage.GetTemplateAlias());
            }
        }
    }
}
```
... and then register it in `Program.cs`:

```c#
builder.CreateUmbracoBuilder()
    .AddBackOffice()
    .AddWebsite()
    .AddDeliveryApi()
    .AddComposers()
    .AddNotificationHandler<RoutingRequestNotification, MaintenanceHandler>()
    .Build();
```

Visiting the website before toggling maintenance mode:

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

Visiting the website after toggling maintenance mode:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oorsrif1or1kpu8fbwch.png)
OWL Odoo framework
Tags: odoo
Published: 2024-05-28 15:38:58

When we work with odoo, it is important with the namecases and caps. I spent like many hours to find out an error like below 


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

and my code is below 

```
export class PPPProductIdFieldInSO extends Many2OneField {
    setup() {
        super.setup();
        this.dialog = useService("dialog");
    }
   
}
PPPProductIdFieldInSO.template = "web.Many2OneField"
 
export const PPPProductIdFieldInSO = {
    ...many2OneField,
    component: PPPProductIdFieldInSO,
};
 
registry.category("fields").add("pppproduct_id_with_warning", PPPProductIdFieldInSO);
```


and the fixed code is below 


```
export class PPPProductIdFieldInSO extends Many2OneField {
    setup() {
        super.setup();
        this.dialog = useService("dialog");
    }
   
}
PPPProductIdFieldInSO.template = "web.Many2OneField"
 
export const pPPProductIdFieldInSO = {
    ...many2OneField,
    component: PPProductIdFieldInSO,
};
 
registry.category("fields").add("pppproduct_id_with_warning", pPPProductIdFieldInSO);
```

can you spot the issue ?  if you did so fast, then you are good but it took me a while to get into that fix.
Test
Published: 2024-05-28 15:37:26

```
// async/await
let fn = async () => {
  try {
    let result = await getData()
    Console.log(result)
  } catch {
  | err => Console.error(err)
  }
}

// Promises
let fn = () => {
  getData()
  ->Promise.thenResolve(result => Console.log(result))
  ->Promise.catch(err => {
    Console.error(err)
    Promise.resolve()
  })
}
```
1208. Get Equal Substrings Within Budget
Tags: php, leetcode, algorithms, programming
Published: 2024-05-28 15:31:57

1208\. Get Equal Substrings Within Budget

Medium

You are given two strings `s` and `t` of the same length and an integer `maxCost`.

You want to change `s` to `t`. Changing the <code>i<sup>th</sup></code> character of s to ith character of `t` costs `|s[i] - t[i]|` (i.e., the absolute difference between the ASCII values of the characters).

Return _the maximum length of a substring of `s` that can be changed to be the same as the corresponding substring of `t` with a cost less than or equal to `maxCost`. If there is no substring from `s` that can be changed to its corresponding substring from `t`, return `0`_.

**Example 1:**

- **Input:** s = "abcd", t = "bcdf", maxCost = 3
- **Output:** 3
- **Explanation:** "abc" of s can change to "bcd".

  That costs 3, so the maximum length is 3.


**Example 2:**

- **Input:** s = "abcd", t = "cdef", maxCost = 3
- **Output:** 1
- **Explanation:** Each character in s costs 2 to change to character in t,  so the maximum length is 1.


**Example 3:**

- **Input:** s = "abcd", t = "acde", maxCost = 0
- **Output:** 1
- **Explanation:** You cannot make any change, so the maximum length is 1.


**Constraints:**

- <code>1 <= s.length <= 10<sup>5</sup></code>
- <code>t.length == s.length</code>
- <code>0 <= maxCost <= 10<sup>6</sup></code>
- `s` and `t` consist of only lowercase English letters.


**Solution:**

```
class Solution {

    /**
     * @param String $s
     * @param String $t
     * @param Integer $maxCost
     * @return Integer
     */
    function equalSubstring($s, $t, $maxCost) {
        $j = 0;
        for ($i = 0; $i < strlen($s); ++$i) {
            $maxCost -= abs(ord($s[$i]) - ord($t[$i]));
            if ($maxCost < 0)
                $maxCost += abs(ord($s[$j]) - ord($t[$j++]));
        }

        return strlen($s) - $j;
    }
}
```


**Contact Links**

- **[LinkedIn](https://www.linkedin.com/in/arifulhaque/)**
- **[GitHub](https://github.com/mah-shamim)**
Light Bulb Challenge
Tags: javascript, webdev, beginners, programming
Published: 2024-05-28 15:13:56

Hi, This is one of the javascript challenges that was quite popular when I was studying Javascript. This challenge is a completly begginer friendly challenge for who ever began to code Javascript.
Bulb challenge is when you create button and when the user presses the button the content changes or in this case, the image of the unlit bulb changes to a lit bulb image when the use clicks on light off button.This challenge is performed by the onclick function in Javascript.
Hope this would be helpfull!!
Your Ultimate Guide to Preparing for the AWS Certified Cloud Practitioner Certification with MyExamCloud: A 5-Week Study Plan
Tags: aws, cloudcomputing, software, coding
Published: 2024-05-28 15:02:20

Earning the AWS Certified Cloud Practitioner certification is a highly valuable achievement for individuals with a solid understanding of the AWS Cloud, regardless of their job role. To successfully obtain this certification, candidates must demonstrate their knowledge in various areas related to AWS.

For an effective preparation strategy for the Python AWS Certified Cloud Practitioner exam, we have created a 5-week study plan that covers all exam objectives and important study techniques.

**Phase 1: Building a Strong Foundation (Week 1)**
The first week of preparation should focus on establishing a strong foundation of knowledge about the AWS Cloud. This includes getting familiar with AWS concepts and learning about the core AWS services.

**Phase 2: Focusing on Exam Topics (Week 2)**
In the second week, you should concentrate on each topic covered in the exam. This will help you solidify your understanding of the subject and serve as a solid base for the remaining phases of study.

**Phase 3: Practice and Revision (Week 3-4)**
To enhance your preparation, it is crucial to practice and review consistently. Utilize resources such as MyExamCloud to access AWS Certified Cloud Practitioner practice tests and revise essential concepts. Taking objective tests and identifying weak areas will also strengthen your overall knowledge.

**Phase 4: Attempting Mock Tests and Analyzing Results (Week 5)**
During the final week of preparation, prioritize taking mock tests and analyzing the results. These are a crucial part of your study plan as they simulate the real exam environment and help identify any remaining knowledge gaps.

**MyExamCloud's AWS Certified Cloud Practitioner Study Plan**
MyExamCloud [CLF-C02 Practice Tests](https://www.myexamcloud.com/onlineexam/clf-c02-practice-exam-questions.course) offers a comprehensive study plan for AWS Certified Cloud Practitioner exam preparation, which includes:
- 23 full-length mock exams
- 2 free trial exams
- 5 flashcard quiz exams
- Objective and random tests
- eBook with detailed answers and explanations
- Access to course material through a mobile app or web browser
- 1400+ questions, organized by exam topics
- "Plan, Practice, Achieve" dashboard to set goals and track progress

Don't hesitate any longer, start your journey towards achieving AWS Certified Cloud Practitioner certification with MyExamCloud. With our comprehensive study plan, you can confidently prepare for the exam and achieve success!
Sorting Arrays
Tags: java, programming, learning, beginners
Published: 2024-05-28 14:38:39

Sorting, like searching, is a common task in computer programming. Many different algorithms have been developed for sorting. This section introduces an intuitive sorting algorithm: selection sort.

Suppose that you want to sort a list in ascending order. Selection sort finds the smallest number in the list and swaps it with the first element. It then finds the smallest number remaining and swaps it with the second element, and so on, until only a single number remains. Figure below shows how to sort the list {**2**, **9**, **5**, **4**, **8**, **1**, **6**} using selection sort.

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

You know how the selection-sort approach works. The task now is to implement it in Java. Beginners find it difficult to develop a complete solution on the first attempt. Start by writing the code for the first iteration to find the smallest element in the list and swap it with the first element, and then observe what would be different for the second iteration, the third, and so on. The insight this gives will enable you to write a loop that generalizes all the iterations.

The solution can be described as follows:

`for (int i = 0; i < list.length - 1; i++) {
 select the smallest element in list[i..list.length-1];
 swap the smallest with list[i], if necessary;
 // list[i] is in its correct position.
 // The next iteration applies on list[i+1..list.length-1]
}`

Below implements the solution:

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

The **selectionSort(double[] list)** method sorts any array of **double** elements. The method is implemented with a nested **for** loop. The outer loop (with the loop control variable **i**) (line 12) is iterated in order to find the smallest element in the list, which ranges from **list[i]** to **list[list.length-1]**, and exchange it with **list[i]**.

The variable **i** is initially **0**. After each iteration of the outer loop, **list[i]** is in the right place. Eventually, all the elements are put in the right place; therefore, the whole list is sorted.
Ibuprofeno.py💊| #111: Explica este código Python
Tags: python, spanish, learning, beginners
Published: 2024-05-28 14:32:49

## **<center>Explica este código Python</center>**
#### <center>**Dificultad:** <mark>Fácil</mark></center>

```py
categories = ["color", "fruit", "pet"]
objects = ["blue", "apple", "dog"]

new_dict = {key:value for key, value in zip(categories, objects)}
print(new_dict)
```

👉 **A.** `{'blue': 'color', 'apple': 'fruit', 'dog': 'pet'}`
👉 **B.** `{'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}`
👉 **C.** `KeyError`
👉 **D.** `RangeError`

---

{% details **Respuesta:** %} 

👉 **B.** `{'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}`

Podemos crear diccionarios por comprensión de una manera muy similar a las listas por comprehensión. 

En el ejemplo iteramos de manera paralela sobre las listas `categories` y `objects` y regresamos cada par clave valor dentro de un nuevo diccionario. 


{% enddetails %}
Stay Updated with PHP/Laravel: Weekly News Summary (20/05/2024 - 26/05/2024)
Tags: php, laravel
Published: 2024-05-28 14:30:39

Dive into the latest tech buzz with this weekly news summary, focusing on PHP and Laravel updates from May 20th to May 26th, 2024. Stay ahead in the tech game with insights curated just for you!

This summary offers a concise overview of recent advancements in the PHP/Laravel framework, providing valuable insights for developers and enthusiasts alike. Explore the full post for more in-depth coverage and stay updated on the latest PHP/Laravel development.

Check out the complete article here [https://poovarasu.dev/php-laravel-weekly-news-summary-20-05-2024-to-26-05-2024/](https://poovarasu.dev/php-laravel-weekly-news-summary-20-05-2024-to-26-05-2024/)
Day3: Git and GitHub
Published: 2024-05-28 14:28:13

# Git:
Git is a distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Version Control: Git allows multiple developers to work on the same project simultaneously without interfering with each other's work. It tracks changes to files, enabling developers to revert to previous versions if necessary.

Branching and Merging: Git allows for the creation of branches, which are separate lines of development. Developers can work on features or fixes in isolated branches and then merge these branches back into the main codebase.

Distributed: Each developer has a full copy of the repository, including the entire history of changes. This means that they can work offline and sync changes when they are back online.

**Usage**: Git is a command-line tool, although there are also graphical user interfaces (GUIs) and integrations in development environments that facilitate its use.

**Installation**: Git needs to be installed on your local machine. It's available for all major operating systems (Linux, macOS, Windows).

# GitHub:
GitHub is a web-based platform that uses Git for version control. It offers a collaborative interface for managing Git repositories.

Repository Hosting: GitHub hosts Git repositories, making it easy to share code with others. Repositories can be public (open to everyone) or private (restricted access).

Collaboration Tools: GitHub provides tools for issue tracking, project management, and collaboration. This includes pull requests, where developers can propose changes to the codebase, and code reviews.

Integrated Features: GitHub offers additional features like GitHub Actions (for CI/CD), GitHub Pages (for hosting static websites), and GitHub Packages (for hosting packages).

Social Coding: GitHub is often described as a social network for developers. Users can follow each other, star repositories, and contribute to open-source projects.

**Usage**: GitHub can be accessed through a web browser. It also integrates with Git, meaning you can push and pull changes from your local Git repository to GitHub using Git commands.

**Account**: You need to create an account on GitHub to use its services. There are free and paid plans, with the free plan offering a substantial amount of functionality for individual developers and open-source projects.
We Need to Talk More About Conformance, If We Want to Stop Fantasy HTML
Tags: html, conformance, validation, community
Published: 2024-05-28 14:24:56

Conformant and valid HTML is the exception when it comes to HTML used on websites and in apps. This is particularly visible on popular websites, where at the moment, <a href="https://meiert.com/en/blog/html-conformance-2023/">none of the Top 100 sites worldwide</a> uses valid HTML.

It’s easy to argue that conformant and valid output is <a href="https://meiert.com/en/blog/professional-web-developer/#toc-high-standards">the mark of a professional web developer</a>. It takes <em>nothing</em> to write a document that contains HTML errors. To reuse a past metaphor, put a houseplant on the keyboard, store the result as a file with an “html” extension, and you have an invalid HTML document.

To stop houseplant and fantasy HTML, however, we need to raise awareness for HTML conformance and validation—we need to talk about HTML conformance and validation.

That happens <a href="https://frontenddogma.com/topics/conformance/">not nearly as often</a> as it should happen (and it should not always be done by the same people).

Surveys like <a href="https://2023.stateofhtml.com/">State of HTML</a> are an excellent opportunity to inquire about authors’ validation practices (one that, sadly, was missed last year). Even if the result confirms what we can measure on people’s websites—that authors don’t pay attention to using actual, valid HTML code—, asking plants a seed.

Whether you’re a frontend developer, lead, or manager, reconsider your expectations and practices if you haven’t yet chosen not to ship erroneous HTML. The <a href="https://meiert.com/en/blog/commit-to-conformance/">more of us</a> decide to talk about using actual HTML on our sites and in our apps, and lead by example, the better for our users and clients, and the better for our craft and profession. On the engineering side of web development, it’s <strong>HTML first</strong>—<a href="https://validator.w3.org/">if it is HTML</a>.
Thợ-code hàng real khác thợ-chém như thế nào?
Tags: quoratrans
Published: 2024-05-28 14:24:45

Thợ-code hàng real khác thợ-chém như thế nào? 
Trả lời bởi Alan Mellor, bán code kiếm cơm từ 1981. 
Thợ code hàng real thực-sự-code. Thợ code hàng fake không-code. 
Tôi: anh đã build sản phẩm gì?
Thợ-chém: tôi đã hoàn thành 62.7% ở EE-ZEE-LURN Bootcamp academy online, và tui thành thạo Java, Swift, Mobile Development, websites. 
Tôi: "thành thạo" nghe hấp dẫn đấy, vậy anh đã làm được dự án nào với java? cho tui xin 1 cái tên. 
Thợ-chém: ...
Vậy là xong. 
Một người trở thành kỹ sư phần mềm giỏi, bởi vì anh ta code, anh ta tạo ra các phần mềm (*), và anh ta muốn làm điều đó. 
Chém-er thì không không hứng thú với việc xây dựng các phần mềm. Vậy nên họ chém, và không có output gì. 
Chân thành mà nói, chém-er cũng không phải là quá tệ. nhưng Software Developer thì phải develop software thôi. 
Trans note: 
- Vì đồng tình với tác giả, nên mỗi khi đi dạy, mình luôn động viên sinh viên làm thật, ra sản phẩm thật, để đi "khoe" mỗi khi ứng tuyển. 
- Và hồi tuyển ~cậu~ à nhầm thằng bạn vàng Nguyễn Tiến Hoàng mình accept luôn sau khi nhìn thấy sản phẩm trong laptop của nó. 
- Chém-er cũng không phải vấn đề, ngành công nghiệp phần mềm, có rất nhiều vị trí không-cần-code-chỉ-cần-chém, nhưng phải cân nhắc xem là bạn bạn đang tuyển người vào để làm gì. Tuyển coder đi chém và tuyển chém-er đi code thì chỉ ra thảm họa, 
còn tuyển được chém-er đi chém thì vẫn rất ngon, 
còn tuyển 1 ông vừa code ngon vừa chém ngon như ông Viet Cv thì tiền đâu trả cho nổi, mà những người như ổng thì bận startup cái business của ổng rồi.
Tôi cần show cái gì trong CV để kiếm được 1 công việc (Java)
Tags: quoratrans
Published: 2024-05-28 14:22:04

## Tôi cần show cái gì trong CV để kiếm được 1 công việc (Java) 
// vì có quá nhiều thuật ngữ nên về cơ bản mấy cái tui để giữa cặp nháy thì mọi người chịu khó Google nhé! 
Với tư cách là người tuyển dụng, tui muốn xem 
- Clean code, cách đặt tên code trong sáng, `SOLID`, `Lambdas` (liên hệ anh Google để biết về SOLID và Lambda trong lập trình)
- Bạn có áp dụng good/best pratices cho `REST` (best practice = các kinh nghiệm hay trong lập trình, liên hệ anh Google để biết về REST), `repositories` (lại liên hệ anh Gồ để biết về `repositories`, hoặc cụ thể hơn là `Spring Rest Respositories`) và mấy thứ liên quan 
- Có sử dụng `build script`, `maven/gradle` để thực hiện `CI` (ờ, nếu chưa biết mấy cái build script, maven/gradle, CI thì lại hỏi anh Gồ đi)
- `Unit test`, test tích hợp (`Integration Test`), kiểm thử trực quan (end to end testing) được sử dụng phù hợp  
- `Logging` phù hợp 
- Quản lý lỗi (`exception/error`) 
- Có sự suy nghĩ về khả năng mở rộng (`scalability`) 
Bất kể dự án gì, miễn dự án đó được làm tốt, sử dụng development good practice.
Quan trọng là trưng ra được bạn nghĩ công việc nên được hoàn thành như thế nào. 
Lời bình hồi 2020: 
Dịch thì thế thôi, chứ lương < 10M thì hồi 2017 tuyển mãi có mỗi thằng Hoàng nó mang code theo, sau đó thêm Tài thì nó làm được bài logic lập trình căn bản, sau đó may thay anh Tiến ảnh vớt được ku Nam làm được việc, chứ giờ ném 3 cục đá thì 2 cục trúng 2 thằng dev đi lang thang, cơ mà code thì như cái cục chất thải 😂

Lời bình 2024: 
hôm vừa rồi phỏng vấn Senior java, đã code java được 5 năm, nhưng quá nửa đống này chưa làm bao giờ :(
10 Lesser Known Git Commands and Techniques You Should Know
Tags: git, versioncontrol, advancedgit, devtools
Published: 2024-05-28 14:17:22

Git is a powerful version control system used by developers worldwide to manage and track changes in their codebases. While most developers are familiar with basic Git commands like `git commit`, `git push`, and `git pull`, there are many advanced commands and techniques that can greatly enhance your workflow and productivity. In this post, we’ll explore 10 lesser-known Git commands and techniques that you probably haven't used yet but can significantly streamline your development process and improve your version control skills. Dive in and discover how these advanced features can help you tackle complex tasks with ease.

1. **git bisect**: This command is used for binary search to find the commit that introduced a bug. Start with `git bisect start`, mark the current commit as bad with `git bisect bad`, and mark a known good commit with `git bisect good [commit]`. Git will then help you find the exact commit that introduced the issue.

2. **git reflog**: This command allows you to view the history of all actions in the local repository, including those that are not part of the commit history, such as resets and rebases. Use `git reflog` to see this history.

3. **git rerere**: This stands for "reuse recorded resolution." It helps to remember how you resolved a conflict and reuses that resolution if the same conflict happens again. Enable it with `git config --global rerere.enabled true`.

4. **git blame -C -C**: This variant of `git blame` tracks moved or copied lines of code across files. The `-C -C` options increase the likelihood of detecting such changes.

5. **git commit --fixup [commit]**: This command marks a commit as a fixup of an existing commit. Later, you can use `git rebase -i --autosquash` to automatically squash the fixup commit into the target commit.

6. **git worktree**: This command allows you to check out multiple branches at once in separate working directories. Use `git worktree add [path] [branch]` to create a new working tree.

7. **git stash push -m [message]**: This command allows you to stash changes with a message. Use `git stash list` to see the list of stashes with their messages.

8. **git cherry-pick -n [commit]**: The `-n` (no-commit) option applies the changes from the commit but does not create a commit. This allows you to make additional changes before committing.

9. **git filter-branch**: This powerful command allows you to rewrite history, such as removing sensitive data or changing author information. Use with caution, as it can rewrite large parts of history.

10. **git clean -fdx**: This command removes all untracked files and directories, including ignored ones. Use it to clean your working directory completely.