teleren/devto huggingface dataset:
ASP.NET Core - Policy-Based Authorization for Fine-Grained Access Control
Tags: aspdotnet, webdev, programming, tutorial
Published: 2023-11-23 15:30:00

ASP.NET Core provides a powerful feature called policy-based authorization, which allows you to define fine-grained access control rules for your application. Instead of hardcoding authorization checks throughout your code, you can centralize them in policy definitions.

To implement policy-based authorization:

- **Define Policies**: In your Startup.cs file or a separate authorization configuration file, define policies using the `services.AddAuthorization()` method. For example:

   ```csharp
   services.AddAuthorization(options =>
   {
       options.AddPolicy("RequireAdminRole", policy =>
           policy.RequireRole("Admin"));
       options.AddPolicy("RequireMinimumAge", policy =>
           policy.Requirements.Add(new MinimumAgeRequirement(18)));
   });
   ```

- **Create Policy Requirements**: Create custom policy requirement classes that implement the `IAuthorizationRequirement` interface. In the example above, we have a custom requirement called `MinimumAgeRequirement`.

- **Use Policies**: Apply policies to your controllers or action methods using the `[Authorize]` attribute and specifying the policy name. For example:

   ```csharp
   [Authorize(Policy = "RequireAdminRole")]
   public IActionResult AdminDashboard()
   {
       // This action can only be accessed by users with the "Admin" role.
       // ...
   }
   ```

- **Handle Authorization Failures**: If a user doesn't meet the policy requirements, ASP.NET Core will automatically handle authorization failures. You can customize the behavior by implementing an `IAuthorizationHandler`.

Policy-based authorization provides a flexible and maintainable way to control access to your application's resources based on various factors like roles, claims, and custom requirements. It promotes a clean separation of authorization logic from your business logic, making your application more secure and easier to manage.
Optimizing Excalidraw: Simple File Size Reduction Tactics
Tags: javascript, opensource, webdev, programming
Published: 2023-11-23 15:27:47

Excalidraw is a versatile and user-friendly platform for creating diagrams, sketches, and collaborative drawings. As with any software, users and developers are constantly looking for ways to enhance its performance and efficiency. In this post, I'll explore my recent contribution to Excalidraw that addresses a crucial issue and significantly improves the file size of drawings.

## The Issue:

Excalidraw users may have encountered a common concern regarding the size of save files, libraries, and the clipboard. Issue #7169 on the Excalidraw GitHub repository highlights the problem, pointing out that even small drawings could result in file sizes as large as 612K. The issue context notes that, upon inspecting the .excalidraw file with a text editor, the JSON structure is "prettified," contributing to the larger file sizes. The user suggests that minifying the .excalidraw files could save substantial space without sacrificing usability.

## The Contribution:

The proposed solution comes in the form of a modification to the JSON.stringify function, ensuring that the output to the file does not include unnecessary spacing, essentially minifying the JSON. This change results in a notable reduction in file size for save files, libraries, and when copying to the clipboard.

To put this improvement into perspective, a simple test file exhibited a reduction from **31.4kb** to **17.1kb**. User reports indicate that the reduction becomes even more significant as drawings increase in complexity. For instance, the original issue mentioned a file size reduction from 612K to 296K when using the `jq -r tostring` command to minify the `.excalidraw` file. Notably, the minified file still opens seamlessly in the browser.

## Reasons to Merge:

The pull request containing this modification presents compelling reasons to merge the changes into the Excalidraw codebase:

### Reduces Size on Local/Cloud Storage: 
Minifying the `.excalidraw` files leads to a substantial reduction in file size, addressing the concern of large storage requirements. This optimization not only benefits individual users but also contributes to more efficient cloud storage solutions.

### Faster Saving on Slow Connections: 
The reduced file size directly translates to faster saving, especially for users with slower internet connections. This improvement enhances the overall user experience by minimizing the time required to save and load drawings.

## Conclusion:

Excalidraw continues to evolve, thanks to the active contributions of its community. The recent [pull request](https://github.com/excalidraw/excalidraw/pull/7187) to minimize the size of `.excalidraw` files is a example of how user feedback and developer expertise come together to enhance the platform's performance. By addressing the issue of inflated file sizes, Excalidraw becomes an even more efficient and user-friendly tool, catering to the diverse needs of its growing user base.
Decode obfuscated Javascript code with help of ChatGPT
Tags: javascript, html, node, gpt3
Published: 2023-11-23 14:59:56

Back in 2022 Anthony Smith [shared a fun tip](https://dev.to/anthonys1760/obfuscating-javascript-code-with-nodejs-233) about code obfuscation in Javascript. 

## Problem?
Analyzing obfuscated JavaScript code is tough because the code is purposely made confusing to hide its real purpose. This makes it hard to debug, understand, and check for security issues, requiring special tools and methods.

When analyzing obfuscated JavaScript code, try using GPT! Here’s how to do it.

## Quick tip on decoding obfuscate Javascript code using GPT
1. Ask GPT to analyze the code and paste the code after.
2. Then ask to rewrite it for better readability!

## I/O

Here is what I fed to GPT:
```
Please analyze the following code and tell me what it does? 

function _0x33bc(_0x357a49, _0x4d043b) {
    var _0x3af57c = _0x3af5();
    return _0x33bc = function (_0x33bc59, _0x2d7f6b) {
        _0x33bc59 = _0x33bc59 - 0xac;
        var _0x433c74 = _0x3af57c[_0x33bc59];
        return _0x433c74;
    }, _0x33bc(_0x357a49, _0x4d043b);
}
var _0x5b0965 = _0x33bc;

function _0x3af5() {
    var _0x16d4f2 = ['2293120DDXwAC', '5tguhIh', 'ExpressJS', '32097acJbHr', '1234303tDdtZs', 'HTML', '51273EoArEE', 'CSS', 'JavaScript', '3214428qqnLuG', 'MongoDB', '40qdyzEo', 'Smith', '252346qcgJWs', '292cvJCiT', 'Anthony', 'PHP', '2392880xWQHuO',...
```

Then she explained details, but still wasn't clear what this code is supposed to do.

After that I asked for more!.. She flawlessly re-wrote it and turned it into human-readable and friendly source code! Amazing!
```
function generateProgrammingLanguages() {
    return ['HTML', 'CSS', 'JavaScript', 'React', 'NodeJS', 'MongoDB', 'ExpressJS', 'PHP'];
}

function selectLanguage(index) {
    const languages = generateProgrammingLanguages();
    return languages[index];
}

const person = {
    first_name: 'Anthony',
    last_name: 'Smith',
    occupation: 'Full Stack Developer',
    languages: [
        selectLanguage(0),
        selectLanguage(1),
        selectLanguage(2),
        'React',
        selectLanguage(3),
        selectLanguage(4),
        selectLanguage(5),
        selectLanguage(6),
    ]
};
```

Now the response is very close to sample from Anthony's tip. At least, it is much easier to understand what this code is doing. 

How do you de-obfuscate source code? What features of ChatGPT do you use for explaining source code? Answer in comments! 

Thanks for reading.

## Reference
Check out [the full session in ChatGPT](https://chat.openai.com/c/a31c76d9-1fb0-4d3d-8749-9ec847e67233).
TechnBrains: Elevate Your Brand with Premier Mobile App Development
Published: 2023-11-23 14:50:56

Unlock innovation and success with TechnBrains, the leading [Mobile App Development Company](https://www.technbrains.com/services/mobile-app-development/). We specialize in android and iOS app development, ensuring your app thrives in both ecosystems. As your dedicated technology partner, we prioritize user experience, security, and scalability. From ideation to deployment, **choose TechnBrains** for a transformative journey. Whether you're a startup or an enterprise, let's redefine your brand's future together through exceptional Mobile App Development services.
What is the difference between waterfall and agile methodologies in SDLC ?
Published: 2023-11-23 14:46:30

AGILE METHODOLOGIES:

The Agile methodology promotes the continuous interaction of the development and testing during the SDLC process of any project. Unlike the waterfall model, the development and testing activities in the agile model are simultaneous. Agile methodology allows much communication between the customers, developers, testers, and managers.

In the Agile method, the entire project is divided into small incremental builds. All of these builds are provided in iterations, and each iteration lasts from one to three weeks.

1.Agile focuses on customer feedback, collaboration, small and rapid releases.
2.Its purpose is to manage complex projects.
3.The Agile produces better application suites with the desired requirements. Moreover, it can quickly adapt according to the changes made on time during the project life.
4.It has a small team size. Therefore, fewer people work on it so that they can move faster.

Waterfall model:

It is one of the easiest and traditional model to manage. Because of its traditional development nature, each phase has specific deliverables and a review process. The waterfall model works well in smaller size projects where requirements are easily understandable.

The waterfall model is a universally accepted SDLC model. In this method, the whole process of software development is divided into various phases. The development in the waterfall model is seen as flowing steadily downwards (like a waterfall) as it is a continuous software development model. This model is named "Waterfall Model", because its diagrammatic representation resembles a cascade of waterfalls. Some important points related to the waterfall model are listed as follows -

1.Waterfall model is not an ideal model to develop a large scale project size.
2.The requirements in the waterfall model should be clear cut at the beginning time; otherwise, it may lead to a less effective method.
3.In the waterfall model, it is hard to move back in order to make changes in the previous phase.
4.The testing process in the waterfall model starts after the completion of development. So, there is a high chance of bugs to be found later in the project development.
Me and ChatGPT created a Bash script for text-to-speech using OpenAI TTS
Tags: programming, bash, chatgpt, tutorial
Published: 2023-11-23 14:42:15

Hi Dev.to community! 

ChatGPT became an essential helper in writing and analyzing a  code. But this specific case makes ChatGPT incredibly helpful!

If you caught yourself crunching the Bash syntax to make a handy automation on your Linux or Mac, you should hire ChatGPT.

Just look at the output below! I asked GPT to create a text-to-speech Bash script that works similar to `say` command on Linux. It took just a minute to build this useful, flexible and beautiful CLI tool out of an idea.
 
 {% embed https://gist.github.com/vladignatyev/537a26554fd043742defca77c8eeb819 %}

## Quick tip: How to create a Bash/Python/etc. script using ChatGPT
1. Start by asking to create a basic script. Do not provide details on what the script will do. Just tell more about script interface: CLI arguments, parameters, environmental variables etc. 
2. Tell ChatGPT apply necessary modifications and improvements to make this script do the actual workload. Provide sample code and ask to integrate some code pieces found over the web if needed.
3. Well done!

Read the [full story in Medium](https://medium.com/@v_ignatyev/text-to-speech-on-linux-mac-using-bash-made-by-chatgpt-4-570ade59c967).
Resolving Selenium's Zombie Process Issue
Tags: webdev, selenium, python, beginners
Published: 2023-11-23 14:14:17

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

**Introduction**
When working with Selenium in Python, developers often encounter a persistent issue: the generation of zombie processes. These defunct processes can significantly degrade server performance by consuming valuable system resources. This article addresses this common challenge and provides a practical solution.

---

**Understanding the Issue**
- **Zombie Processes**: These are processes that have completed execution but still remain in the process table, typically because their parent process has not yet read their exit status. In a Linux environment, such processes are marked with a 'Z' and can be identified using commands like `ps`.

- **Example Scenario**:
  ```
  root     32358  0.0  0.0      0     0 pts/0    Z    09:36   0:00 [chrome] <defunct>
  ```

---

**Implementing the Solution**
The key to resolving this issue lies in modifying the WebDriver options used by Selenium. Here's a step-by-step guide:

1. **Modifying WebDriver Options**:
   Add the `--no-zygote` argument to the ChromeOptions in Selenium. This prevents the Chrome driver from initiating the Zygote process, which, although generally beneficial for performance and security, can inadvertently lead to zombie processes in certain environments.

   ```python
   from selenium import webdriver

   options = webdriver.ChromeOptions()
   options.add_argument('--no-zygote')
   driver = webdriver.Chrome(options=options)
   ```

---

**Key Considerations**
- **Selective Use**: The `--no-zygote` option should be used judiciously, as it is only necessary in specific environments and scenarios.
- **Troubleshooting**: Before applying this solution, it's advisable to check for other potential causes, like outdated drivers or inefficient coding practices.

---

**Conclusion**
The addition of the `--no-zygote` option in Selenium's ChromeOptions provides a straightforward and effective solution to the zombie process issue on Linux servers. By understanding and implementing this solution, developers can enhance the performance and reliability of their Selenium-based automation scripts.
4twbet
Published: 2023-11-23 12:00:19

4TWBET - Trang chủ chính thức nhà cái 4TW BET 

"4TWBET là một sự lựa chọn hàng đầu dành cho những người chơi VIP tìm kiếm trải nghiệm đỉnh cao trong thế giới trò chơi trực tuyến. Với danh tiếng uy tín và trải nghiệm chất lượng, 4TWBET là nơi mà bạn không nên bỏ qua. Dễ dàng truy cập trang web 4TWBET thông qua liên kết tương ứng và khám phá những trò chơi đa dạng cùng với những cơ hội đầy hấp dẫn để nhận các khoản thưởng hoàn cược. Đặc biệt, 4TWBET đảm bảo sự an toàn và minh bạch, với sự giám sát của PAGCOR, giúp bạn hoàn toàn yên tâm khi tham gia. Hãy đăng ký tài khoản tại 4TWBET ngay hôm nay để trải nghiệm một thế giới giải trí đỉnh cao!"


https://4tw.bet/
https://www.facebook.com/profile.php?id=61553550550556
https://twitter.com/4twbett
https://www.youtube.com/channel/UCoxCgsZJwm1WSm0dMsUW7Tw
https://www.pinterest.com/4twbet1/
https://social.msdn.microsoft.com/Profile/a4twbet
https://bbs.now.qq.com/home.php?mod=space&uid=6175712
https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/648567
https://www.flickr.com/people/4twbet1/
https://www.tumblr.com/4twbet1
https://www.reddit.com/user/4twbett/
https://www.twitch.tv/4twbet1/about
https://medium.com/@4twbet1/about
https://ok.ru/profile/586363147620/statuses/156394637767524
https://profile.hatena.ne.jp/a4twbet1/
https://dribbble.com/4twbet1/about
https://tawk.to/4twbet1
https://www.deviantart.com/4twbet1/about
40. Learning If Else in Python (Day 38)
Published: 2023-11-23 11:33:10

Today's lecture was a full immersion in Python Conditions and If statements. Reminded me of maths in school! In case you forgot, it's these:

\= (equal to), > (greater than), < (less than)
a= b
b< c
c > d

**How the `if` works in Python is:**

```
a = 500 
b = 200 
if a > b: 
   print("a is greater")
```

`Print` is used for giving an output. So, if we run those commands, you will get a result, in this case, "a is greater".

**The `elif`**

This word is a short form for "else if", which basically means - _if a previous condition was false, then try another condition._

```
a = 500 
b = 200 
if a > b: 
   print("a is greater")
elif a = b:
   print("They are equals!")
```

**The `else`**

This one is used if anything is outside of the previous conditions, or if it didn't meet any of the previous conditions.

```
a = 500 
b = 200 
if a > b: 
   print("a is greater")
elif a = b:
   print("They are equals!")
else:
   print("b is greater")
```

**Conclusion**
So far so good. I understand the theory of the above, but I need a lot of practice! I asked the tutor if there were any websites that offer practice challenges and he referred me to the below two:

[Leetcode](https://leetcode.com/)

[Codewars](https://www.codewars.com/)

They look great! This is exactly what I need to sharpen my coding skills and be more confident! I just need to find the time to do them though :( Perhaps, during my Christmas-New Year break coming up!

**Time now** - 10:25 and good night. It's drizzling out there.
Tomoro: Redefining Work with a Three-Day Week and AI Magic
Tags: futureofwork, aiinnovation, workweekrevolution, tomorotech
Published: 2023-11-23 13:48:56

Meet Tomoro: Your Ticket to a Super Cool Three-Day Workweek!

Ever wished your workweek was shorter than the usual 9-to-5 grind? You've probably heard about the four-day workweek, but what if we told you about a startup aiming for something even better? That's Tomoro, a UK-based venture on a mission to make your workweek just three days – and they're adding a dash of AI magic to make it happen.

Imagine having AI "agents" as your personalized helpers, not just handling boring tasks but making decisions on their own within certain limits. Ed Broussard, the brain behind Tomoro and the founder of data and AI consultancy Mudano, dreams of a future where these robot-like helpers team up with real people, learning, adapting, and solving problems. It's not your average automation; it's a whole new way of working together with tech.

But here's the cool part – Tomoro isn't trying to take your job. Their goal is to ramp up your productivity, claiming they can boost efficiency at big companies by an impressive eight times. And guess what? They've teamed up with OpenAI, the genius behind ChatGPT, to make this futuristic dream a reality.

Fresh on the scene and already making waves, Tomoro has landed its first client, the British insurance firm PremFina. Broussard wants you to know AI isn't about taking jobs away; it's about creating a [dynamic partnership](https://www.earwolf.com/episode/how-smart-is-ai-part-two-with-meredith-broussard/) between AI and humans. He envisions a workplace revolution where AI becomes the ultimate productivity sidekick, kind of like the shift from hunting to farming.

In a world where Elon Musk thinks [AI might take over everything](https://fortune.com/2023/11/03/elon-musk-ai-no-job-needed-work/), Broussard sees a different picture – one where AI and humans work together to create a workplace that's not just efficient but seriously awesome. So, get ready for the future of work with Tomoro – because who wouldn't want a super cool three-day workweek, powered by the magic of AI innovation?
Cheers to a future where work feels more like an adventure!
Markov Decision Processes(MDP) basic concept
Tags: ai, machinelearning, reinforcementlearning
Published: 2023-11-23 13:31:46

A Markov decision process (MDP) is a mathematical framework used to model decision-making problems in which outcomes are partly random and partly under the control of a decision-maker. It consists of a set of states, a set of actions, and a set of rewards. The decision-maker takes actions in each state, and the environment transitions to a new state based on the action taken and a probability distribution over the next state. The decision-maker receives a reward based on the state and action taken.

Here’s an example of an MDP:

> Consider a robot that is trying to navigate through a maze. The robot can move in four directions: up, down, left, or right. The robot’s goal is to reach the exit of the maze. The robot’s current state is its current location in the maze. The robot can only see a limited area around it, so it doesn’t have access to the entire maze. The robot’s actions are to move in one of the four directions. The environment transitions to a new state based on the action taken and a probability distribution over the next state. For example, if the robot moves up, there might be a 70% chance that it stays in the same location, a 10% chance that it moves to the left, a 10% chance that it moves to the right, and a 10% chance that it moves down. The robot receives a reward based on the state and action taken. For example, the robot might receive a reward of +10 if it reaches the exit of the maze, a reward of -1 if it bumps into a wall, and a reward of -0.1 for each step it takes.

The environment is typically formulated as a Markov Decision Process

1.) set of states: S
In chess, a state is a given configuration of the board

2.) set of actions: A (for example: up, down, left, right)
Every possible move in chess or tic-tac-toe

3.) Conditional distribution of the next state
The next state depends on the actual one exclusively „Markov-property"
P(s'|s,a) transition probability matrix

4.) R(s,s') the reward function of the next s' state after the agent makes action a while being in the state s

5.) γ gamma discount factor

The Markov property is a fundamental assumption in reinforcement learning. It states that the current state of an agent contains all the information that is relevant for decision-making. In other words, the future state of the agent depends only on its current state and not on its past states. This assumption enables theoretical proofs for certain algorithms and is widely used in current research.

For example, in a Markov decision process (MDP), we assume that the current state is independent of the whole history given the previous state. However, in real-life scenarios, this assumption may not always hold true and can lead to an RL algorithm failing in a specific environment.

Reference:
https://web.stanford.edu/class/cme241/lecture_slides/david_silver_slides/MDP.pdf