teleren/devto huggingface dataset:
1 line of code: How to split an Array in half
Tags: javascript, webdev, performance, codequality
Published: 2021-11-01 15:10:05



```javascript
const splitInHalf = arr => [arr.slice(0, Math.ceil(arr.length / 2)), arr.slice(Math.ceil(arr.length / 2))];
```
Returns an new array where the first entry is the "first" and the second entry is the "second" half of the original array.

---

## The repository & npm package

You can find the all the utility functions from this series at [github.com/martinkr/onelinecode](https://github.com/martinkr/onelinecode)
The library is also published to [npm as @onelinecode](https://www.npmjs.com/package/@onelinecode/onelinecode) for your convenience.

The code and the npm package will be updated every time I publish a new article.

---

Follow me on [Twitter: @martinkr](http://twitter.com/_martinkr) and consider to [buy me a coffee](https://www.buymeacoffee.com/martinkr)

Photo by [zoo_monkey](https://unsplash.com/@zoo_monkey) on [Unsplash](https://unsplash.com/s/photos/fuji)

---
10 answers to popular Javascript tech interview questions in two minutes part. 1
Published: 2021-11-01 15:07:17

Lately, I was participating in a tech interview, where some JavaScript questions appeared. Eventually I found the experience fun, even after 16 years of coding with JavaScript. As every respectful creator, I have decided to make a series out of it :-)

Since that said, now I run a mini-series of answers to the most popular JavaScript interview questions. Below you will find a compilation of answers to first ten questions I have decided to answer. The questions are:

1. What is Javascript?
2. What types are available in Javascript?
3. What is hoisting?
4. What is the difference between == and ===?
5. What is implicit type coercion?
6. What does it mean Javascript is dynamically typed?
7. What is NaN?
8. What is the difference between assignment by value and reference?
9. What are immediately invoked functions?
10. What is "this"?
Answers:

If you like to learn more, you can follow me in various places and receive new videos with answers. Currently I am publishing one video (up to 15 seconds) per day.

You can follow me on

[YouTube](https://www.youtube.com/channel/UCNJCAg4hjHnWKUvgwuBqALw)
[Instagram](https://www.instagram.com/tomaszs2/)
[Facebook](https://www.facebook.com/tomsmyk/)
[Twitter](https://twitter.com/tomaszs2)
[LinkedIn](https://www.linkedin.com/in/tomaszsmykowski2/)
[TikTok](https://www.tiktok.com/@tomasz_smykowski)

Because I believe we should be able to choose a service we like the most. 

Also, you can follow me here, I will try to publish packs of ten answers here as well. 

The series is possible because I receive great feedback about it. If you like it, and would like me to continue the series, please upvote etc. 

Also: check out [flashcards for programmers](https://summonthejson.com) (Summon The JSON). It is far the greatest of my projects.

Have a good day!
PHP SimpleXMLElement
Published: 2021-11-01 14:59:31

SimpleXMLElement is part of the PHP core. It's an extention that allows us to create or manipulate XML.

I use `addChild()` to layout my XML, but what if you need to edit or replace an element afterworth? There is no `editChild()` or `replaceChild` to accomplish this, nor could you add a position to a new child. There are many ways to solve this, but according to me... This is the way.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/Ld77zD3fF3Run8olIt/giphy.gif">

##1. Generate XML##

To start with, lets create some dummy XML:

```php
$xml = newSimpleXMLElement('<request></request>');

$xml->addChild('name', $name);
$xml->addChild('age', $age);
$xml->addChild('gender', $gender);

$result = $xml->asXML();
```

This would result in the following output:
```xml
<?xml version="1.0"?>
<request>
    <name>John Doe</name>
    <age>50</age>
    <gender>Female</gender>
</request>
```

##2. Edit or replace XML nodes/elements##
Now if I would like to change the gender from `Female` to `Male`, I would edit or replace the value:

```php
$xml->gender[0] = 'Male';

$result = $xml->asXML();
```

Output:

```xml
<?xml version="1.0"?>
<request>
    <name>John Doe</name>
    <age>50</age>
    <gender>Male</gender>
</request>
```

That's all folks~

Source: https://coderedirect.com/questions/154676/edit-xml-with-simplexml
Conditional GitHub action based on commit message
Tags: github
Published: 2021-11-01 14:39:42

It's really annoying having a certain build/deployment GitHub action run on every push.

You can use this to run it **based on the commit message's content**:

```yaml
name: Publish

on:
  push:
    branches:
      - master

jobs:
  publish:
    if: "contains(github.event.head_commit.message, '[build]')"
```

Feel free to change the `'[build]'` part with whatever string you want.

You can also put a `!` at the beginning to invert the logic (Run the action on commit messages that **DON'T contain a certain string**)
How to talk about permanent situations in English correctly
Tags: blogging, language
Published: 2021-11-01 14:20:09

👥 This article shares the deeper understanding of using Present Simple in the context of permanent situations. Quotes are real life examples from your blogs!

🔤 The basis of it all. Expressing permanent and unchangeable situations. Before we get adventurous and start describing things that change, things that are only temporary or things that are conditional, first we need to talk about what we already have. Let's start then with the permanent situations. To describe them we will go with Present Simple!

🚲 The easiest, for many, most natural structure to use in English. You do not need to know much to start, just the verb list of Google Translate to help you out.

### Quick cheatsheet:
 **-s (for 3rd person singular)**
> Sarah **works** with programmers.

 **Do, Does?**
> **Does** Sarah work in helpdesk?
> She **doesn't do** enough tests.


**the verb be - am / is /are**
> Sarah **isn't** a programmer but she can become one if she wants to.

#### PERMANENT situations
> I **am** a developer.
> How **does** the Research Technology **work**?

Use Present Simple to express that whatever we are talking about is permanent from our perspective, and is unlikely to change.

#### CONSTANT states
> Only three things **are** certain in life: death,taxes, and more meetings.
> Python **continues** to be one of the bestprogramming languages every developer should learn.

Use Present Simple to talk about things you take for granted, which are not changing anytime soon. Very often we refer here to jobs, marital status, where we live and e.g. what language you program in.

#### UNCHANGEABLE truths
> Basel **enjoys** learning about computer science,astronomy and philosophy.
> I **hate** this (updating DOM inside datahandling functions?)

When we talk about things that are always true for us, even if we perceive them through the eyes of now, we use Present Simple.

### STATE VERBS
When we talk about current situation, our natural instinct is to use Present Continuous. But with certain verbs it is impossible. 
Verbs like:
*belong
*owe
*own
*know
*understand
*mean
*believe
do NOT take the continuous form, even if they express the current situation. 

In this category we also get feelings/emotions:
- like
- hate
- adore
- enjoy
- love.

> Each tag **belongs** to many posts
> Each post **belongs** to one user
> Each post **belongs** to one category
> Each post **belongs** to many tags

## Present Simple
Present Simple is a great tool to talk about things we see as permanent. Those could be routines, habits, facts and general truths.
It is also useful when we meet a state verb that cannot be changed into another form.

🧳Prepare for your next language challenge with Mirabella!
Semantic HTML / Semantic Tags
Tags: html, semantichtml
Published: 2021-11-01 14:19:15


Using <code>div</code> too much might not be the best practice. Try to avoid using it when it's unnecessary.
These are some new semantic tags according to the link https://developer.mozilla.org/en-US/docs/Glossary/Semantics#semantics_in_html
```html
<article>
<aside>
<details>
<figcaption>
<figure>
<footer>
<header>
<main>
<mark>
<nav>
<section>
<summary>
<time>
```
and there are more, these are some of the roughly 100 [elements](https://developer.mozilla.org/en-US/docs/Web/HTML/Element).

<code>section</code> tag defines sections in a document, a section is a thematic grouping of content and <code>article</code> sepecifies independent, self-contained content. An article should make sense on its own and it should be possible to distribute it independently from the rest of the site.
<code>aside</code> represents a portion of a document whose content is only <strong>indirectly related</strong> to the document's main content. Asides are frequently presented as sidebars or call-out boxes, often used to display ad.

<code>figure</code> and <code>figcaption</code>
<code>figure</code> is for wrapping your image content around it, and <code>figcaption</code> is to caption your image.


### When to use <code>dl</code>, <code>dd</code> and <code>dt</code>
<code>dl</code> represents a description list. The element encloses a list of groups of terms (specified using the <code>dt</code> element) and descriptions provided by <code>dd</code> elements. <code>dd</code> tag is used to describe a term/name in a description list. Common uses for this element are to implement a glossary or to display metadata (a list of key-value pairs).
* Only tag that can be inside <code>dl</code> apart from <code>dt</code> and dd is <code>div</code>.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dl
Base64 Encode and Decode in Javascript
Tags: base64, encode, decode, javascript
Published: 2021-11-01 13:50:35

[See it in Action - https://www.apps4developers.com/base64](https://www.apps4developers.com/base64)

#### Converting Plain Text to Base64 Encoded String

`btoa()` generates a Base64 encoded ASCII string from plain text. This method is useful to encode text that is not in a URL-safe format.

Passing a string to `btoa` method will return a Base64 encoded string.

`Example`
```javascript
btoa("Apps4Developers.com")
```

***---***

#### Converting Base64 Encoded String to Plain Text

`atob()` method is used to convert Base64 encoded ASCII string to plain text.

Passing a Base64 encoded ASCII string to `atob` method will return plain text.

`Example`
```javascript
atob("AkFwcHM0RGV2ZWxvcGVycy5jb20=")
```
Functional Programming with Java Streams
Tags: java, programming, tutoria
Published: 2021-11-01 13:29:48

Functional programming is becoming very popular and it focuses around pure functions. Functional applications avoid the shared state, and tend to be more concise and predictable than those using object-oriented code. In this course you will learn you how to move away from imperative to declarative programming allowing you to write less code and focus on what is important when build applications.

List of topics for this course

*What is functional programming ?*
- Stream API
- Transformations with Map, Reduce and FlatMap
- Filtering with Filter, TakeWhile
- Collectors
- Statistics
- Grouping
- Sorting

Full Course is available here: https://amigoscode.com/p/java-streams?coupon_code=STREAMS50 with **50% OFF**

## Crash course
{% youtube f5j1TaJlc0w %}
This podcast now has a fancy M1 processor!
Tags: jokes, podcast, career, inclusion
Published: 2021-11-01 13:25:32

In this episode, we chat about how much responsibility developers have for the actions of their employers, and then we play: Tech Dick  Shady Science, or Nazis?

{% spotify spotify:episode:6kS4gGQyY6VEXwKDkDvyjF %}
Containerization with Docker 🐳
Tags: webdev, docker, todayilearned, architecture
Published: 2021-11-01 13:17:26

Hello everyone!  This week I am going to go over containerization in docker and when it might be best to use it.  For those that are familiar with virtual machines, containers have the same concept.  Their purpose is to create an isolated environment that can be configured for a specific application.  Since virtual machines and containers are similar I think it is important to explain the difference between them for those that aren’t familiar.

Virtual machines were developed first and they are essentially virtual computers that are ran on the same hardware.  Each VM has it’s own OS and environment.  It uses something called a hypervisor to manage the hardware resources between each VM.  Disadvantages of a VM is that they are resource heavy and difficult to migrate between platforms.

![Virtual Machine Diagram](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tgzktewhe9l5unmgq419.png)

Containers are similar to VMs in concept but the big difference is that they don’t include the OS in the container.  This allows developers to create an environment for the application without including the resource heavy components of the VM.  Unlike VMs, containers are easy to migrate between platforms with the same OS and are lightweight.

![Docker Diagram](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q4euw9brh1mpcvj2clr2.png)

Containers do have their downsides though, some of which have to do with sharing the OS.  Any security vulnerabilities introduced with one container that effects the OS will therefore affect all of the containers on the same machine.  The containers are also initialized to work on a specific OS so if you want to migrate it, the new platform will need to be the same.  With the positives and negatives weighed, the developer will need to consider what migration, resource, and security concerns will effect the application.  Neither method is inherently better and will depend on the type of project.

I hope you all found this post helpful in understanding the basics of what containerization in docker is.  Next week I plan on giving a tutorial for setting up and using docker.  Please like and comment to let me know how I am doing and I hope you all have a great rest of your week.  Happy coding!

**Resources:**

1. https://docker-curriculum.com/#getting-started
2. https://www.youtube.com/watch?v=JSLpG_spOBM
3. https://www.netapp.com/blog/containers-vs-vms/
4. https://www.redhat.com/en/topics/containers/containers-vs-vms
Reseason Why Someone Should be a Programmer
Tags: programming, career, beginners, discuss
Published: 2021-11-01 13:15:28

## Salary

The average salary of a front-end developer in 2017 was about $70K per year. This varies, even more, depending on which country you live in.

## Creativity

Having the ability to create whatever you want is an amazing perk of being a programmer. You don’t depend on anyone to build your projects.

## Transferrable Skills

Usually, most of the things you learn in programming are transferrable skills you can reuse in another job position or company.

## Side Hustles

There are more and more remote jobs for programmers, which means more time to focus on side hustles while having a job. This is one of the best perks.

## Building your empire

If you look closely at the most successful people, most of them knew to program. Programming allows you to do anything!

---

Did you find it helpful? Let me know your thoughts in the comments below!

## Let's connect!

You can follow me on [Twitter](https://twitter.com/MrDanishSaleem), [LinkedIn](https://www.linkedin.com/in/mrdanishsaleem/) & [GitHub](https://github.com/mrdanishsaleem/)

---

If you like this post. Kindly support me by [Buying Me a Coffee](https://www.buymeacoffee.com/mrdanishsaleem)

![Buy Me a Coffee](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v0ikih5nlsqs0oops11e.png)
3 Soft Skills To Succeed as a Developer
Tags: programming, productivity, career, todayilearned
Published: 2021-11-01 12:40:36

**1. Creativity**
When problems surface, a creative developer knows solutions likely already exist. And if it doesn’t, the developer isn’t afraid to come up with new solutions.

As a software developer, solutions aren’t handed over to you to mindlessly code. Instead, you must explore possibilities, weighing different technologies and your team’s skills. After gaining some experience to understand what technologies exist, the creativity of combining these solutions together becomes easier.

**As a full-time software developer, you cannot fail — if a problem exists in your code, there is a solution, and you will find it. This will be the true test of your creativity.**

**2. Reliability**
In a team, people rely on you to get your work done, especially when you promise to complete a task. If you’re reliable, no one will need to check up on your progress, as you’ve proven you can take on responsibilities.

Leaders want software developers who don’t need any babysitting. They want direct reports from who agree to do something and then follow through on their commitment. Believe it or not, many people aren’t reliable, so being a reliable developer will make you the go-to person for new tasks and opportunities.

**3. Steller Communication**
All softwares are built on a team composed of people with different ideologies, beliefs, biases, and experiences.

The best software developers communicate complex technical concepts to non-technical folks or technical ones who are still learning. You will go far as a developer if you can communicate across roles and teach others.
"chat not found" error when replying to user
Published: 2021-11-01 12:22:28

We have a scenario where the user starts a conversation by calling our telegram bot. We extract the chat id from the message data when the user calls our bot

We use the chat id in order to reply the user by making a post call:
url - https://api.telegram.org/bot123321123321:token/sendPhoto
body - "chat_id":"123456789","parse_mode":"Markdown","text":"hi"}

The response is: error 400 "Bad Request: chat not found" 

This only happens for some of the users while the rest are able to receive the messages. Is it possible that the chat id of this user was sent incorrectly by telegram on the first message? Or maybe this user has privacy settings? The same error is received when trying to make the same call from postman.

Thanks
Code Smell 99 - First Second
Tags: oop, tutorial, webdev, cleancode
Published: 2021-11-01 12:06:51

*How many times do we see lazy argument names?*

> TL;DR: Name your arguments according to the role and not the accidental position

# Problems

- Readability

- Intention Revealing Names

# Solutions

1. Use meaningful names

# Context

When writing methods, we usually don't stop to find decent names.

We never refactor the obvious, neither.

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/552f2a10d660ee37744f111fe9bf6665)
```python
class Calculator:
  def subtract(self, first, second):
    return first - second

class CalculatorTest:  
  def test_multiply():
    assert equals(first, second)
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/bbbc636c7c309c86b4f1114b1f57f6b8)
```python
class Calculator:
  def subtract(self, minuend, subtrahend):
    return minuend - subtrahend

class CalculatorTest:  
  def test_multiply():
    assert equals(expectedValue, realValue)
```

# Detection

[x] Manual

We can warn for forbidden words like 'first' and 'second' as argument names.

# Tags

- Readability

# Conclusion

Always follow rule suggesting parameter.

Name your collaborators according to the role.

# Relations

{% post https://dev.to/mcsee/code-smell-65-variables-named-after-types-9da %}

# More Info

{% post https://dev.to/mcsee/what-exactly-is-a-name-part-ii-rehab-20gd %}

# Credits

Photo by <a href="https://unsplash.com/@priscilladupreez">Priscilla Du Preez</a> on <a href="https://unsplash.com/s/photos/two">Unsplash</a>
  
* * *

> Final source code is the real software design.

_Jack Reeves_
 
{% post https://dev.to/mcsee/software-engineering-great-quotes-26ci %}

* * *

This article is part of the CodeSmell Series.

{% post https://dev.to/mcsee/how-to-find-the-stinky-parts-of-your-code-1dbc %}
useMemo React 
Published: 2021-11-01 11:43:56

Utilizei o useMemo no react e memorizou uma configuração porém preciso apagar esta memorização, estou utilizando o expo, limpei cache, ja fiz de tudo porém não consigo apagar da memória, inclusive removi todo o useMemo da minha aplicação e não teve sucesso em remover o que foi gravado na memória.
10 Reasons to Choose Veeam to Protect Your Data on AWS
Tags: aws, cloud
Published: 2021-11-01 11:36:48

One of the biggest worries organizations have about moving their workloads and data to the cloud is data loss. It’s a valid worry. Even AWS, the leader by far maintains that your applications and your data in the cloud are your responsibility, as evinced by the AWS Shared Responsibility Model. However, you can easily eliminate data loss risk while saving on costs using a service from AWS partner network: Veeam Backup and DR

Fully automated and native, Veeam provides comprehensive backup and disaster recovery services that can help you secure your data on Amazon EC2, Amazon RDS, Amazon EFS and Amazon VPC, while saving on back up costs. There are several reasons to pick Veeam for your AWS back up and recovery, here are the top 10
Five Ways AWS Helps You Meet Security Requirements
Published: 2021-11-01 11:31:45

AWS regularly monitors and secures 3rd party validation for global security and compliance standards for diverse industries, including finance, insurance, public sector enterprises, and more. These latest security controls, which are operated by AWS, beef up your own compliance and certification programs. AWS provides access to tools to run your own specific security assurance requirements, effectively saving you cost and time.
My 10 favorite Tech Twitter tweets from this week
Tags: webdev, codenewbie, programming, tutorial
Published: 2021-11-01 11:28:13

_If you found value in this thread you will most likely enjoy my tweets too so make sure you follow me on [Twitter](https://twitter.com/VladPasca5)  for more information about web development and how to improve as a developer. This article was first published on my [Blog](https://vladpasca.hashnode.dev/)_

"NFTs are just some jpgs"

By dabit3 

{% twitter 1452711320923648010 %}


Your version 1 will be bad no matter how hard you're trying. Just ship it

By IMAC2 

{% twitter 1452969144379396096 %}


Normal day for a developer

By TheAnkurTyagi 

{% twitter 1452688171603578887 %}


Stop learning only programming languages. Learn other skills too

By heyOnuoha 

{% twitter 1453319167894036481 %}


<a> tag social media sharing cheat sheet

By denicmarko 

{% twitter 1452973356077264904 %}


Clear roadmap for the web3 aspiring developers

By oliverjumpertz 

{% twitter 1452585404348215298 %}


Prepare for your job interview as a developer

By sunilc_ 

{% twitter 1453350418482966542 %}


Learn to position yourself as a freelancer

By study_web_dev 

{% twitter 1453283977960243223 %}


You can't judge a tool before using it, try and then take a conclusion

By csaba_kissi 

{% twitter 1452885896278196225 %}


JavaScript can literally change your life

By SimonHoiberg 

{% twitter 1453024314576580615 %}

_I hope found this useful and if you did please let me know. If you have any questions feel free to DM me on  [Twitter](https://twitter.com/VladPasca5)._let me know. If you have any questions feel free to DM me on  [Twitter](https://twitter.com/VladPasca5)._
CloudFormation vs CDK vs Terraform—Which IaC tool is right for you?
Published: 2021-11-01 11:15:11

If you’re mostly using simple solutions, like Serverless, with minimal dependencies, CloudFormation or CDK will serve you well enough. This is also true if you intend to keep you infrastructure exclusively on AWS. However, if you use a mutli-cloud environment, or see this as a future possibility, Terraform’s platform agnostic nature offers a definite advantage