teleren/devto huggingface dataset:
JavaScript sort method – part 2
Tags: javascript, beginners, tutorial
Published: 2021-11-05 07:26:31

*This post was originally published on [webinuse.com](https://webinuse.com/javascript-sort-method-how-to-use-it/)*

Welcome to JavaScript sort method part 2. [We already wrote on how to sort strings and numbers](https://webinuse.com/javascript-sort-method-how-to-use-it/). Today we are talking about how can we sort [objects](https://webinuse.com/guide-to-javascript-data-types/). 

Similar to arrays, we can sort objects by some key. 

```javascript

const obj = [
    {id: 225, name: 'John'},
    {id: 123, name: 'Aida'},
    {id: 897, name: 'Elisabeth'},
    {id: 242, name: 'Jamal'}
]

obj.sort(function(a,b) {
    if (a.id > b.id) {
        return 1;
    }

    return -1;
})

//Result
/*[
    {id: 123, name: 'Aida'},
    {id: 225, name: 'John'},
    {id: 242, name: 'Jamal'},
    {id: 897, name: 'Elisabeth'}
]
*/
```
In the previous example, we sorted object by `obj.id`. We can do the same, but with `obj.name`.

```javascript

const obj = [
    {id: 225, name: 'John'},
    {id: 123, name: 'Aida'},
    {id: 897, name: 'Elisabeth'},
    {id: 242, name: 'Jamal'}
]

obj.sort(function(a,b) {
    if (a.name > b.name) {
        return 1;
    }

    return -1;
})

//Result
/*[
    {id: 123, name: 'Aida'},
    {id: 897, name: 'Elisabeth'},
    {id: 242, name: 'Jamal'},
    {id: 225, name: 'John'}   
]
*/
```

###How to use arrow functions with JavaScript sort method?

ES2015 introduced [arrow function expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions). An arrow function can help us shorten `compare function`.

Let's take a look at some examples. We will create previous examples (and from [part 1](https://webinuse.com/javascript-sort-method-how-to-use-it/)) with arrow functions instead of "normal" functions.

```javascript
    const numbers = [4, 2, 5, 1, 3];
    numbers.sort((a, b) => a - b);
    console.log(numbers);
    
    //Result:
    // [1, 2, 3, 4, 5]
    
    numbers.sort(a, b) => b - a);
    console.log(numbers);
    
    //Result:
    // [5, 4, 3, 2, 1]
    
    
    numbers.sort(a, b) => b === a);
    console.log(numbers);
    
    //Result:
    // [4, 2, 5, 1, 3]

    const obj = [
        {id: 225, name: 'John'},
        {id: 123, name: 'Aida'},
        {id: 897, name: 'Elisabeth'},
        {id: 242, name: 'Jamal'}
    ]

    obj.sort((a,b) => (a.id > b.id) ? 1 : -1)

    //Result
    /*[
        {id: 123, name: 'Aida'},
        {id: 225, name: 'John'},
        {id: 242, name: 'Jamal'},
        {id: 897, name: 'Elisabeth'}
    ]
    */

    obj.sort((a,b) => (a.name > b.name) ? 1 : -1)
    //Result
    /*[
        {id: 123, name: 'Aida'},
        {id: 225, name: 'John'},
        {id: 242, name: 'Jamal'},
        {id: 897, name: 'Elisabeth'}
    ]
    */
```
If you have any questions or anything you can find me on my [Twitter](href="https://twitter.com/AmerSikira), or you can read some of my other articles like [JavaScript sort method – part 1](https://webinuse.com/javascript-sort-method-how-to-use-it/).
Introduction to Tree data structures
Tags: beginners, programming, tutorial, computerscience
Published: 2021-11-05 07:26:17

In the realm of data structures, Linked list, array can be described as a linear data structure unlike trees which are non-linear, hierarchical data structures.
Read more-
https://paragnaik2019.medium.com/introduction-to-tree-data-structures-31c7976979a5
Java/ Protect Presentation Slides
Published: 2021-11-05 07:22:30

To protect a PowerPoint document from being snooped or modified， Free Spire.Presentation for Java enables developers to encrypt the PowerPoint files with password or to set write protection to make the presentation read only. In this article, you will learn how to use the above two methods to protect the presentation slides.

###Import jar dependency###
● You can download the [free library](https://www.e-iceblue.com/Download/presentation-for-java-free.html) and unzip it, and then add the Spire.Presentation.jar file to your project as dependency.

● Or you can directly add the jar dependency to your maven project by adding the following configurations to the pom.xml.
```xml
<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation.free</artifactId>
        <version>3.9.0</version>
    </dependency>
</dependencies>
```
###Encrypt PowerPoint File###
Free Spire.Presentation for Java offers the **Presentation.encrypt()** method to encrypt the whole document with specified password.
```java
import com.spire.presentation.*;

public class encrypt {
    public static void main(String[] args) throws Exception {

        //Load a PPT document
        Presentation presentation = new Presentation();
        presentation.loadFromFile("Sample.pptx");


        //Encrypt the document with the password
        presentation.encrypt("abc-123");

        //Save the file
        presentation.saveToFile("output/Encrypted.pptx", FileFormat.PPTX_2010);
    }
}
```
![Encrypt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1kloaw32jv2hfg0rhve6.jpg)


###Set the Presentation Slides Read Only###
The **Presentation.protect()** method allows developers to protect the PowerPoint document with password. Unlike the **Presentation.encrypt()** method mentioned above, the users only need to enter the password when they want to modify the document, otherwise they can directly open the document in read-only mode.
```java
import com.spire.presentation.*;

public class setDocumentReadOnly {
    public static void main(String[] args) throws Exception {

        //Load a PowerPoint document.
        Presentation presentation = new Presentation();
        presentation.loadFromFile("Sample.pptx");

        //Protect the document with the password
        presentation.protect("123456");

        //save the file
        presentation.saveToFile("output/Readonly.pptx", FileFormat.PPTX_2010);
    }
}
```

![Read only](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ee40d6g141g0tknsr0bu.jpg)
Markdown Cheatsheet
Tags: markdown, webdev, writing
Published: 2021-11-05 07:09:48

# Headings

### ` #Heading1 `

### ` ##Heading2 `

### ` ###Heading3 `

### ` ####Heading4`

### ` #####Heading5 `

### ` ######Heading6 `

___


# Link 

### ` [ link name ] (link url) `
[Demo Link](https://gauravvala.xyz)

Here the link url will have to be in specific format of :`https:// yoursite domain`

___

# Text

### ` _ italic text  _ `
demo _text_

Here you can also use star(*) instead of underscore(_)

### ` ** bold text **`
demo __text__

Same as previously you can use underscore instead of start but use 2.
___

# Blockquotes

### ` > your text here`
### ` >> nested blockquote`

>Demo text showing the blockquote
>>Nested blockquote text here

___

# Lists

You can make 2 types of lists using markdown: Ordered list and Unordered List

## *Ordered List*

### ` 1. Your text here`

Demo 👇🏻
1. Text 1
2. Text 2

While making ordered list you just start from (1.), here the dot is key element for specifying the list. You just add numbers with dots to form an ordered list

## *Unordered List*

### ` * Your text here`

Demo 👇🏻
* Text 1
- Text 2

While making unordered list you use the (*) symbol. the use of start symbol is not necessary here, you can also use (-) _ __both works...__ _

___

# Image 

### ` ![image alt text](image url)`

Demo Image👇🏻

![demo image alt](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT1zgzHl5ahX-1kFu_mz2m7kN4-g1S1NEL0IA&usqp=CAU)

___

# Code blocks

### ` `your inline code` `

Here you use the (`) symbol where your code is written in between two symbols

### ` ```Your whole code block``` `

```
HERE WILL BE YOUR CODE WITH SYNTAX HIGHLIGHTING
```

While making a code block make sure to write the (```) two time on seperate line where the code will come in the area between them.

___ 

# Conclusion

These are some basic symbols that i use while formatting my blogs on Hashnode or Dev to

> One thing to keep in mind that some sites don't recognise the markdown if you don't give space between the `symbol` and the `text` so check the preview while formatting to adjust the space and format according to the site

If you want to to learn more complex components of markdown you can checkout the [github guide](https://guides.github.com/features/mastering-markdown/) for reference.

___ 

**If you found the content i share useful than share it with your developer friends and also follow me on [Instagram](https://www.instagram.com/gaurav_vaala/) and [Twitter](https://twitter.com/gaurav_vaala)**
HTML tags | option
Tags: html, tags, option
Published: 2021-11-05 07:05:43

It is used to **define an item contained in a select list**, that is, inside `<select>`, `<optgroup>` or `<datalist>` elements.

If you have a long list of options, you can group related options within the `<optgroup>` tag. 

### disabled
If this Boolean attribute is set, this option is not checkable. Often browsers grey out such control and it won't receive any browsing event, like mouse clicks or focus-related ones. If this attribute is not set, the element can still be disabled if one of its ancestors is a disabled `<optgroup>` element.

### label
This attribute is text for the label indicating the meaning of the option. If the `label` attribute isn't defined, its value is that of the element text content.

### selected
If present, this Boolean attribute indicates that the option is initially selected. If the `<option>` element is the descendant of a `<select>` element whose `multiple` attribute is not set, only one single `<option>` of this `<select>` element may have the `selected` attribute.

### value
The content of this attribute represents the value to be submitted with the form, should this option be selected. If this attribute is omitted, the value is taken from the text content of the option element.

- Type: *block*
- Self-closing: *No*
- Semantic value: *No*

[Definition and example](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option) | [Support](https://caniuse.com/mdn-html_elements_option)
Text-to-Speech
Tags: html, css, javascript, webdev
Published: 2021-11-05 06:53:13

<a href="https://protecgames.godaddysites.com/sign-up"><botton>Sign Up</button>
<Br>
<p>Many of you have surely using Text-to-Speech Service by Google. It's cool right? But have you ever thought how  can you also make such program using only HTML , CSS , and JavaScript! Let me show an example <a href="https://protecgamesofficial.blogspot.com/2021/10/text-to-speech_31.html?m=1">Click to see example</a> <br>

</P>
<A href="https://www.google.com/search?q=text+to+speech&tbm=isch&tbs=itp:animated&client=ms-android-huaqin&prmd=bnixv&hl=en-GB&sa=X&ved=2ahUKEwjEoIP80ID0AhUqsksFHREND88Q2p8EegQIARBW&biw=360&bih=512#imgrc=lYKj-I4B-uVDnM">ABOUT IMAGE AND OWNER</A>
Guía de bolsillo para crecer de Junior a Senior
Tags: spanish, beginners, career, latam
Published: 2021-11-05 06:09:02

## ¿Qué hace un DEV Senior que no pueda hacer yo?

Esta serie de posts tiene contenido de mi [libro el cual se encuentra en preventa y saldrá antes de terminar 2021](https://marianorenteria.gumroad.com/l/guia-junio-senior). 


# ¿Cuál es la diferencia entre un Junior y que es un Senior?

#### Un senior es alguien que genera valor y comparte conocimiento con el equipo.

Esta será la teoría sobre lo que trabajaré en esta guía y mi objetivo será ayudarte a que te conviertas en un Senior.

En mis años de experiencia y dirigiendo un equipo con bastante ingenieros e ingenieras de software, te puedo decir que el común denominador entre un junior y un senior para nosotros es que tan importantes son para el equipo, cuantos errores comenten, cuanto _management_ requieren, el tipo de preguntas que hacen, etc. 

Si existe una relación entre lo que te menciono arriba y los años de experiencia que llevan trabajando, pero también influye mucho el tipo de proyectos que han tenido, el tipo de empresas, el tipo de jefes, etc. demasiadas variables… 

Mi intención es orientarte a que de cierta forma te des cuenta en lo que nosotros los líderes vemos como Senior para que tú busques desarrollar o mejorar esas características. 

####¿Cuántos años de experiencia necesito?

De preferencia 4 años de experiencia. 

Esto no va ligado simplemente a los años trabajando, porque todos conocemos a mucha gente que no aporta valor a los equipos, que es tóxica, esas personas de igual forma cumplen los años de experiencia, pero están estancados o cambian constantemente de trabajo porque no se sienten “cómodos”.

---

En mi equipo actual, en el departamento de ingeniería, hay 50 personas,  algunas de ellas son personas con muchos años de experiencia, que en el papel y en sus CV ponen que son senior, pero que aún cometen errores de junior, esas personas trabajan “bien”, pero el valor que aportan al equipo comparado con lo que cobran no es el deseado. 

En comparación hay personas con no tantos años de experiencia que hacen las preguntas correctas, compromiso alto, pocos errores, el valor que aportan es alto, esas personas son las que buscamos retener e impulsar, algunas en poco tiempo se convierten en líderes por lo mismo. 


----

Sigo trabajando en mis productos con el fin de ayudar de forma más estructurada a la comunidad de TI, si te interesan [pásale a mi perfil de Gumroad](https://marianorenteria.gumroad.com/)
- 📕 Líder Técnico
- 📘 De Junior a Senior
- 🗓 Mentorías
- 📑 Revisión de C.V.

Te invito a que **[me sigas en Twitter](https://twitter.com/marianorenteria/)** para que te enteres de todo el contenido que hago normalmente 🙃.

También soy creador del [podcast Chile, Mole & Tech](#)(https://dev.to/chilemoleytech), el cual esta [en todas las plataformas](#)(https://linktr.ee/chilemoleytech).

** Si te gusto este post, no dudes en compartirlo, me ayuda mucho. **
----
How do apps manage user credits/ features nowadays?
Tags: help, discuss, architecture, cloud
Published: 2021-11-05 06:04:55

This seems to be a very common building block for apps, but I can't find popular solutions - 

1. An app has registered users
2. Every user can have different types of credits, points, enabled-features, used-promo-codes, campaigns etc...
3. Different parts should behave differently according to those

Sure, we can manage all that data in a DB and write lots of custom code, however it becomes a big block to design, refactor, migrate schema versions, manually resolve issues....

To clarify the question lets simplify to one use-case - 
*"Credits Management"* - 
1. Upon purchase, user gets 1,000 credits of type "paid-credits" to be used in the app. These don't expire.
2. Upon promo-code-activation, user gets 200 credits of type "promo-credits-feature1" - only to be used with "Feature1" of the app, and those expire after 1 month. 
3. User spends 200 credits on Feature1 
4. User is not satisfied, asks for refund. His "paid-credits" are not used yet, so he qualifies for a no-questions-asked refund.
5. Upon server-side usage of Feature2, the backend needs to verify the amount of available credits (possibly "reserve X credits" for an activity), log the usage of the credits for traceability (such as an invoice breakdown)  etc.

I would expect some existing solution to offer this as a service with an API. Do CRMs have anything to do with these things? 

Is it "too simple of a problem" that everybody manage in their DB and don't make a big deal out of it?

It will be nice to hear what others are using and some insights about this.
What’s the model?
Tags: ios, beginners, programming
Published: 2021-11-05 01:28:22

I teach iOS development as a side job. I work 9-5 (well, actually, it’s a bit earlier than that, since I’m working for an English company at this moment). After I finish working, three times a week, I teach iOS development to different people, for two hours. They are starting their careers, and they are developing their intuition about software engineering.

That’s really interesting from the point of view of somebody who has been in the industry for some years now. It’s good to remember how you started and what errors did you make at the beginning. 

Today, I’m going to talk to you about an error I see over and over again, and recently, I think I reached a way of making people think about it, and reason about it.

Imagine you are developing an app for ordering food from restaurants: 

- You have a listwith different dishes and options. 
- You can add more units of any of the options you have in the list.
- Each item in the list has the number of items of that type you’ve already added, it will let you add or sub any number of items at any moment.
- Whenever you add food, there is a shopping cart or something like that at the bottom of the screen where you can see immediately updated the price of the food you’re buying.

Fairly simple, straightforward problem.

So, here is the thing. There are many ways on how to develop something like that. Imagine you’re using UIKit for now, and not SwiftUI. You would have tableView or collectionView cells for the items in the list, and you would sum to the amount that you have in the bottom.

This is how people tend to design these kind of apps when they start:

- They detect the event to add more items of a certain type. 
- They check the label in the cell to know how many items of that type they have already added.
- They add one to that number.
- They update the label in the cell.

And they have similar solutions for the different parts of the UI in this and similar problems. **They rely on the UI as the source of truth.**

So I started to ask them: **What is the model?**. I start any exercise with them in the same way. Regardless of how simple of complex a screen is, I start asking them: What is the model in this UI?

The other thing that’s related to this I use to tell them from the very beginning is: We are UI developers. As UI developers, our goal isn’t only to deliver delightful UIs with animations and beatiful graphics. **Our goal is to ensure consistency between the model and the UI.** The part about the UI is usually easily understandable. The part about the model is very hard to understand when you’re starting.

Our goal is to ensure consistency between the model and the UI. You have a UI, what is the model?
AzCopy.exe exited with non-zero exit code while uploading files to blob storage
Tags: azure, devops, storage
Published: 2021-11-05 05:52:58

In Azure DevOps, trying to copy a file to Azure Storage using the Azure file copy task.

Initially we were using v3 and it had an error in a "Pre-job" task (but the task itself succeeded) with this error:
`Unable to fetch storage account key. Error: '{0}' Error: Input required: ConnectedServiceNameSelector`

In v2 of the task the error is:
`Unable to fetch storage account key. Error: '{0}' TypeError: Cannot read property 'retrieveSecret' of undefined`

## The Fix
Under the hood the task must be creating a SAS token and then trying to upload to the blob storage. To fix the problem you need to ensure the Service Principal being used has these two roles on the Azure Storage Account:

`Storage Account Contributor` - "Lets you manage storage accounts, including accessing storage account keys which provide full access to storage account data."

`Storage Blob Data Contributor` - "Allows for read, write and delete access to Azure Storage blob containers and data"

You can add those roles in IAM
![IAM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2jwyxz5ux3ipezd8x025.png)
![Add roles](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tarnjx12i3lmpjtmzlxm.png)
Note-Keeper
Tags: notekeeper, javascript, webdev, naemazam
Published: 2021-11-05 05:30:31

Note-taking is the practice of recording information from different sources and platforms. By taking notes, the writer records the essence of the information, freeing their mind from having to recall everything. in Note keeper app you can save, edit and delete your notes. It's have also Search feature and No one can see Your notes. It's Fully HTML, CSS, and Js based Web APP.

visit GitHub To Learn more 

[Github](https://github.com/naemazam/Note-Keeper)
Top learning methods for software developers
Tags: javascript, webdev, programming, productivity
Published: 2021-11-05 05:25:37

One of the most difficult staff of being a Self- Taught Developers is being able to find resources for learning.

If you have an internet connection you can be able to get all the learning resources in the world, but sometimes it can be tiresome, so I have come up with top learning methods you can use a Self-Taught developer to teach yourself the coding skills from beginner to advance without any curriculum barrier. Meanwhile.

This journey of being a Self-Taught Developer requires a lot of dedication and consistency while following these learning methods. 

1. read books
2. audio books and podcasts
3. written tutorials and blogs
4. Structured electronic courses
5. reading other people’s code
6. YouTube tutorials
7. stand alone courses
8. documentation
9. build your own projects

Read the full post here
https://www.weptim.com/top-learning-methods-of-self-taught-developers/
ติดตั้ง IDE Helper ใน Lumen
Tags: laravel, lumen
Published: 2021-11-05 04:43:22

จาก [Laravel IDE Helper Generator](https://github.com/barryvdh/laravel-ide-helper)
## ติดตั้ง laravel-ide-helper
```sh
composer require --dev barryvdh/laravel-ide-helper
```

## Setting
register ide-helper ที่ `bootstrap/app.php`
```php
...
// check local environment
if (app()->environment('local')) {
    // register ide-helper
    $app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
...
```

เพิ่มลง `composer.json`
```json
...
"scripts": {
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "@php artisan ide-helper:generate",
            "@php artisan ide-helper:meta"
        ],
       ....
    },
...
```

ทดสอบ
```sh
composer update
```
php7.1-gd ใน docker หาย ก็มาใช้ php7.2-gd ได้เหมือนกัน
Tags: php, webdev
Published: 2021-11-05 05:13:13

ต้องใช้ php7.2 เพราะ php7.1-gd หาไม่ได้แล้ว แก้ที่ `phpdocker/php-fpm/Dockerfile` ตามนี้
```
# use php7.2-fpm
FROM phpdockerio/php72-fpm:latest
WORKDIR "/application"

# install php7.2 extensions for laravel
RUN apt-get update; \
    apt-get -y --no-install-recommends install \
        git \ 
        php7.2-bcmath \
        php7.2-gd \ 
        php7.2-imap \ 
        php7.2-mysql && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
```