teleren/devto huggingface dataset:
Symmetric Difference of Arrays in JavaScript
Tags: javascript, tutorial, discuss, typescript
Published: 2023-02-03 08:38:54

The symmetric difference of two arrays are the elements that are present in either one or the other array, but not in both. This means that an element is present in the first array but not in the second, or vice versa. 

This is useful when you want to compare two arrays and identify the elements that are unique in each array. On the other hand, using one set alone would only remove duplicates, but would not provide information about the unique elements relative to other sets.

Here's an example to illustrate this difference:

```js
const arrayA = [1, 2, 3, 4];
const arrayB = [3, 4, 5, 6];

const union = new Set([...arrayA, ...arrayB]);
console.log(Array.from(union));
// Output: [1, 2, 3, 4, 5, 6]

const symmetricDifference = (arrayA, arrayB) => {
    // ...
};

const difference = symmetricDifference(arrayA, arrayB);
console.log(difference);
// Output: [1, 2, 5, 6]
```

Typically, I would use the [`_.xor()`](https://lodash.com/docs/4.17.15#xor) function from Lodash to create the symmetric difference. It even supports more than two arrays and keeps the original order of the elements. However, if we don't need this additional functionality, we can simply implement this function in plain JavaScript:

```js
const symmetricDifference = (arrayA, arrayB) => {
  const setA = new Set(arrayA);
  const setB = new Set(arrayB);

  const diffA = Array.from(setA).filter(x => !setB.has(x));
  const diffB = Array.from(setB).filter(x => !setA.has(x));

  return [...diffA, ...diffB];
};
```

Interestingly, the plain JavaScript implementation seems to perform much better than Lodash's function on this simple [benchmark](https://jsben.ch/XF08b) of two arrays of 100 random elements each. However, I would imagine that the performance of Lodash's function increases with the number of array elements. Therefore, it might not always make sense to implement the function yourself.
5 Tips for Optimizing Your PHP Code
Tags: beginners, tutorial, php, webdev
Published: 2023-02-03 08:20:42

---
canonical_url: https://baransel.dev/post/php-5-tips-for-optimizing/
---

> [Sign up to my newsletter for more tutorials!](https://baransel.dev/newsletter/).

### 1. Use the Right Data Types

By using the appropriate data types, you can increase the performance of your PHP code. For example, using an integer instead of a string for a number can improve performance and reduce memory usage.

```php
<?php
// Correct Usage
$age = 25;

// Incorrect Usage
$age = "25";
?>
```

### 2. Avoid Using Unnecessary Variables

Minimizing the number of variables in your code can help improve performance. Use variables only when they are necessary, and re-use them when possible.

```php
<?php
// Correct Usage
$result = $a + $b;

// Incorrect Usage
$sum = $a + $b;
$result = $sum;
?>
```

### 3. Use the Right Control Structures

Using the right control structures can simplify your code and improve its performance. For example, using a switch statement instead of multiple if statements can improve readability and efficiency.

```php
<?php
// Correct Usage
switch ($day) {
  case 'Monday':
    echo 'Today is Monday';
    break;
  case 'Tuesday':
    echo 'Today is Tuesday';
    break;
  default:
    echo 'Today is another day';
}

// Incorrect Usage
if ($day == 'Monday') {
  echo 'Today is Monday';
} else if ($day == 'Tuesday') {
  echo 'Today is Tuesday';
} else {
  echo 'Today is another day';
}
?>
```

### 4. Minimize the Use of Regular Expressions

Regular expressions are powerful, but they can also be slow. Minimize their usage by using alternative solutions whenever possible.

```php
<?php
// Correct Usage
$email = filter_var($email, FILTER_VALIDATE_EMAIL);

// Incorrect Usage
$pattern = "/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/";
$email = preg_match($pattern, $email) ? $email : null;
?>
```

### 5. Use Caching

Caching can significantly improve the performance of your PHP code. Store the results of expensive operations in cache so that they can be reused later, instead of being computed every time.

```php
<?php
// Correct Usage
$result = cache_get('expensive_operation_result');

if ($result === false) {
  $result = expensive_operation();
  cache_set('expensive_operation_result', $result);
}

// Incorrect Usage
$result = expensive_operation();
?>
```

By following these tips, you can optimize your PHP code and improve its performance and readability. Implement these best practices in your projects to get the most out of your PHP development.

In my opinion, these tips are not only important for PHP developers, but for all programmers. Whether you are a seasoned programmer or just starting out, these tips can help you write more efficient and readable code. Additionally, following best practices and optimizing your code can also save you time and resources in the long run, making your projects more successful and sustainable.
Book Review: Learn Go with Pocket-Sized Projects
Tags: go, books, beginners
Published: 2023-02-03 08:11:42

In this bonus book review, for the early-access edition of "Learn Go with Pocket-Sized Projects" from the Manning Early Access Program, I explain why I'm excited about the upcoming release of this book.

{% youtube https://youtu.be/txFOGhVJi2A %}
Accessing Symfony security user on the background
Tags: symfony, security, messenger, background
Published: 2023-02-03 08:04:08

In this short post I would like to show how to access symfony logged user in the background. When we want to access user on a [Symfony controller](https://symfony.com/doc/current/controller.html), we can do it easily following this way:

```php
   class MyController extends AbstractController
   {
      #[Route('/my-route', name: 'my_route')]
      public function myAction(): Response
      {
          $user = $this->getUser();
      }
   }
```

This is valid only in real-time where you have access to the request, but you cannot do it, for instance, in a message handler since it runs in the background where there is no access to the request.

So, what we can do to access user in the background?. The solution is to pass the user identifier so it can be accessed in the background and we can load the user. Let's see it with an example using [symfony messenger](https://symfony.com/doc/current/messenger.html):

```php
   class MyMessage
   {
      public function __construct(
         public readonly string $userIdentifier
      ){ }
   }
```
```php
   class MyController extends AbstractController
   {
      #[Route('/my-route', name: 'my_route')]
      public function myAction(): Response
      {
          $this->bus->dispatch(new MyMessage($this->getUser()->getUserIdentifier()));
      }
   }
```

As we can see in the above code block, we've created a message model which accepts user identifier as an argument. The second block dispatches a message to the background passing as an argument the logged user identifier.

Now, we can access it in the message handler and load the user in the way we want like retreiving it from the database, as we can see in the following code block:

```php
   #[AsMessageHandler]
   class MyMessageHandler
   {
      public function __construct(
         private readonly EntityManagerInterface $em
      ){ }

      public function __invoke(MyMessage $message): void
      {
         $this->em->getRepository(User::class)->find($message->userIdentifier);
      }
  }
```

> I've recently published an ebook where i show how to build an operation-oriented api using PHP and Symfony. This book uses a similar way to give to an operation access to the authenticated user. If you want to read it, you can find it [here](https://www.amazon.com/dp/B0D79KGL7P).
MFA vs. SSO: What is the Difference?
Published: 2024-06-22 08:40:52

---
title: MFA vs. SSO: What is the Difference?
published: true
date: 2023-02-03 08:03:58 UTC
tags: 
canonical_url: https://mojoauth.com/blog/mfa-vs-sso
---

Over the years, Multi-factor Authentication (MFA) and Single Sign-on (SSO) have become crucial parts of authentication. MFA ensures the application and data security against various cyber attacks, while SSO ensures a great user experience as users don’t have to create or remember another account password. The articles cover more details on each of these authentication approaches, including: What is Multi-factor Authentication? What is Single Sign-on? MFA vs. SSO: How Do MFA and SSO Work Together?
Cheapest Durable Elasticache Redis
Tags: redis, aws
Published: 2023-02-03 08:02:28

# Cheapest Durable Elasticache

The recommended cheapest Elasticache solution for high availability would be to set up a Redis cluster with **at least 3 cache nodes in different Availability Zones within a single region**. This provides both **high availability and data durability**, as each cache node is its own full cluster, and each node in the cluster is a separate instance running in its own Availability Zone.

Each of the 3 cache nodes in an AWS Elasticache Redis cluster **acts as a full and independent cluster, storing the same data**. This means that all of the cache nodes contain the same data and can be used for both read and write operations.

The cache nodes communicate with each other using a protocol called Redis Cluster, which automatically distributes data across the nodes in the cluster and ensures data consistency and availability. **If one of the cache nodes fails or becomes unavailable, the remaining cache nodes will continue to function and serve client requests.**

## Read Replicas are not needed for durability, just for if you need a read endpoint…

Having a **single cache node and a single read replica** in AWS Elasticache Redis **will not ensure data durability if the write node fails**. In this case, the read replica would not be able to take over as the primary node and continue serving client requests.

# t3 vs t4g
The new T4g instances provide better CPU performance and they are cheaper than T3 and T3a instances. This should be the go-to instance type in this instance family.
Digital Ocean's Failure to Address Abusive Traffic from their Own Network
Tags: cloud, webdev, security, discuss
Published: 2023-02-03 08:01:34

As a user of Digital Ocean's cloud hosting services, I have been deeply disappointed by the company's failure to address abusive traffic originating from their own network, specifically from `AS14061 DIGITALOCEAN-ASN`.

I have regularly encountered malicious crawlers, spammers, and exploit scanners that are clearly operating from Digital Ocean's own network. These malicious actors are causing significant harm to my website and my business, yet Digital Ocean has done little to nothing to address the problem.

One of the main issues is that Digital Ocean's abuse reporting process is woefully inadequate. I have submitted multiple reports of abuse, yet have received little to no response from the company. Even worse, the abuse continues despite my repeated efforts to have it stopped.

This lack of action from Digital Ocean is not only damaging to my business, but it also undermines the trust and confidence of their customers in the company's ability to provide a secure and reliable hosting service.

It is unacceptable for a hosting provider to be indifferent to abuse originating from its own network. Digital Ocean has a responsibility to actively monitor and address any malicious activity on their network, and to take swift action to shut down any abusive actors.

I urge Digital Ocean to take immediate action to address this problem and to improve their abuse reporting process. Until they do so, I cannot continue to trust them as a hosting provider and I will be forced to consider other options.

I hope that by sharing my experience, I can raise awareness of this issue and encourage Digital Ocean to take the necessary steps to address it.

---

> At [ISAB](https://isab.run/?utm_source=dev-to-08cfc3a0), we believe in providing valuable and informative content to help developers and technology enthusiasts grow in their respective fields. That's why we decided to share our latest article with the community on [DEV Community](https://dev.to/), to reach a wider audience and engage with a passionate group of developers and tech enthusiasts.
>
> We would like to invite you to take a look at our website [ISAB News & Updates](https://isab.run/?utm_source=dev-to-08cfc3a0) for more content like this. [Our platform](https://isab.run/paste/?utm_source=dev-to-08cfc3a0) is dedicated to providing the latest and greatest in technology, coding, and software development. Our goal is to provide a space for learning, growth, and inspiration for all those who visit us.
>
> Whether you're just starting out or a seasoned veteran in the tech industry, we believe there's always room for growth and learning. With that in mind, we invite you to visit our website and see for yourself what we have to offer.
>
> Thank you for taking the time to read this article, and we hope to see you soon at [ISAB](https://isab.run/?utm_source=dev-to-08cfc3a0)!
A Quick 10-Second Programming Joke For Today
Tags: jokes, dailydeveloperjokes
Published: 2023-02-03 08:00:13

---
title: "A Quick 10-Second Programming Joke For Today"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
published: true
tags: #jokes, #dailydeveloperjokes
---

Hi there! Here's today's Daily Developer Joke. We hope you enjoy it; it's a good one.

![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e12596bcfd66.png)

---

For more jokes, and to submit your own joke to get featured, check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/). We're also open sourced, so feel free to view [our GitHub Profile](https://github.com/dailydeveloperjokes).

### Leave this post a ❤️ if you liked today's joke, and stay tuned for tomorrow's joke too!

_This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit._

<!--
Joke text:
___Q:___ What was Grace Hopper's favorite car?

___A:___ VW Bug
 -->
forkJoin deprecated in RxJS v8
Tags: angular, javascript, webdev
Published: 2023-02-03 07:46:14

This is just a little warning for all developers using `forkJoin`, not a post about how to use it.
If you are looking for a coding example explaining how to use `forkJoin` read [How To Use ForkJoin - Angular Example (free article)](https://medium.com/gitconnected/how-to-use-forkjoin-angular-example-fadfe00d71cf).

## Deprecation warning

In many examples, you will see syntax like the following.

```
forkJoin(
  of(1, 2),
  of(A, B),
)
```
The code will work but the problem is that the syntax is deprecated and won't work in RxJS v8.

As reported in the [documentation](https://rxjs.dev/deprecations/array-argument), passing Observables directly as parameters is deprecated.
This is called rest-parameter signature and it will be removed in RxJS v8.

RxJS suggests passing an array of sources, as below.
```
const sources = [of(1, 2), of(A, B)]
forkJoin(sources)
```
You can find a more realistic example in [How To Use ForkJoin - Angular Example (free article)](https://medium.com/gitconnected/how-to-use-forkjoin-angular-example-fadfe00d71cf), but here is a preview:

```
sources = [
    this.http.get('https://.../users/1'),
    this.http.get('https://.../users/2'),
    this.http.get('https://.../users/3'),
  ];

  constructor(private http: HttpClient) {}

  ngOnInit() {
    forkJoin(this.sources).subscribe(console.log);
  }

```
and a link to [StackBlitz](https://stackblitz.com/edit/angular-forkjoin-medium?file=src/main.ts).

### Good To Know

If you work with RxJS and you don't know the RxJS [Operator Decision Tree](https://rxjs.dev/operator-decision-tree), you should check it out. It will help you find or select the best operator for your needs.


![RxJS Operator Decision Tree](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/13djtv556incm6uwb7lu.png)
custom model data
Tags: minecraft
Published: 2023-02-03 07:33:35


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9iz8zgqp396on27qpb42.png)
custom model data is not working in my server, idk why but i dont remember configuring something related to it to disable it, anyone knows how to fix it?

List of plugins in case sone of them disabled it:
AdvancedPets, AdvanceParticle, AirdropX, AntiPopup, AuctionHouse, BetterRTP, BountyHunters, ChatBrawl, ChestShop, ChunkSpawnerLimiter, Citizens, CMILib, CoreProtect, CrackShot, CrackShotPlus, CraftingStore, CrazyCrates, DecentHolograms, DeluxeMenus, dynmap, Dynmap-Towny, Essentials, EssentialsSpawn, ExecutableItems, GlowAPI, Infiniteannouncements, InfiniteVouchers, InventoryRollbackPlus, Jobs, LoneLibs, LuckPerms, MarriageMaster, mcMMO, Multiverse-Core, NBTAPI, PacketListenerApi, PinataParty, PlaceholderAPI, Plan, PlotSquared, ProtocolLib, PvPManager, RealScoreboard, ResourceWorld, SCore, ShopGUIPlus, SilkSpawners_v2, SimpleSit*, spark, SuperVanish, TAB, TDRPlaytime*, Towny, TownyChat, TradeSystem, Vault, Vehicles, ViaVersion, Votifier, Vulcan, WorldBorder, WorldEdit, WorldGuard

thanks in advance
8 Must-Know Rules for Writing Clean Code
Tags: webdev, javascript, beginners, programming
Published: 2023-02-03 06:37:06


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1v5n12dnafs0mszm51rf.jpg)

Writing clean code is a vital aspect of software development. It not only makes the code more readable, maintainable, and easier to debug, but it also ensures the longevity of the software. Here are 8 must-know rules for writing clean code:

Use Meaningful Names: Choose descriptive and concise names for variables, functions, and classes. This helps in better understanding the purpose of the code.

Write Simple Code: Keep the code as simple as possible, avoiding complex expressions and convoluted control structures.

Keep the Code Short: Short functions are easier to understand and maintain. If a function becomes too long, it is a sign that it should be broken down into smaller, more manageable functions.

Use Comments: Comments help explain the purpose and reasoning behind the code, making it easier for others to understand and maintain. However, keep the comments brief and relevant.

Consistent Indentation and Spacing: Consistent indentation and spacing helps to clearly separate the different parts of the code, making it easier to read.

Follow a Standard Coding Style: Adhere to a well-established coding style such as PEP 8 (Python), JSLint (JavaScript), or Google’s R style guide (R). This makes the code more readable and easier to maintain.

Avoid Magic Numbers: Magic numbers are unnamed, hardcoded values in the code. Instead, use constants or enumerations to represent these values, making the code more readable and maintainable like [Mynordstrom Login](https://mynstromy.com/).

Test the Code: Test the code thoroughly to ensure it is working as expected. This helps identify and fix any bugs early on, making the code more reliable and maintainable.

By following these 8 rules, developers can write clean, readable, and maintainable code that will stand the test of time.
create a window in SDL2 for any OS
Published: 2023-02-03 07:30:33

**step 1**
first we need to import SDL2 into our `main.c` project. However there are different library's for every OS so we can allow the computer to choose the needed one by doing this:

```rust
#include <stdio.h> /* printf and fprintf */
#include <stdbool.h>
#ifdef _WIN32
#include <SDL/SDL.h> /* Windows-specific SDL2 library */
#else
#include <SDL2/SDL.h> /* macOS- and GNU/Linux-specific */
#endif
```

**step 2**
to make the window with a title and window size we can do:

```c
int main() {
    SDL_Init(SDL_INIT_VIDEO);

    SDL_Window* w = SDL_CreateWindow(
        /* If you flip this, SDL_SetWindowTitle() below starts working */
        #if 1
        "hello window!",
        #else
        "hello window!",
        #endif
        SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
        400, 400, 0); // window size

    /* If you call this, the below stops working */
    //SDL_SetWindowTitle(w, "Another title without UTF-8");

    /* This works only if the previously set title had an em-dash as well */
    SDL_SetWindowTitle(w, "hello window!"); //title

    SDL_Event event;
    while(SDL_WaitEvent(&event))
        if(event.type == SDL_QUIT) break;

    SDL_DestroyWindow(w);
    SDL_Quit();
}
```
this sets the window size and title.

**step3**
to compile our `main.c` file with g++ we can do:
```bash
g++ -o main main.c -lSDL2
```
and run it with:
```c
./main
```

**step4**
enjoy and have a good day
SharePoint List Advanced Formatting - What classes and icons can we use?
Tags: sharepoint, sharepointonline
Published: 2023-02-03 06:46:48

One of the common attributes when formatting SharePoint lists are **classes** and **icons**. It can get confusing to know what are the actual values that are available to use, as the [official documentation](https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting) does not list this down.

Below is some guidance which will hopefully help.

#Class

### How to use?

> Attribute: "class"

### Example

```
  "attributes": {
        "class": "sp-field-severity--warning"
  }
```
![Class example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ubb64ryez2slcnt4mlgk.png)

### Class Source
https://pnp.github.io/List-Formatting/groupings/classes/sp-field/

<p>&nbsp;</p>


#Icons

### How to use?

> Attribute: iconName


### Example

```
"attributes": {
        "iconName": "CheckMark"
      }
```

In this example `CheckMark` is the name of the icon being used.
Note that the icon value is <u>not case-sensitive</u>, hence a lower-cased'checkmark' will still work.

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



### Icon Source

https://developer.microsoft.com/en-us/fluentui#/styles/web/icons

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