teleren/devto huggingface dataset:
PHP foreach() loop for indexed and associative arrays
Tags: tutorial, beginners, programming
Published: 2021-09-21 12:13:43

In this tutorial, we look at the PHP foreach() loop. We also look at how to use it while working with an indexed or associative array.

This tutorial is a part of our initiative at [Flexiple](https://flexiple.com/), to write short curated tutorials around often used or interesting concepts.

### Table of Contents - PHP foreach:
- [What is foreach()?](#what-is-foreach-in-php)
- [Code and Explanation](#code-amp-explanation)
    - Indexed arrays
    - Associative arrays
- [Closing thoughts](#closing-thoughts)

## What is foreach in PHP?
The foreach() method is used to loop through the elements in an indexed or associative array. It can also be used to iterate over objects. This allows you to run blocks of code for each element.

### Syntax of PHP foreach():
The foreach() method has two syntaxes, one for each type of array.

The syntax for indexed arrays is as given in the following code block:
```php
foreach (iterable as $value)
    statement
```
The syntax for associative arrays:
```php
foreach (iterable as $key => $value)
    statement
```
Here, “Iterable” is the required parameter. It is the array or the variable containing the array. “$value” is a variable that stores the current element in each iteration.

Associated array, uses keys and values, and hence the $key & $values in the second syntax represent the same accordingly.

## Code & Explanation:
In this section, we first look at how the foreach() function works on an indexed array followed by which we look at it’s working on an associative array.

### PHP Foreach() on Indexed arrays:
```php
<?php
$flexiple = array("Hire", "top", "freelance", "developers");

foreach ($flexiple as $value) {
  echo "$value <br>";
}
?>
```
The output of the above code snippet would be:
```php
Hire
Top
Freelance
developers
```
PHP Foreach() on an Associative array:
```php
<?php 
$freelancer = array( 
    "name" => "Eric", 
    "email" => "Eric@gmail.com", 
    "age" => 22, 
    "gender" => "male"
); 
  
// Loop through employee array 
foreach($freelancer as $key => $value) { 
    echo $key . ": " . $value . "<br>"; 
} 
?> 
```
The output of the above code snippet would be:
```php
name: Eric
email: Eric@gmail.com
age: 22
gender: male
```
Now let’s look at a case where we pass a second argument. As you can see the key and the values of the associative array were printed. Additionally, we replaced “=>” with a “:” to make it more readable.

## Closing thoughts:
The foreach() method would return an error in case you use it on variables with a different data type. Additionally, the foreach() method does not modify the values of the internal pointer.

Once you have understood the working to the foreach() method try working with the for loop.
Has Reality Punched you in the Nose?
Tags: teamwork, agile, softwaredevelopment
Published: 2021-09-21 12:11:38

---
title: Has Reality Punched you in the Nose?
published: true
date: 2021-09-21 12:08:52 UTC
tags: teamwork,agile,softwaredevelopment
canonical_url: https://medium.com/chingu/has-reality-punched-you-in-the-nose-832f5f169f0d
---

#### Sprint 4 — Tuesday

![](https://cdn-images-1.medium.com/max/1024/1*u0Plfy_NtebaiJxUz_xr6w.jpeg)<figcaption>Photo by <a href="https://unsplash.com/@nm_runners?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Natalie Runnerstrom</a> on <a href="https://unsplash.com/s/photos/boxing?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption>

Something every software project faces is that reality sometimes rears its ugly head and punches you right in the nose!

Every team and every team member have moments of **uncertainty** when their project doesn’t go as planned. This could be the result of a technical problem, a team issue, or the realization that the project is just too complex to complete in the remaining sprints.

> Emotions are part of the human experience, but don’t let them dictate your future

But **_uncertainty doesn’t mean failure is a certainty_**!!! Uncertainty is your signal to pause, evaluate the situation, and adjust your project. This might be as simple as just asking for help on a technical issue, or it may be removing or trimming the number of features in your project backlog so you can complete your MVP (aka _managing scope_).

Emotions are part of the human experience, but don’t let them dictate your future. Take a **_fact-based_** approach to dealing with what reality throws at you to find the best solution with less stress.

![](https://cdn-images-1.medium.com/max/900/1*_N6n0FgISC2prZduuTbVQA.jpeg)

### Before you Go!

Chingu helps you to get out of “_Tutorial Purgatory_” by transforming what you’ve learned into experience. The experience to boost your Developer career and help you get jobs.

You can learn more about **Chingu** & how to join us at [https://chingu.io](https://chingu.io/)

* * *
Discord Servers
Tags: discuss, discord, server
Published: 2021-09-21 11:59:40

I would like to join a challenging Discord server..

Name of a challenging Discord server :-
devchallenges.io..

That website also exist but there is also a server with that name...

Send me the invitation in the comment section of this post...

It would be a great help..

Thanks for reading my post please press the like and the unicorn button while going.
Thank you.
Darsh kulthia.
Configure the Prettier
Tags: prettier, settings, react
Published: 2021-09-21 11:55:20

Here we will install two dependencies to configure Prettier along with ESLint, the [first](https://github.com/prettier/eslint-config-prettier) disables the conflicting rules between Prettier and ESLint and the [second](https://github.com/prettier/eslint-plugin-prettier) transforms Prettier and its settings into ESLint rules, so we can integrate the two, come on:

If you don't have ESLint installed, check out the step-by-step guide [(here)](https://dev.to/edsonjuniornarvaes/eslint-i03).

```bash
yarn add -D prettier eslint-config-prettier eslint-plugin-prettier
```

Now let's update our `.eslintrc` file again, let's leave our keys` extends`, `plugins` and `rules`, in the example below I'll be configuring with react:

```js
extends: [
  "eslint:recommended",
  "prettier/react",
  "airbnb",
  "plugin:react/recommended",
  "plugin:prettier/recommended"
],
plugins: ['react', 'prettier'],
rules: {'prettier/prettier':  'error'}
```

Finally, create a `.prettierrc.json` file and configure it as follows:

```json
{
  "trailingComma": "es5",
  "tabWidth": 2,
  "semi": true,
  "singleQuote": true,
  "jsxSingleQuote": true
}
```
How to make mistakes
Tags: development, leadership, agile, mentor
Published: 2021-09-21 12:58:59

---
title: How to make mistakes
published: true
date: 2021-09-21 11:52:00 UTC
tags: development,leadership,agile,Mentor
canonical_url: https://craignicol.wordpress.com/2021/09/21/how-to-make-mistakes/
series: mentor
cover_image: https://craignicol.files.wordpress.com/2021/01/wp-1609625213249.jpg?w=1200
---

_Nobody is perfect. If you tell me you’ve never made a mistake in your career, not only will I not believe you, I won’t be able to trust you._

In a [safe and functioning team](https://dev.to/craignicol/successful-teams-145c), we can accept our mistakes, discuss them openly, learn the lessons, improve our system, and move on.

Without that, we’re trapped not by our mistakes but by our fear of making them and our fear of the consequences when our mistakes are inevitably surfaced. And “our” mistakes quickly become “your” mistake. Not a failure of the team, not a failure of the system – the processes, the automation, the communication, and the rest – but a fault of the most vulnerable and the most exposed. “It’s always the intern.”

No one makes the intern pilot responsible for a jet plane. They start in small props and in simulators. They are supported and mentored. They are given space to practice, and to fail. Because what really makes the difference isn’t avoiding mistakes, it’s recovering from them.

## Build for failure

Test-first, red-green-refactor: every new feature starts with a failing test which we then fix. Make failures part of the process, small and recoverable. Expected.

Build for backup, rollback, recovery. Test for failure continually. And recover automatically if you can.

## Plan for failure

Be agile. Try new things for a day, or a week, or a year. Decide in advance what success and failure look like and monitor them. Adjust course if things aren’t working. Celebrate what you learn either way..

Move fast and bend stuff, don’t break it. Do and succeed, or do, fail and recover.

The longer a decision takes, and the more you invest in it, the harder it will be to change it, and the bigger a mistake it will become. So make it quick and don’t make it permanent.

## Lead for failure

A leader needs to set a clear direction. To resolve conflicts by stating strong opinions and sticking to them. It makes conflicts easier to resolve. Until those opinions need to change. Maybe the mistake is yours, maybe it’s wrong because other things have moved on. It’s ok to change your mind, so long as you can explain it.

_And then go read about why Cognitive Dissonance makes all of this so hard, by reading [“Mistakes Were Made”](_wp_link_placeholder)_
How I use multiple browsers
Tags: multiple, browsers, chrome, firefox
Published: 2021-09-21 11:43:31

---
title: How I use multiple browsers
published: true
description: Use browsers like a PRO :)
tags: multiple, browsers, chrome, firefox
cover_image: https://raw.githubusercontent.com/raevilman/the-rd-notes/master/notes/me/assets/cover-multiple-browsers.webp
canonical_url: https://www.therdnotes.com/how-i-use-multiple-browsers
---

For instance, on my phone, I have three browsers:

1. Default set to Firefox.

2. Firefox Focus, pinned on right bottom for quick access.

3. Google Chrome, pinned on left bottom for quick access

In the January, I [tweeted](https://twitter.com/raevilman/status/1355399469576056832?s=20) about 'How I use multiple Google Chrome profiles?'

But for past couple of months, I have started using multiple browsers along with multiple Chrome profiles.

---
![YouTube](https://raw.githubusercontent.com/raevilman/the-rd-notes/master/notes/me/assets/youtube.png)
Interested in watching the video version of this thread.
I have upload the vlog on YouTube [here](https://youtu.be/qg7NZWLgL8E). More [verbose] info.

---

So as mentioned above, I use Chrome, Firefox, Firefox Focus on my phone,  
here's how they fit for different purpose.



### The default browser: Firefox.

This comes in situation when I am clicking links in the apps like twitter, email, chats etc.

Because those are random links thus I don't want them to be linked with my Google account, as I am logged into the Chrome, thus separate browser.

So by setting Firefox as default, I am segregating the random links I open via apps, from my Google account, which can result in Google algos recommending useless stuff, which anyways happens but still.

### Temp browser: Firefox Focus

I use it for quick searches, that I don't want to be attached to my profile. 

Eg: 
Searches like ongoing trends, news or sports highlights, this temp browser works well 
and these searches doesn't get attached to my interests in the Google account.

### My online identity: Chrome

Here I am logged into most of my online accounts. 

I open Chrome when I want to access these platforms, which are linked to my Google account. 

Like Twitter, GitHub etc. are all here in Chrome.

---

So that is  it, that's the way how I use browsers for now.
Which has evolved from my last January tweet for sure.

May be more improvements coming in the future 🤷‍♀️  

|  HIH  
|  Take care  
~ @raevilman
React is Declarative - What Does it Mean?
Published: 2021-09-21 11:39:08

It's drilled into you when learning React that it is *declarative*. But what does *declarative* mean, and what is the opposite of *declarative*

---

## Declarative vs Imperative UI

The opposite of *declarative* is *imperative*. These are not React-specific terms. They apply to programming in general.

[StackOverflow - What is the difference between declarative and imperative paradigm in programming?](https://stackoverflow.com/questions/1784664/what-is-the-difference-between-declarative-and-imperative-paradigm-in-programmin)

In terms of web user interfaces:

- **The imperative approach is when you provide step-by-step DOM mutations until you reach desired UI**
- **The declarative approach is when you describe the final state of the desired UI**

---

## Example of declarative vs imperative UI

Let's say we need to build this user interface:

![example1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3999u1bm812ahziuavii.gif) 

### Imperative approach

Here is the imperative solution. For every interaction, we provide step-by-step DOM mutations to reach the desired state of UI. *(The example is slowed down to show how each instruction affects the user interface)*

![example-imperative](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vsmtm96pezlabk4sc0dn.gif)

### Declarative approach

Here is a declarative React solution. We don't provide step-by-step instructions to reach the desired UI. Instead, we describe the final UI we want for each scene. 

![example-declarative](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v26gfs4by3iwyscpr4n9.gif)

We may structure the component differently. It doesn't make it less declarative.

![example-declarative-2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wwfaigwqgwbujfftg1aj.gif)

What makes it declarative is that we describe a final UI for any given state representation. It is the opposite of providing manual DOM mutations to transition between UI states, which would be considered imperative.

---

Originally published at [alexsidorenko.com](https://alexsidorenko.com/blog/react-is-declarative-what-does-it-mean/)
I like the new ios 15 safari
Tags: ios, safari
Published: 2021-09-21 11:38:51

The new ios 15 safari UI seems to be very controversial, the majority of videos on youtube suggest changing it back to older view. They seem to like the way things are and want to stick with them.
I on the other hand love the new UI. I don't care so much about the way it looks and yes there is a learning curve to it. But the additional swipe functionality is definitely worth it.
- Swipe left/right to switch between tabs.
- Swipe up to go to your open tabs.

Using this swipe gestures feels great. Plus to get the added convenience of a reachable address bar which is great. I have  a iphone 11 and average sized fingers and I had to mostly resort to the reachability swipe down shortcut to edit the address bar if i am using a single hand which to be frank is most of the time.
I still think there is a lot that Apple can do to improve safari like adding better PWA support, supporting new APIs so websites look nicer but as far as the new address bar location is concerned, I am very happy with it and feel that its an improvement.
Configure the ESLint
Tags: eslint, settings
Published: 2021-09-21 11:36:19

To start, we must use the following command:

```bash
yarn add eslint -D
```

And then we've already initialized it with:

```bash
npx eslint --init
```

Now that we've started setting up ESLint, the first question concerns how we're going to use ESLint in our system:

```bash
  To check syntax only
  To check syntax and find problems
▸ To check syntax, find problems, and enforce code style
```

Then choose what kind of modules the project uses, in the example I choose the first option _React_:

```bash
? What type of modules does your project use? ...
▸ JavaScript modules (import/export)
  CommonJS (require/exports)
  None of these
```

In the next step, we select which framework we are using, in the example I will follow the previous step _React_:

```bash
? Which framework does your project use? ...
▸ React
  Vue.js
  None of these
```

The next question is about TypeScript, in the example I won't use it, so I selected ** No **:

```bash
? Does your project use TypeScript? » No / Yes
```

In the next step, we must select where our code will run:

```bash
? Where does your code run? ...  (Press <space> to select, <a> to toggle all, <i> to invert selection)
√ Browser
  Node
```

Now we are asked to choose a style to be used in the project, we must choose between an existing one, create a style or use our own, I always choose to use an existing one and choose to use _AirBNB_:

```bash
? How would you like to define a style for your project? ...
▸ Use a popular style guide
  Answer questions about your style
  Inspect your JavaScript file(s)
```

And finally, we chose the format of our configuration file, again a personal choice:

```bash
? What format do you want your config file to be in? ...
▸ JavaScript
  YAML
  JSON
```

Once the settings are complete, ESLint will ask you if you want to install the dependencies using ** npm **, as our project is using ** yarn ** here you have two options:

- select ** Yes **, delete the `package.lock.json` file generated after installation and run` yarn` to install the dependencies into the ` yarn.lock` file
- select ** No **, copy the list of dependencies described and install them using `yarn add ...` (don't forget to add -D if you choose this option)

Now that we have our `.eslintrc` file, we assume the following settings for the configuration made above:

```js
module.exports = {
  env: {
    browser: true,
    es2021: true,
  },
  extends: ['airbnb', 'plugin:react/recommended'],
  parser: 'babel-eslint',
  parserOptions: {
    ecmaFeatures: {
      jsx: true,
    },
    ecmaVersion: 12,
    sourceType: 'module',
  },
  plugins: ['react'],
  rules: {
    'react/jsx-filename-extension': ['warn', { extensions: ['.js', '.jsx'] }],
    'import/prefer-default-export': 'off',
    'jsx-quotes': ['error', 'prefer-single'],
  },
};
```

[Install](https://eslint.org) the ESLint extension for VS Code.
Create custom alias for 127.0.0.1 in Ubuntu
Tags: ubuntu, localhost, linux
Published: 2021-09-21 11:23:55

In some cases developers need some alternates for _localhost_ to access the IP _127.0.0.1_ in our system.

Here we are going to see how to setup alias for IP _127.0.0.1_ in Ubuntu. 

#####Step 1 :

We need to edit _/etc/hosts_ file to add new aliases

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

In hosts file, you can see the _localhost_ configured as alias for _127.0.0.1_ 

![Step 1.1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/279p76y36s1v7b79gy81.png)

#####Step 2 :

Add your alias like below and save it.

![Step 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/um9zwp5c2ln5zg6f41jp.png)

Now localhost, _abc.fake.com_ and _xyz.test.com_ are aliases for IP _127.0.0.1_

**Note :** Browser always search in your local domain registry before reached to DNS server.
Someone could be scraping data from your website - how aware are you?
Tags: security, webdev
Published: 2021-09-21 11:18:42

I’ve been in the business of data extraction and web scraping for more than 10 years now. As the owner of Price2Spy - a price monitoring tool, capable of scraping not only prices but much other information from websites I got complaints and some website owners even threatened me with legal consequences if I don’t stop gathering data from their websites. 

This leads me to my question - how damaging to your business do you find competitors who are scraping data from your website?

I recently started building a new product - BotMeNot - a bot protection score service https://botmenot.com/. Do you think this would be helpful for your anti-bot efforts?
More than a corporate party: How the first Evrone Fest went
Tags: eventdriven, writing, webdev, productivity
Published: 2021-09-21 10:50:49

In 2020, due to the pandemic, Evrone did not get to hold its traditional New Year’s corporate party. For us, as a distributed team, these offline meetings are very important. They allow us to personally meet colleagues who we normally only see as avatars in Slack. So in 2021, we knew we had to do something special, and we did!

[The first Evrone Fest](https://evrone.com/evrone-fest) took place in Moscow in mid-August of 2021. It was attended by our employees from more than 50 cities and European countries, including Germany and Slovenia. Since our team grew significantly in 2020 and the first half of 2021, many people saw their colleagues in-person for the very first time.
Evrone at PyCon 2021: What we talked about, and how we prepared
Tags: python, eventdriven, webdev, programming
Published: 2021-09-21 10:49:49

PyCon is one of the three largest professional Python conferences in Russia. In 2021, it was held on September 5–6 in the Moscow region. Around 500 developers, including those working at Evrone, took part in it.
[Read the full article.](https://evrone.com/pycon)
While selecting text inside a react-rnd, and if selection goes out of the draggable component, the selection changes
Published: 2021-09-21 10:41:39

0


I implemented a draggable textarea using react-rnd by having the textarea component inside of the react-rnd component. Now when I try to select the text inside the textarea by using the cursor and if I accidentally go out of the react-rnd component, the selection changes.

The problem is illustrated in the gif image below. Here, I try to select the text from 'o' and go in the reverse direction and when I go out of the textbox, the selection changes and everything after that 'o' letter is selected. How to retain the original selection 'hello' in this case even when I go out of the react-rnd component.

The problem does not occur if I take the textarea out of the draggable component. I am struck with this issue for more than 2 days and I am yet to find a solution for this.

I created the replica of my issue in the below codesandbox.

https://codesandbox.io/s/lucid-sky-bl33e?file=/src/App.js
ES6 JavaScript : Part 1 | Let Const Default Parameters Spread Rest Operator Object Literal & more

Tags: javascript, modernjavascript, es6, beginners
Published: 2021-09-21 10:19:13

<b> ES6 JavaScript : Part 1 | Let Const Default Parameters Spread Rest Operator Object Literal & more </b>

Timeline :
00:00 Introduction 
00:16 Let keyword
<b>02:14 Interview Question about Let</b>
03:47 Const Keyyword
04:20 Default Parameters 
06:50 Rest Operator
08:41 Spread Operator
<b>09:45 Shallow copy with Spread Operator</b>
10:51 Object Literal
12:48 Template Literal
14:44 for Of

{% youtube BAiU1b_4MtA %}
Deploy Website on AWS
Tags: webdev, devops, react, node
Published: 2021-09-21 10:05:42

Here we are going to learn Deployment on AWS.
Steps:-
    1. Go to AWS Console.
    2. Create Account.
    3. Select Launch EC2 instance.
    4. Configure Network settings and SSH.
    5. Now connect to your AWS instance.
    6. Now in your instance Clone your website through github.
    7. Install NVM in you AWS instance.
    8. Now run you WebApp and assign port.
    9. Now to run your webApp in background use below command:
        > Command:-
        ```
           $ forever start ./bin/www
        ```
   10. To check runnign background webApps use:
        > Command:-
        ```
           $ forever list
        ```
   11. Congrats your webApp is hoisted Now.
Java 9 Try With Resources Improvements
Tags: java
Published: 2021-09-21 10:00:48

Any resource like File or database connection or network connection etc… needs to be released after they are used. Before Java 7, try with finally blocks are used to close the resources.

With the introduction of try-with-resources in Java 7, closing the resources have become even easier. There is no need to explicitly close the resources using finally block. Try-with-resources auto closes the resources used in try block.

But, Java 7 try-with-resources has one drawback. It requires resources to be declared locally within try block. It doesn’t recognize resources declared outside the try block. That issue has been resolved in Java 9.

For examples and how the resources can be handled before Java 7, after Java 7 and after Java 9, see https://javaconceptoftheday.com/java-9-try-with-resources-improvements/ post.