teleren/devto huggingface dataset:
A different way of handling required arguments in javascript functions
Tags: javascript, webdev
Published: 2019-09-22 12:51:37

---
title: A different way of handling required arguments in javascript functions
published: true
description: Required parameters are everywhere in our codebase, in this short article we are going to explore a different way of handling them that might just be your new favorite approach.
tags: javascript, webdev
canonical_url: https://enmascript.com/articles/2019/09/22/a-different-way-of-handling-required-arguments-in-javascript-functions
cover_image: https://enmascript.com/images/2019-09-22-required-function-arguments.png
---

_Originally posted on [Enmascript.com](https://enmascript.com/articles/2019/09/22/a-different-way-of-handling-required-arguments-in-javascript-functions)_

<mark>**#Did you know** is a new series of Enmascript where we write short and concise explanations about topics we consider might be relevant or underestimated, if you are looking for more complete in-depth articles check out our **[other series](/series)**.</mark>

_Usually_ in javascript if you want to validate required arguments, you would do something similar to this:

```javascript
function Person(water, food, candy) {
    if (!water || !food) {
        throw new Error('water and food are required for Person');
    }

    // Do something with water and food...
}
```

The constructor `Person` Above would throw an error if no `water` or `food` is supplied, this is a relatively common and popular way of validating parameters, but there is a different more functional way to achieve this.

Create a helper function that throws an error:

```javascript
const required = name => {
    throw new Error(`Parameter ${name} is required`);
};
```

In the case above we are passing an argument `name` to the function because it feels more natural to print the name of the parameter that is required.

Then we use it like this:

```javascript
function Person(
    water = required('water'),
    food = required('food'),
    candy
) {
    // Do something with water and food
}
```

**What is happening here? How does this validation work? It is very straight forward:**

If we don't pass the required parameter's values, the `required` function is executed throwing an error and forcing the user to pass each mandatory value everytime the function is invoked.

Passing the name of the parameter to the `required` function is only a preference; we can decide not to pass it and make the helper function simpler, it is a personal choice.

This approach is not limited to this implementation, we can use this same principle to create our own argument's validators and reuse in our functions to enforce consistency and security.

Do you have ideas that are similar or related to this topic? [share them with us](https://www.reddit.com/r/javascript/comments/d7pvw7/a_different_way_of_handling_required_arguments_in/).
Real developers don't ask for help
Tags: beginners, career, motivation
Published: 2019-09-22 12:32:27

You've probably been in this situation; you have been programming for years, but you still have to ask others for help or Google the same simple thing every day. 

So you sit there and wonder "am I ever going to be a proper developer, if I'm still asking others for help or using Google every day?".

The answer is no.

- Real developers don't have to ask for help.
- Real developers don't use Google.
- Real developers memorise everything. It's inefficient to have to keep looking everything up. 

![That's bullshit!](https://media.giphy.com/media/ybG5Au3UhHv4k/giphy.gif)

Of course everything I said above is complete bullshit. The truth is the complete opposite. 

Good developers ask for help. 

Good developers ask for other people's opinions, even when they think they know the answer or have come up with the best solution. 

Good development teams work together, even on simple problems. 

Let me tell you - if you ask others for help, or Google the same thing ten times a day, this does not make you a bad developer. 

It makes you a real developer, who is happy to admit what they don't know or need help with. 

There is nothing more dangerous than a developer who thinks they know everything, refuses to ask for help, or will only work on their own.
Demystifying CSS ( A Pratical Approach ) Part. I
Tags: css, tips, development, frontend
Published: 2019-09-22 12:07:23

---
title: Demystifying CSS ( A Pratical Approach ) Part. I
published: true
description: css tutorial
tags: #css #tips #development #frontend
cover_image : https://thepracticaldev.s3.amazonaws.com/i/jetgijqw1als8d2xjnjy.png
---


I decided write a tutorial about **``CSS``**,  demystifying some properties and concepts about css. this is a  first part from a series of posts. then, enjoy!

#Margin vs Padding
**Margin** :  Defines the ``exterior space`` of an elements relative to browser elements. For examples : want give a space of 10px to a button in relation to top of page. Therefore, margin property defines the margins of a element.

**``margin``** used alone  implies give a margin in **top**, **left**, **right** and **bottom** with the same spacing values, however It's still possible defines specific values for each sense.

**``margin-top``** :  top spacing
**``margin-bottom``** :  bottom spacing
**``margin-right``** : right spacing
**``margin-left``** : left spacing

**Examples**


**``element without margin``**

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/aubf2kzndv6jw13gcgfs.png)

**``element with margin``**

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/9l03ia49t73plzk0b93u.png)

That is, from the margin, it is possible to define the same spacing value for all directions, as it is possible to select specifically which directions will have a spacing.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/qciaxkenaa4dkzoxqo8g.png)


**Padding** : Sets the spacing relative to the edge of an element. That is, defines the horizontal and vertical spacing of an element within a larger element.

Like margin, the padding property can define spacing in four directions: top, bottom, right and left.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/hdyq2zp1nlvz5pjfti9h.png)

**Examples**

**``element without padding``**

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/wgamte10z2kwimnu128y.png)

**``element with padding``**

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/9as552zhoitrk4nc0qij.png)

**Conclusion**  :tada:

So this first part of the "Demystifying CSS (A Pratical Approach)" series came to an end. Thanks for everything and wait for the other parts!
Do we need to know the magic?
Tags: discuss, webdev, beginners, productivity
Published: 2019-09-22 07:44:22

---
title: Do we need to know the magic?
published: true
description: Do developers need to know how the magic works behind the commands and build tools they use in modern web development?
tags: discuss,webdev,beginners, productivity
---

I'm hoping to open up a bit of discussion here.

In my opinion, the current state of modern web development has a lot of "magic".

What I mean by magic is the running of commands or using software that does a lot of set up, scaffolding or triggers a build process etc with minimal knowledge required from the developer.

This magic is fantastic, it helps us get up and running quickly and allows us to focus on our apps or products and not get delayed having to understand or set up complex environments and configurations.

However, every time one of these magic commands fails or does not reflect the readme verbatim I can often find myself on Google for hours trying to debug and understand what went wrong.

My question is, does anyone else experience this and does it make you feel like an imposter? How important is having a working knowledge of these package managers and scaffolding applications?

Would love to know everybody's thoughts. 👍
🚀Made Paper , an offline note taking app with a "networkless" share option.🖥️🔄📱
Tags: showdev, webdev, javascript
Published: 2019-09-22 07:13:33

{% youtube wXRBCvfp2pQ %}

Paper is created by me and 

{% user pjijin %}

What lead to the creation of Paper?
The idea to create paper came out when we both were working on a side project and wanted to share text/links between our 🖥️🔄📱computers/mobile, thanks to BSNL (Indian Broadband Network) and its fluctuating internet connectivity, we thought of working on an offline note sharing application leveraging local storage and QR code.

✅ Live Preview: https://paperapp.now.sh

Pros
🔥 PWA Based
📖 OpenSource
⛓️ Easy Share
🔌 No Internet
🖥️ LocalStorage
📠 Share through QR
🌗 Dark/Light Theme
🖥️🔄📱Ideal for sharing between PC and Mobile / Mobile to Mobile

Cons
💾 Limited Storage
📳 No Web Based Sharing/Storage
🐘 Large texts are not supported
📷 Sharing depends on camera and depends on camera quality and background lighting
🖥️🔄🖥️ PC-PC Sharing is tough to achieve as you don't want to move your laptop and point it at another one 🙄. Well you can do a 🖥️🔄📱🔄🖥️ 

Paper is a PWA made with Angular,It uses local storage for storing notes, so you can't store more than 10 MB of notes, and sharing of large text via QR is not supported (seems to be a issue)
it uses QR code for sharing the note between devices.


If you like this share it/follow us on twitter, star this on github

{% twitter 1175447635970248704 %}

{% github jp1016/paper %}

Upvote on Product hunt
https://www.producthunt.com/posts/paper-6/

🤝 Contributing
Contributions, issues and feature requests are welcome! 😍
Object mindMap
Tags: beginners, javascript, object
Published: 2019-09-22 06:49:44

---
title: Object mindMap
published: true
description: Object Javascript
tags: beginner, javascript, object
---

## Javascript Object mindMap


https://thepracticaldev.s3.amazonaws.com/i/366zsjj4wll671alcrz6.png


![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/dvjbmlm1diymj6ifwxd0.png)
Sparkle - Master computer programming by spaced & repetitive learning.
Tags: mastery, programming, interview, flashcards
Published: 2019-09-22 05:05:33

---
title: Sparkle - Master computer programming by spaced & repetitive learning.
published: true
description: Master software programming leveraging flashcards (ANKI method)
tags: Mastery, Programming, Interviews, Flashcards
---

Perpetual Learning is the greatest constant in a Software Development career (at least if you do care about your career). The technology landscape changes too fast and we need to keep up. That’s just the way it is.

Software programming can be mastered by spaced repetition. And, flashcards are just meant to help you get there.

SPARKLE is free software that lets you create flashcards in respective sections and offers a whole lot more. Thanks for checking it out - https://sparkle.apricity.co.in

SPARKLE - Where you start as a novice; and, leave as a master!
Rich Dad Poor Dad Chapter 1 Lesson Notes:
Tags: devjournal
Published: 2019-09-22 05:05:12

---
title: Rich Dad Poor Dad Chapter 1 Lesson Notes:
published: true
description: Just wrote lesson I learned from the book Rich Dad Poor Dad
tags: #devjournal
---

⦁	Learn as much about money as possible especially how to make money work for me.
⦁	Money is one form of power but financial education is more powerfull
⦁	The Rich don't work for money, they have money work for them, poor and middle class work for money.
⦁	Just because an idea fails doesn't mean you should give up. Basically never give up and allways think of new ways to make money work for you.
⦁	When you get fed up and angry because life is pushing you around, don't just get angry at your boss or coworkers or job, push back at life which is the one controlling everything.
⦁	When you blame someone else saying my boss or job is the problem you don't learn anything. You have to admit you're the problem in order to solve it.
⦁	To solve the problems life throws at you, you need to use your mind. think of new possibilities, options, ways to grow.
⦁	Every person has a week and needy part of their soul/person that can be bought. So to overcome life's troubles one must conquer that momentary glory.
⦁	Most peoples price come from fear and greed.
⦁	Don't fear not having money, think logically and overcome that life problem.
⦁	While working to becoming rich never fear losing money. All things can be brought back but when you fear loss you get stuck.
⦁	When stuck with fear for finding money, ask your self will a job be the solution to this fear in the long run?
⦁	Master the power of money instead of being afraid of it.
⦁	Self inflicted fear and ignorance keep people trapped and poor.
⦁	By not giving into emotions you give yourself time to think and solve problems more easily.
⦁	Never exploring your dreams because of fear is cruel.
Simple automated interactions with Telegram Bots using MTProto (Pyrogram)
Tags: telegram, automation, mtproto, python
Published: 2019-10-06 17:48:39

---
title: Simple automated interactions with Telegram Bots using MTProto (Pyrogram)
published: true
date: 2019-09-22 03:03:42 UTC
tags: telegram,Automation,MTProto,python
canonical_url: https://blog.1a23.com/2019/09/22/simple-automated-interactions-with-telegram-bots-using-mtproto-pyrogram/
---

[Telegram](https://telegram.org) is a popular <abbr title="instant messaging">IM</abbr> platform that is famous for its openness. A lot of applications are being discovered with their public Bot API and User API. Exposed as an HTTP interface, the Bot API is more popular on Telegram, but to interact with a bot, we still need to expose its User API, which is using an original protocol named MTProto. Below is my simple code snipped that sends a message to a bot and mark its first reply as read, using [Pyrogram](https://github.com/pyrogram/pyrogram) — a Python wrapping of MTProto.


## What you need  


- Python 3.6 or higher  
- Telegram account  

## Install Pyrogram  

```shell
pip3 install 'pyrogram[fast]'
```

`[fast]` here means to use the C-based cryptography module for better performance.

## Telegram API key  

Get your own Telegram API key from [https://my.telegram.org/apps](https://my.telegram.org/apps), which will be used later.  

## The script

```python
from pyrogram import Client, Filters, MessageHandler, Message
from threading import Event

# Put your Telegram API key here
api_id = 12345
api_hash = "12345678901234567890abcdefabcdef"

# User to send message to
user = "botfather"
# Message content
command = "/help"

feedback_evt = Event()


def mark_as_read(client: Client, message: Message):
    client.read_history(message.chat.id, message.message_id)
    feedback_evt.set()


with Client("login", api_id, api_hash) as app:
    app.send_message(user, command)
    app.add_handler(MessageHandler(mark_as_read, Filters.chat(user)))
    feedback_evt.wait()
```

Change the highlighted lines accordingly.  

## First time use

Run the script with Python, and you should be prompted to log in with your phone number and login code. This is only needed on the first run.  

> Note
>
> Your login session data will be stored in `login.session` file. Keep this file as secure as your password.  

Now this script is ready to run. You can run this with anything you want, bash script, cronjob, or whatever that can call a command.  

The post [Simple automated interactions with Telegram Bots using MTProto (Pyrogram)](https://blog.1a23.com/2019/09/22/simple-automated-interactions-with-telegram-bots-using-mtproto-pyrogram/) appeared first on [1A23 Blog](https://blog.1a23.com).
DOM Property vs HTML Attribute in Property Binding
Tags: angular
Published: 2019-09-22 02:42:05

To gain more understanding of how Angular property binding works, we need to know the differences between DOM Property and HTML attributes. Property binding is a way to display a value comes from component to template. 

If we have this ordinary HTML,

```html
<input type="text" value="name"></input>
```

and if we want to bind a property to that in Angular, we wrap `value` with square brackets `[` and `]` such as:

```html
<input type="text" [value]="name"></input>
```

We have `value` and `[value]`. Regardless of the brackets, they look exactly the same but they are different things. 

What you must know is

1. In the first code, `value` is an HTML attribute. See [HTML Input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes).
2. In the second code, `value` in `[value]` is a DOM property. See [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement).

So, what Angular does in property binding is always target DOM property, *not* HTML attribute.


Does HTML attribute always have 1:1 mapping with DOM property?

The answer is no.
- Some of them have 1:1 mapping e.g `value`, `name`, `type`, `id`, `src`
- Some of them have 1:1 mapping with different name e.g. `tabindex vs tabIndex`, `rowspan vs rowSpan`, `colspan vs colSpan`
- Some exist only in HTML attribute e.g. `role`, `aria`
- Some exist only in DOM property e.g. `textContent`

# Custom Property
Angular allows us to have custom property either from directive or component. 

```html
<div [ngStyle]="{'font-size': fontSize}"></div>
```

`ngStyle` is a custom property comes from Angular directive. Others such as `ngClass`, `ngIf` and etc. 

Example for a custom component: 

```html
<student-list [students]="students"></student-list>
```

`students` is a custom property from component named `StudentList` that we have below

`student-list.component.ts`

```ts

@Component({
  selector: 'student-list'
  ...
})
export class StudentList {
  @Input() students;
}
```
Angular read from `@Input` of that component so it'll recognize `students` property.

The default behavior of Angular in property binding will always look for

1. Custom property from directive or component
2. DOM property

If Angular couldn't find the property from those two, it will trigger an error, for example we are trying to specify unknown property `initial` like below: 

```html
<input type="text" value="name" [initial]="initialValue" />
```

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/vkmh5vct27atvfxgwcej.jpg)


# Summary
Property binding in Angular always targets to DOM property instead of HTML attribute. In order to support custom property, Angular will look for custom property from directive or component then DOM property.
Downgrade About Dark Mode And Content Security Policy
Tags: ask, code, help, darkmode
Published: 2019-09-22 01:56:04

https://observatory.mozilla.org/

Observatory (grade checker by Mozilla) will downgrade score if website still use inline style or script.  

https://infosec.mozilla.org/guidelines/web_security#content-security-policy

How to fix this issue while dark mode toggle needs "onclick" to trigger and switch the light / dark mode?
GitLens: where have you been all my life!
Tags: git, gitlens, vscode
Published: 2019-09-22 01:36:24

I have been using Visual Studio Code more and more lately. I recently stumbled across [GitLens] (https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens) and I must say I am blown away by it.

If I want to know who modified a line last and view all the changes they made to a file, I simply do this:
![diffs](https://thepracticaldev.s3.amazonaws.com/i/vy6ym3cvtfmyeb98bq89.gif)

Now say I am interested in finding out all the recent changes from a source file, I simply do this:
![Recent diffs](https://thepracticaldev.s3.amazonaws.com/i/031f69gb110aqysm4d20.gif)

The ole git blame is there too:
![git blame](https://thepracticaldev.s3.amazonaws.com/i/azr8vjha9rtf9hpz4vhs.gif)

Now if I am interested in what has changed between 2 branches or tags, I can do this:
![Branch tag compare](https://thepracticaldev.s3.amazonaws.com/i/wfv0pj60yjmo8emmoks8.gif)

These are just a few of the great features. If you use git and Visual Studio Code, this extension is well worth a look.
Ezibo : Zambia's digital literacy launch
Tags: digitalliteracy, tech, productlaunch
Published: 2019-09-22 00:29:37

Asikana network in partnership with Facebook launched the E-zibo digital literacy on 12th September 2019. Ezibo literally means electronic knowledge and is derived from the lozi word "Zibo" which means Knowledge

The digital literacy program aims to promote online safety for school going pupils with a target audience of 13 - 19 year old learners. The program aims to reach 1500 learners in 30 schools across six provinces of Zambia.

This program will educate on how ton stay safe on the internet, and also educate learners on how to identify fake news, online bulling , fraud etc.
difflib - Finding close matches of strings from a list
Tags: beginners, python
Published: 2019-09-22 17:20:41

---
title: difflib - Finding close matches of strings from a list
published: true
tags: beginners, python
canonical_url: https://wangonya.com/blog/difflib/
---

Say we have a list of strings: `_list = [...,]` and user input `_input = '...'`, how do we find the items in `_list` that most closely resemble `_input`?

Python has a built-in package called [`difflib`](https://docs.python.org/2/library/difflib.html) with the function `get_close_matches()` that can help us.

`get_close_matches(word, possibilities, n, cutoff)` accepts four parameters:

- `word` - the word to find close matches for in our list
- `possibilities` - the list in which to search for close matches of `word`
- `n` (optional) - the maximum number of close matches to return. Must be `> 0`. Default is `3`.
- `cutoff` (optional) - a float in the range [0, 1] that a `possibility` must score in order to be considered similar to `word`. `0` is very lenient, `1` is very strict. Default is `0.6`.

An example from the [docs](https://docs.python.org/2/library/difflib.html#difflib.get_close_matches):

```
Python 3.7.3

>>> from difflib import get_close_matches
>>> get_close_matches('appel', ['ape', 'apple', 'peach', 'puppy'])
['apple', 'ape']
```

The above example can easily be modified to use a custom list `_list` for `possibilities` and user input `_input` for `word`.
Herramientas para la terminal de linux
Tags: ubuntu, terminal, bash
Published: 2019-09-21 23:16:08

# Un reemplazo para find 
Vamos, todos sabemos que find es complejo para utilizar 
https://github.com/sharkdp/fd nos aporta un buscador muy rápido y con múltiples opciones.

$ fd texto_buscado : busca desde el directorio donde estamos el texto_buscado

$ fd '[0-9]\.jpg$' ~ : todas las imágenes jpg en el directorio home. 

$ fd -e jpg -x convert {} {.}.png : llamando un binario y reemplazando los nombres de archivos

$ fd -x wc -l \; -e php :  la cantidad de lineas en los archivos php del directorio.

# Un navegador de history y directorios muy rápido.

[FZF](https://github.com/junegunn/fzf) : una  vez instalado se llama con alt +c o ctrl+r o ctrl+t

Gran herramienta que permite navegar con teclado directorios o el historial de comandos, filtrarlo mientras lo navegamos,  y muchas opciones más, al utilizar comandos como el anterior "fd" es mucho más rápido. 

Posee una ventana de preview que permite ir visualizando el contenido del archivo a medida que vamos cambiando en el selector de archivos.


$ fzf --preview 'cat {}'

Grandes herramientas para la consola.
Alexa, Movie mode on!
Tags: homeautomation, alexa, hardware, esp8266
Published: 2019-09-21 23:13:38

---
title: Alexa, Movie mode on!
published: true
description: Control Vankyo V600 using ESP8266 and Alexa to build a seamless home experience.
tags: homeautomation, alexa, hardware, esp8266
canonical_url: https://crondev.blog/2019/09/21/alexa-esp8266-remote-control/

---
Control Vankyo V600 using ESP8266 and Alexa to build a seamless home experience. Mimic any IR remote and replay it to control your devices using ESP8266 and Amazon Echo. [Read the full post here](https://crondev.blog/2019/09/21/alexa-esp8266-remote-control/). 

{% youtube wEBa5QbZWP0 %}