teleren/devto huggingface dataset:
Rescue exception in Ruby and continue
Tags: ruby
Published: 2023-05-18 09:24:30

Usually when we run scheduled jobs we like to bunch a few things together for convenience. Let's say that you have hourly, daily, weekly, monthly task list that needs to be executed. And that you use cron to execute those tasks. A good approach here would be to have those same cron tasks defined in crontab, one entry for each task. However we rarely do that because we have multiple tasks that can run _together_ at the same time so we define a method that will run them one after another. 
The thing we usually forget is that one of those methods, usually not the last one, will raise an exception and prevent the other methods from running. Something like:

```ruby
def run_hourly
  update_counters
  send_emails
  sync_logs
end
```

Now imagine that the `update_counters` method fails and no emails get sent and the logs aren't synced (whatever that means). We don't want that situation to happen, but we also don't want to blindly ignore exceptions doing something like this:
```ruby
def run_hourly
  update_counters rescue nil
  send_emails rescue nil
  sync_logs
end
```
Of course we have linters and tools to warn us that this is bad practice, but we are trying to ship the product and it's late Friday afternoon just before the big trip. A more sane solution would be to run those methods, catch any exceptions that occur and then continue.

You could define every method with a rescue clause:

```ruby
def update_counters
rescue StandardError => e
  ErrorService.process(e)
end
```

But if you want to avoid repeating code and just implement the rescue once, you can define a exception catching block method:

```ruby
def handle_exception(&block)
  block.call
rescue StandardError => e
  ErrorService.process(e)
end
```

This way we can rewrite the example above to be more concise, catch any exceptions that occur and run all _good_ methods.

```ruby
def run_hourly
  handle_exception { update_counters }
  handle_exception { send_emails }
  handle_exception { sync_logs }
end
```

If you encounter this problem in other places in the code, it's always easy to extract it into a module and then include that module anywhere else in the code where you need the functionality.
How to Perform Selection in .NET MAUI DataGrid
Tags: dotnet, dotnetmaui, csharp
Published: 2023-05-18 09:23:10

Learn how to perform selection in the Syncfusion .NET MAUI DataGrid control easily. This video teaches enabling and disabling selection, clearing selection, and programmatic selection. It also shows how to customize the appearance of selected rows and the current cell focus border. 

The .NET MAUI DataGrid control is a UI component that displays tabular data in a grid. Users can interact with data by sorting, filtering, selecting, and editing it. The DataGrid control can be used to display data from various data sources, including in-memory collections, databases, web services, and more. 

_Product overview_: https://www.syncfusion.com/maui-controls/maui-datagrid

_Tutorial videos_: https://www.syncfusion.com/tutorial-videos

_Download getting started example from GitHub_: https://github.com/SyncfusionExamples/getting-started-with-the-dotnet-maui-datagrid

{% youtube mN95SPfVcHo %}
26. Remove Duplicates from Sorted Array
Tags: algorithms, java, 100daysofcode, leetcode
Published: 2023-05-18 09:19:07

**Question Statement:**
Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums.

Consider the number of unique elements of nums to be k, to get accepted, you need to do the following things:

Change the array nums such that the first k elements of nums contain the unique elements in the order they were present in nums initially. The remaining elements of nums are not important as well as the size of nums.
Return k.

**Custom Judge:**

The judge will test your solution with the following code:

```
int[] nums = [...]; // Input array
int[] expectedNums = [...]; // The expected answer with correct length

int k = removeDuplicates(nums); // Calls your implementation

assert k == expectedNums.length;
for (int i = 0; i < k; i++) {
    assert nums[i] == expectedNums[i];
}
```
If all assertions pass, then your solution will be accepted.

 
**Example 1:**
**Input:** nums = [1,1,2]
**Output:** 2, nums = [1,2,_]
**Explanation:** Your function should return k = 2, with the first two elements of nums being 1 and 2 respectively.
It does not matter what you leave beyond the returned k (hence they are underscores).

**Example 2:**
**Input:** nums = [0,0,1,1,1,2,2,3,3,4]
**Output:** 5, nums = [0,1,2,3,4,_,_,_,_,_]
**Explanation:** Your function should return k = 5, with the first five elements of nums being 0, 1, 2, 3, and 4 respectively.
It does not matter what you leave beyond the returned k (hence they are underscores).
 

**Constraints:**
- 1 <= nums.length <= 3 * 104
- -100 <= nums[i] <= 100
- nums is sorted in non-decreasing order.

Solution:

```
class Solution {
    public int removeDuplicates(int[] nums) {
int i=0;
        for(int j=1;j<nums.length;j++){
            if(nums[i]!=nums[j]){
                i++;
                nums[i]=nums[j];
            }    
        }

        return i+1;
    }
}
```
How to solve white space in Azure DevOps pull requests
Tags: azure, azuredevops, azuregit, github
Published: 2023-05-18 09:11:39

To solve whitespace issues in Azure DevOps pull requests, you can follow these steps:

- 
Identify the whitespace-related problem: Review the pull request and determine whether the issue is related to leading/trailing whitespace, inconsistent indentation, or any other specific whitespace problem.

- 
Discuss with the team: Engage in a conversation with the team members involved in the pull request. Ensure that everyone understands the whitespace standards and conventions that should be followed.

- 
Use a code editor with whitespace support: Utilize a code editor that provides whitespace support, such as Visual Studio Code. These editors can highlight and visualize whitespace characters, making it easier to identify and fix issues.

- 
Configure editor settings: Ensure that your code editor is properly configured to handle whitespace-related issues. Set the editor to automatically trim trailing whitespace, enforce consistent indentation, and display whitespace characters.

- 
Address leading/trailing whitespace: Remove any unnecessary leading or trailing whitespace in your code files. This can be done manually by deleting the extra spaces or by using editor functionalities to automate the process.

- 
Standardize indentation: Ensure that the code indentation follows a consistent style throughout the files. Adjust the indentation of code blocks, lines, or elements to match the established standards.

- 
Apply automated formatting: Utilize code formatting tools or linters to automatically fix whitespace-related issues. These tools can enforce consistent whitespace, indentation, and code style across the project.

- 
Rebase or merge with whitespace fixes: If whitespace changes are required, make the necessary adjustments in a separate branch or commit. Once the whitespace issues are resolved, rebase or merge the changes into the target branch.

- 
Validate changes: Perform a thorough code review and testing to verify that the whitespace fixes did not introduce any unintended side effects or bugs.

- 
Communicate with the team: Notify the team members involved in the pull request about the whitespace fixes that were applied and provide any necessary explanations or instructions.

- 
If you are using Visual studio 2019 and you other team member is using Visual studio 2022 then due to the different Editors you will face this issue due to different editors.

- 
To solve this issue you can use Notpad++ for file changes and then after all the files changes make the new commit and push the latest changes on Azure Git 

By following these steps, you should be able to address whitespace-related issues in Azure DevOps pull requests effectively.
How to learn way more from coding than ever before
Tags: learning, webdev, programming, productivity
Published: 2023-05-18 09:09:39

### Want to become a superhero programmer?

As a developer, learning is your superpower. It is especially important now that frameworks and new tech emerges every 2 days. The faster you can learn something, the more valuable you will be. So let's look at a couple of tricks I use to help me learn new stuff and not forget what I already learned.

1. Make sure that you understand the concepts
2. Apply what you learned(Practice)
3. Take notes
4. Debug
5. Find a community

## 1. Make sure that you understand the concepts

When learning to code you can't memorize code, I know because I did it for a long time. But memorizing code won't get you far. If you actually want to learn something, make sure you understand the working of it. But not just what it does but why it does it too.
For example: Take an "if...else" statement or a logical operator like "&&". Besides understanding what it does when you use it in your code, you should look a little deeper and understand why it does that thing.


## 2.Apply what you learned(Practice)

We can all agree, that learning without actually applying the concepts you learned, is just wasting your time. I mean, why did you even learn it if you are not going to apply it in real life? It doesn't make sense.
You need to apply things to avoid eventually forgetting them. When you apply them in practice your brain builds connections. This way you will actually remember those concepts you applied.


## 3. Take notes

I do this when taking courses, or just generally learning new concepts that I didn't know about before. And let me tell you that taking notes, is just as important as watching a course. Because when you take a course writing down a couple of concepts throughout it, after finishing, you will have a summary of it on paper, that you can come back to any time.
This method also helps you to better understand concepts because it forces you to write down concepts in your own words.


## 4. Debug

The majority of programmers HATE debugging(not that I love it). It is a tedious process and sometimes the problem is just a missing semicolon. 
But what I noticed is that when I actually find the bugs in my code and solve them. I remember those problems and the solutions to them way better in the future. This is because I already encountered them before.


## 5. Find a community

Finding and joining a good community can be a little tricky, but it's definitely worth it. In a community, you can share your code and finished projects, and the community would give feedback on it. You also would be able to provide feedback on other people's code.
Be open to feedback, whether it's good or bad because it's all an opportunity to learn something new.

Thanks for reading!
Fuzzing: The State of the Art - FuzzingWeekly CW20
Tags: fuzzing, testing, security, opensource
Published: 2023-05-18 08:29:00

This week’s theme is Back to Basics.

Fuzzing software is not a new technique and dates back to at least 1988, if not earlier. The first fuzzers were based on randomly or pseudo-randomly generated inputs to find bugs in a piece of software. Fuzzers have grown in sophistication over the years, incorporating artificial intelligence, among other things.  Since then, fuzzing has become an important tool in software security and testing and an interesting technique to study in computer science. Let’s take a look at some of the basic ideas.


And for your enjoyment, here’s a fuzzy scarf (work in progress):

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

## This week's articles:

Fuzzing: The State of the Art - https://apps.dtic.mil/sti/pdfs/ADA558209.pdf

What is Fuzz Testing? - https://www.code-intelligence.com/what-is-fuzz-testing

Fuzzing 101: Tools and Exercises - https://github.com/antonio-morales/Fuzzing101


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lvc01exkwy74w58bxu9t.png)
https://www.fuzztesting.io/fuzzing-weekly
How to Add a Free Shipping Bar to Magento 2
Tags: magento, magento2, magento2tutorial
Published: 2023-05-18 08:56:47

The term FREE has a positive influence on customers' shopping behavior. Incorporating free shipping as part of your brand's marketing strategy can prove to be an effective approach. Discover in this blog post how you can easily **_add a free shipping bar to Magento 2_**.

When comparing a product priced at $110 with free shipping to another priced at $100 with an additional $10 for shipping, the former appears to be a more attractive deal. Research also indicates that customers often abandon their shopping carts due to high extra costs like shipping and taxes. By prominently featuring a free shipping bar on your website, you can increase your profitability.

Moreover, implementing cart value thresholds, where customers receive free shipping once they reach a certain cart value, can significantly boost the average order value.

In this comprehensive blog post, I will provide a step-by-step guide on how to successfully implement the free shipping bar functionality within Magento 2.

For more information , please visit this :- **_[https://meetanshi.com/blog/add-a-free-shipping-bar-to-magento-2/](https://meetanshi.com/blog/add-a-free-shipping-bar-to-magento-2/)_**
A journey into Java: Syntax, Data Types, and Type Casting
Tags: webdev, java, programming, learning
Published: 2023-05-18 08:28:57

Welcome to my blog, fellow developers! Today, we'll embark on a journey into Java programming. Whether you're an advanced developer or a beginner in programming, this article will lay a solid foundation for your Java knowledge. So, let's dive in!

Today, I learned about the basics of the Java programming language, and I will outline the key lessons and implementations of what I learned. We'll discuss:
- Java Syntax

- Data types

- Variables

- Type Casting

1. **Java Syntax**- Every programming language has its unique syntax, and Java is no exception. Understanding the syntax of any programming language is crucial, as it allows us to write code that a computer can understand. In Java, all the code is written inside a class, like `class HelloWorld {}`. The entry point of the code is `public static void main(String[] args) {}`. When you run the program, the code inside the main method will be executed. For example, let's print "Hello world":

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

_(We use `System.out.println()` method to print anything to the console.)_

2. **Data Types** - In Java, there are two types of data types: - **primitive**
       - **non-primitive**
**Primitive** data types are those defined in Java such us `int, String, boolean, float, double`. 
**Non-primitive** data types are those that the programmer defines such as `Arrays, objects, classes, methods`.

3. **Variables** - A variable is memory allocation. In other words,storing data in the memory. Here are examples of how to declare a variable in Java:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xgx9ad2wz1eqy9q7pr8.png)
The output will be 

```
Good Morning
1977
3.14
5.727
```

3. **Type Casting** - This is the changing of the value of a variable from one data type to another. i.e changing from an `int` to a `double` or vice versa. Here's an example of converting an `int` to a `double`:

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


_Outputs: 
502
502.0_

Example of converting a `double` to an integer `int`:

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

_Outputs: 
502.77
502_

This is what I managed to grasp on day 1 of learning Java. More will be covered in the next article. I would greatly appreciate your feedback and suggestions regarding this article. If you notice any errors or have any recommendations for improvement, please feel free to share them below. Your input is invaluable in helping me provide accurate and engaging content.

Thank you in advance for taking the time to review the article. I look forward to hearing your thoughts!



[connect with me](https://www.linkedin.com/in/luqman-shaban/)
1752. Check if Array Is Sorted and Rotated
Tags: algorithms, java
Published: 2023-05-18 08:27:50

Given an array nums, return true if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero). Otherwise, return false.

There may be duplicates in the original array.

Note: An array A rotated by x positions results in an array B of the same length such that A[i] == B[(i+x) % A.length], where % is the modulo operation.

**Example 1:**
**Input:** nums = [3,4,5,1,2]
**Output:** true
**Explanation:** [1,2,3,4,5] is the original sorted array.
You can rotate the array by x = 3 positions to begin on the the element of value 3: [3,4,5,1,2].

**Example 2:**
**Input:** nums = [2,1,3,4]
**Output:** false
**Explanation:** There is no sorted array once rotated that can make nums.

**Example 3:**
**Input:** nums = [1,2,3]
**Output:** true
**Explanation:** [1,2,3] is the original sorted array.
You can rotate the array by x = 0 positions (i.e. no rotation) to make nums.
 

**Constraints:**

- 1 <= nums.length <= 100
- 1 <= nums[i] <= 100

**Solution:**

```
class Solution {
    public boolean check(int[] n) {
        int l= n.length; // Calculating length of given array.
        int nRotation=0;// Declaring a variable to keep a count of number of rotations.
//Running a for loop to identify any rotation in given array.
        for(int i=0;i<l;i++){
            if(n[i]>n[(i+1)%l]){
                nRotation++;
            }
        }
//If number of rotations are greater than 1 return false.
        if(nRotation>1)
            return false;
//Else return True.
        return true;

    }
}
```
Containerising a fullstack Nodejs + mssql app and running it locally.
Tags: docker, devops, containers, azure
Published: 2023-05-18 08:20:30

In the she code Africa Cloud School program,
We recently learnt about Containerisation and how important it is in the software development lifecycle, especially in regards to environment related errors such as various versions of runtimes installed on machines.


So i decided why not make an image out of my full stack web application and push the image to the registry then later deploy the app.

For starters i know that i have to define a Dockerfile that defines the environment my app should run in.

Inside the docker file, we add 
- the runtime which will be nodejs 16 though we can use a lightweight image which is lts-alpine.

```
FROM node:lts-alpine

```
- then create a working directory to store our app in the image.

```
WORKDIR /usr/src/app
```
- next we copy our package.json file into that working directory

```
COPY package*.json ./
```
- then we install the dependencies using the RUN command

```
RUN npm install
```
- we can now copy the application code into the directory

```
COPY . .
```
- Then we can now expose the port on our container that will allow us to connect to the web app.

```
EXPOSE 3000
```
- Then to build the application

```
npx tsc
```

- Finally, we set the command to run the application.

```
CMD [ "node", "start" ]
```


![dockerising](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1aaweh1zlr11ogcq8dlx.png)


Next we create a dockerignore file to prevent copying some resources into our application such as node_modules.

![docker ignore](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b947twm1ccktzetr0wsq.png)

Now its time to build our image usign docker build with an image name as mssql_nodejs_app

```
docker build . -t node_mssql
```
Building....

![build](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dka6q1pt96q314b55ye7.png)



Once the build finishes, to see our image we use  

```
docker images
```

![docker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/okdr5ot079kk49ddmlql.png)

To run the application locally,

```
docker run -d -p 3000:3000 node_mssql
```
the -d represents running it in background and prints container id
the -p represents the port number the container exposes to localhost in this case port 3000 (the second)on container is bound to port 3000(the first) on local host.
![binding](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gqi8ejdr0svwoxmj9jsi.png)

After this our app should be visible on localhost 3000

![run](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5pkktycd1zz1zq8l4gt4.png)

So after building this container image, i am now thinking of pushing it to the container registry in azure and create an app service with it.

Super excited!!!!!!!!!!!!!!!!!
App Development Company In Gurgaon
Tags: webdev, digital, appdevelopment, javascript
Published: 2023-05-18 07:48:55

Good day, everyone! I'm adina here. I am talking about [App Development company](https://www.cutedgetechnology.com/app-development-company-in-gurgaon.php) in gurgaon. Cut edge technology is best Android and Ios app development company that provides a full range of services. They are specializes in creating unique mobile apps for Android and iOS platforms no matter how small or big your business is. We work for companies of all sizes.
Liman Cihaz Yönetim ile Zaman Sunucusu Ayarları
Published: 2023-05-18 07:46:47

- Liman arayüzü açılır.
- Menüye girilir.
- Menüde sunucunun alt başlıklarında bulunan <u>Cihaz Yöneticisi</u> eklentisinin içine girilir.
- İlgili makineye sağ tıklanır ve **Ağ** sekmesine tıklanır.
- NTP Adresi kısmına hatalı bir NTP adresi girildiğinde ve kaydet butonuna tıklandığında (null) dönecektir. (ÖR: hatali.ntp.adresi girildiğinde) Ancak, bu adres doğru bir NTP sunucusu olmadığı için zaman senkronizasyonu gerçekleştiremeyecektir.


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




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

- NTP Adresi kısmına geçerli bir adres girilirse ve kaydet butonuna tıklanırsa adres havuzundaki bir sunucuyu temsil eden IP adresi çıkacaktır. (ÖR: pool.ntp.org girildiğinde pool.ntp.org havuzundaki bir sunucuyu temsil eden 162.159.200.1 IP adresi görüntülenecektir.)


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



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

**:bangbang:** Dolayısıyla, 162.159.200.1 IP adresi, pool.ntp.org havuzundaki bir sunucuyu temsil eder ve doğru ve güvenilir zaman bilgileri sağlamak için kullanılabilir. Ancak, belirtmek gerekir ki, pool.ntp.org havuzunda bulunan IP adresleri zaman içinde değişebilir ve farklı sunuculara yönlendirilebilir. Bu nedenle, zaman senkronizasyonu sağlamak için genellikle pool.ntp.org alan adını kullanmak daha uygundur, çünkü bu, güncel ve doğru NTP sunucusuna yönlendirme yapacaktır.
User Driven UI
Tags: ux, webdev, frontend, ui
Published: 2023-05-18 07:41:52

We use software to solve a problem. When someone chooses a new software product. Instead of solving their problem, we give them another. To learn the UI (User Interface). If the software is at a certain level of complexity, new users will only learn parts of it or not use it at all. 

With the capabilities of natural language processors, we can create a new approach to teaching UIs. User-driven UI. Instead of pushing features onto the user, the user pulls them in when needed. 

For details, see https://garden.bradwoods.io/notes/design/user-driven-ui