teleren/devto huggingface dataset:
Did JavaScript objects have static methods before ES6 class static methods?
Tags: help, javascript
Published: 2019-05-09 20:28:51

---
title: Did JavaScript objects have static methods before ES6 class static methods?
published: true
description: Static methods
tags: help, javascript
---

I saw a tutorial which used few javascript classes

```
class Products(){}
class UI(){}
class Storage(){}
```

I thought in the wild I'm not going to always be working with ES6 classes, so I should be able to recreate these with ES5 objects 

```
function Car(price) {
    this.price = price,
    this.someMethod = function(){ }
}
```

But the `Storage` class had only static methods which threw me of a bit 

```
class Storage {
  static saveProducts(products) { }
  static getProduct(id) { }
  static saveCart(cart) {  }
  static getCart() { }
}
```

I understand the difference, we can't directly access `Car.someMethod()` but we can access `Storage.getCar()`.

My question is, is this a good practice? And *most importantly* is this the way to implement this functionality without using classes

```
function Storage(){
  this.someMethod(){ }
}
Storage.prototype.someOtherMethod = function(){ }
Storage.theStaticMethod = function(){ }
```

Though I'm relatively new at JavaScript I have never seen static methods before ES6. I've always seen methods created through the prototype. Though it does pass by tests (the `Storage.theStaticMethod` works exactly as `static theStaticMethod` as far as I can tell) is my understanding correct? Why does it look wrong?
Créer son propre Bot Discord
Tags: javascript, node, npm, discord
Published: 2019-05-09 20:03:52

---
title: Créer son propre Bot Discord
published: true
description: 
tags: #javascript,#node,#npm,#discord
canonical_url: https://thepracticaldev.s3.amazonaws.com/i/v8cvyo9n5oaqiu9afu7o.png
series: Discord Bots
---

**Introduction :**

Avant de commencer ce Tutoriel, veuillez créer un dossier avec le nom de votre BOT n'importe où (de préférence sans espaces), ce sera le dossier où contiendra tous vos fichiers du bot.

_**Prérequis (A suivre dans l'ordre) :**_
    - Rendez vous sur le site [NodeJS](https://nodejs.org/fr) et de télécharger la dernière version. Exécuter le et installer le.
    - Si vous n'avez pas encore d'éditeur de texte, je vous conseille [Visual Studio Code](https://code.visualstudio.com/), téléchargez le et exécutez le sur votre ordinateur afin de l'installer.
    - Démarrez une invite de commandes (Win+R puis **cmd**), rendez vous dans le dossier où le bot est installé (cd chemin/de/votre/bot/), entrez **npm init** et entrez les informations demandés
    - Ensuite, entrez **npm install discord.js -save** puis attendez la fin du téléchargement.
    - Et enfin rendez vous dans votre dossier du bot et créez un nouveau fichier et nommez le par exemple **main.js**.


Nous avons donc effectué la partie installation des outils nécessaire pour le développement / fonctionnement de notre Bot. Mais il nous reste à créer encore le Bot via Discord.


**Création du Bot :**

Pour cela, rendez vous sur [Discord Developers](https://discordapp.com/developers/applications/) et après avoir été connectés, cliquez sur "Create and an application", donnez lui un nom puis rendez vous dans la partie "Bot", cliquez sur "Add Bot".


**Commencement du Code :**

Sur [Discord Developers](https://discordapp.com/developers/applications/), dans la section "Bot", copiez le Token du bot (c'est ce qui va vous permettre de controler votre bot, **A NE DONNER A PERSONNE**).
Rendez vous ensuite dans votre **main.js** et écrivez :
```Javascript
const Discord = require('discord.js');
const client = new Discord.Client();


//Toutes les actions à faire quand le bot se connecte
client.on("ready", function () {
    console.log("Mon BOT est Connecté");
})

// Répondre à un message
client.on("message", function (message) {
    if (message.content === "Salut") { // Lorsque "Salut" est envoyé
        message.channel.send("Salut l'ami !")
    }
})

client.login("TOKEN DE VOTRE BOT");
```


Et voilà, vous pouvez maintenant commencer à développer votre Bot !
Vous pouvez trouver d'autres tutos sur le site : https://g-ca.fr/tutoriels?tag=6&filter=date
Understanding Functional Closures
Published: 2019-05-09 19:58:10

---
title: Understanding Functional Closures
published: true
description: 
tags: 
---

While learning functional programming in JavaScript and Python, one of the hardest concepts to wrap my head around was the idea of closures. Every explanation I found only served to confuse me more so I decided to write a clear explanation with real code examples. 

#What Is A Closure?

##Inner Functions

The first step to understanding closures is understanding inner functions, i.e., a function declared within another function.

```python
def outer():
    x = 3
    def inner():
        print(x+5)
    inner()

outer() #prints 8 to the console
```
If we call the function `outer()`, we can see that it prints out 8. This is because the inner function has access to the variable `x`, which is in its enclosing scope. So the flow here is `outer` begins execution and sets the variable `x` equal to three. The next thing it does is define a function within itself which will print the result of adding 5 to `x`. It then executes the inner function and returns control to the main program.

##Returning The Inner Function

The interesting part happens when we return the inner function from the outer function instead of calling it.

```python
def outer():
    x = 3
    def inner():
        print(x+5)
    return inner

result = outer()  #here we save the returned value of the outer function to a variable
```
If you were to then print the result variable, this is what gets printed to the console:
```python
<function inner at 0x7f5e8c381668>
```
Interestingly, we now have a function object assigned to our result variable, which means we can actually call it by adding parentheses to it.
If we call our new `result()` function, we can see that it still prints out 8. This means that our result function actually remembered what was inside its enclosing scope (the outer function) even though the outer function finished execution long before we ever called our result function. And that's exactly what a closure is! It's the recalling of a variable declared in an enclosing scope even when the program execution has moved on and is no longer in that scope. You could even use the 'del' keyword to delete the `outer` function and everything inside it, but our `result` function would still remember the value of `x`.


#Why Use A Closure?

Using a closure can create some form of data privacy, since the main program has no access to anything declared inside the outer function. The only things that could have access to those variables are any functions defined inside the outer function itself. If you're a Python developer though, the most interesting application of closures by far is the concept of decorators.
Master your bash/zsh environment with Envirou
Tags: bash, zsh
Published: 2019-05-09 19:52:08

---
title: Master your bash/zsh environment with Envirou
published: true
description: A simple tool that helps you view and manage your env
tags: #bash #zsh 
cover_image: https://github.com/sverrirab/envirou/raw/master/screenshots/header.png
---

Years ago I created a simple utility to help me manage my environment variables - I wanted a quick way to view what was was my current configuration. What python virtual env am I using or what AWS profile is currently active?
This replaces `env | grep FOO` and `echo $PATH` completely for me since it tells me what profile is active.  

https://github.com/sverrirab/envirou

Years later I added the possibility to modify the environment as well so now I can simply do `ev prod` and then `ev dev` to quickly switch between configurations.  `ev` then tells me what profile is active and shows me all the important ones (filters out uninteresting variables such as `$TMP` or `$LC_CTYPE`).


Please try it out and see if can simplify your workflow!

{% github sverrirab/envirou %}
Don’t use progress bars in your CV
Tags: beginners, career
Published: 2019-05-09 19:07:07

Sometime ago, I got a chance to be involved in hiring process at my company and one thing I have noticed is that good part of applicants like to use progress bars in their CV’s to show the level of their knowledge.

![](https://thepracticaldev.s3.amazonaws.com/i/gzhi3bx7br3hx763q983.png)

My only question is how? How do you calculate the percentage of certain skill in the first place? Saying you know 80% of something usually means you know what or where 100% is. That further means you have more than 80% of that knowledge, because you know what you don’t know. Now, I don’t want to start a philosophical debate about circle of knowledge, so I’m gonna keep it short and light.

If you’ve graded your knowledge of HTML to 80% or 4/5 stars, are you really sure there isn’t some part of HTML reference, some trick or whatever, that you missed that can give or take away some of those precious points? 

Other thing is that you can’t easily rate something that’s constantly changing and improving.  Say you graded your CSS knowledge to 75%. CSS Working Group gave us CSS-Grid few months ago. Is your CSS grade now 50% or 71% or something else?

My advice is just don’t use it, it’s pointless to say the least.
Logary Rutta intro
Tags: logging, metrics
Published: 2019-02-22 16:00:44

---
title: Logary Rutta intro
published: true
description: Moving forward
tags: logging, metrics
---

[Logary](https://github.com/logary/logary) is coming up for its v5 release, so I figured now would be a good time to post my first blog entry at dev.to.

The last weeks I've been doing a lot of work on Rutta, Logary's log router, in order to make it easier to work with and more reliable. Logary is the core library and Rutta is a normal program/service that you can run in a docker container, and send logs to.

The lifecycle of the library is this:

 - Create a new Logary instance and configure it with where you want to send logs (Targets)
 - Get a `Logger` from the instance and log `Message`s to it

The lifecycle of Rutta is this:

 - Choose its mode:
    * Router for ingesting data and sending it to a target
    * Shipper for sending to a Rutta Router or a Rutta Proxy
    * Proxy to bridge subnets and forward logs

 - If router, you can now choose what it listens to and where to it sends:

    * Provide a number of "listeners", consisting of:
       - A transport (TCP, UDP, HTTP)
       - A binding (e.g. `[::]:8080`)
       - A codec (JSON, plain, binary, log4jxml, etc)
    * Provide a provide a number of "targets", in URI format, to send to, e.g.:
       - `stackdriver://./?projectId=my-gcp-project`
       - `console://./`

That's it; you can try it yourself with `docker run --rm -it haaf/rutta:5.0.0-rc.2.211cd352` — or use its [Helm chart](https://github.com/logary/logary/tree/master/src/services/rutta-helm-chart)

Happy logging!
Help needed on Deep learning design
Tags: help, machinelearning, discuss
Published: 2019-05-09 18:41:34

---
title: Help needed on Deep learning design
published: true
tags: help, machinelearning, discuss
---

I am learning pytorch. The use case is I wanted to give a personalised recommendation to users based on region. The problem is I needed to create multiple Graphs which are more or less the same(But not exactly equivalent) based on each region.

The solution some people suggested is to create separate graphs for each region and use them. But I am not convinced with this approach, because region may quickly grow.


 Can somebody help?
dev.to API: How to Turn DEV Posts into Postcards 📫
Tags: showdev, beginners, opensource, javascript
Published: 2019-05-09 18:28:48

I gain a lot from the DEV community. Whether it's useful tips, project ideas or just learning from other people's experiences. It's the only place I know that offers an equal platform for bloggers and programmers of all abilities, blended in a way that makes accessing interesting and relevant content seem simple.  

But for it to exist, the community relies on users who are active in sharing content that's new and engaging. This isn't an easy thing to do, and after almost 2 years as a member, it took until February before I felt confident enough to post publicly. However, once it was done, the positive reaction I received gave me the encouragement to write reflectively more often. 

Whilst my work involves tech, I'm not a developer. In fact, the majority of my professional network sits within education, making it less likely for colleagues or peers to encounter (or follow links to) the DEV site. So as I continued to write, it felt increasingly important to find a way of sharing content more flexibly, and one that reaches the broadest possible audience. Twitter helps, but how can DEV content be disguised to appear less 'technical'? 

**Answer: The dev.to API.** 🎉

But there's a catch. As far as I'm aware, the dev.to API is still experimental. Nevertheless, despite no official documentation, posts from other users provided enough information to test it out.

By adding a username parameter to the base URL (e.g. https://dev.to/api/articles?username=devteam), the API returns a JSON file containing metadata related to the articles from a specified user. After 'fetching' the data with a basic fetch() method, it's then available to manipulate with JavaScript and add to the DOM.

The snippet below shows how this works, printing the JSON to the console:   

```javascript
	<script>
		fetch('https://dev.to/api/articles?username=devteam')
		.then(function(response) {
		    return response.json();
		})
		.then(function(myJson) {
		    console.log(myJson)
		});
	</script>
```    

For me, this offers a perfect solution for adding DEV content to other sites (including my own), with extra flexibility for defining how it appears. For example, the CodePen below shows how each article can be presented as an individual card, styled in a way that matches the containing site. But also by using CSS Grid for the target div, any amount of posts can be added to the page whilst keeping the layout responsive.    

{% codepen https://codepen.io/danieladamharding/pen/GaJgLN %}

If you'd like to see how the API can be used to create a blog section of a portfolio website, please visit [danharding.co.uk](https://danharding.co.uk) or feel free to play with the CodePen.

And if you have any feedback, I'm always interested to hear it! 👨🏻‍💻
When to use browser push notifications
Tags: notifications, javascript, browsers
Published: 2019-05-09 17:57:16

---
title: When to use browser push notifications
published: true
description: Push notifications are a really nice feature, you can trigger a notification to the user device with any text that you want with title, image, body and it even can make the mobile device to vibrate (depends on the browser) when receiving it.
tags: notifications, javascript, browsers
cover_image: https://thepracticaldev.s3.amazonaws.com/i/uy7oc9djytf9stoicweb.png
canonical_url: https://lyubomir-angelov.com/when-to-use-browser-push-notifications/
---

Push notifications are a really nice feature, you can trigger a notification to the user device with any text that you want with title, image, body and it even can make the mobile device to vibrate (depends on the browser) when receiving it.

This is a really cool way to get the user attention when you have promotions, forgotten baskets full of products or you have published something new.

In order to use **push notifications** you have first to ask the users for permission, this is the small pop-up next to URL bar with buttons "allow" and "block":

![push notification request](https://thepracticaldev.s3.amazonaws.com/i/n8o7o56u00q5wf5uqicz.png)

How the majority of the websites are using this feature?

They make this pop-up appear immediately when you visit their site, you have no Idea what is this, for what you have to subscribe and for god sake I didn't do anything, what is this pop-up for? Ok, block it!

Most of the users are clicking **block** because you don't ask for permissions on the right time and you are just throwing away the chance to convert this user.

Instead of triggering it on initial loading, please do it on user action, for example after he read the article put a button to ask if the user wants to subscribe for more news. Or on saving an item to his wish list, you can ask him if he wants to subscribe to notifications in order to receive information when this item will be available.

Here you can find more information about what is possible and how to install it in [Google Dev website](https://developers.google.com/web/ilt/pwa/introduction-to-push-notifications)
The State of Angular: ng-conf 2019
Tags: angular, javascript, rxjs
Published: 2019-05-09 17:34:57

---
title: The State of Angular: ng-conf 2019
published: true
description: Auth0’s Sam Julien and Kim Maida spoke at ng-conf 2019 in Salt Lake City.
tags: #angular #javascript #rxjs 
canonical_url: https://auth0.com/blog/recap-of-state-of-angular-ng-conf-2019/
---

TL;DR Auth0's Sam Julien and Kim Maida spoke at ng-conf 2019 in Salt Lake City, Utah. You can find all of the videos on YouTube and check out my central repository for the speakers' slides.

The Angular community is special. I know all tech communities think that, but it's true with Angular. The Angular community prides itself on being welcoming, collaborative, and inclusive. The biggest symbol of the Angular community is ng-conf, the largest Angular conference in the world. It happens every spring in Salt Lake City, Utah at the Grand America Hotel. This conference is organized by community leaders, not by Google, and each year strives to be better, more educational, more diverse and inclusive, and, yes, more fun! It is also the time when big news is announced by both Google and community project leaders.

[Continue Reading 📖](→ https://auth0.com/blog/recap-of-state-of-angular-ng-conf-2019/?utm_source=dev&utm_medium=sc&utm_campaign=recap_angularngconf)
Adding permissions without permission
Tags: bash, linux, security, productivity
Published: 2019-05-09 16:46:58

---
title: Adding permissions without permission
published: true
description: Quickly add access by means of public keys with gitlab & github APIs
cover_image: https://thepracticaldev.s3.amazonaws.com/i/6u2bzsg5jj6z5vnfjgym.jpeg
tags: bash, linux, security, productivity
---

Gone are the days...

![public key?](https://thepracticaldev.s3.amazonaws.com/i/bgakjq3pfvxcp1xw0567.jpg)


So to avoid those conversations all together:

```bash
$ {
    for user in davecheney robpike ardan-bkennedy
    do
        curl https://github.com/$user.keys >> .ssh/authorized_keys
    done
  }
```

And start having these conversations:
![xzibit](https://thepracticaldev.s3.amazonaws.com/i/ag0b2u0b607qli4i1r22.jpg)


> This will also work with [gitlab](https://gitlab.com/derekahn.keys)
Developing a WordPress theme/plugin with wordup
Tags: webdev, showdev, wordpress, tutorial
Published: 2019-05-09 16:13:39

---
title: Developing a WordPress theme/plugin with wordup
published: true
description: Create and manage new WordPress projects with ease
cover_image: https://thepracticaldev.s3.amazonaws.com/i/wmae10nr8q8pd1vkvogj.png
tags: webdev, showdev, wordpress, tutorial
---

As the developer of [wordup](https://github.com/wordup-dev/wordup-cli), i would like show how easy and fast you can setup a new WordPress project with wordup

## What is wordup?

Wordup is an open-source development toolkit for setting up and managing your local WordPress Theme/Plugin development, so that you can totally focus on coding.

The wordup-cli is a command line interface written in nodejs and uses docker-compose.

It is available as a package on [npm](https://www.npmjs.com/package/wordup-cli) 


## Requirementes 

You need to have nodejs and docker installed on your system. 

## Init a new project

We are using wordup-cli as a local devDependency. 

To do that we will run the wordup-cli commands via `npx`.

`npx` belongs to npm and executes a command even if it's not installed on your system. 

To start your first project run (in a folder of your choice):

```bash
npx wordup-cli init
```

You will be guided to some questions. After that wordup will install automatically all containers and components. 

**Note:** If you use wordup-cli as a devDependency make sure to always use `npx` before every wordup command.

You can find the whole wordup documentation on [GitHub](https://github.com/wordup-dev/wordup-cli#commands)

## Start developing

Take a look at the newly created project folder in your editor. All files located in the /src folder belong to the WordPress plugin/theme you want to develop. 

Files outside of this folder belong to your project in general.

In the package.json file you can see the wordup project settings. 

## Export your project

After some coding you want to distribute your WordPress plugin/theme.

You can do that by running in your project folder:  

```bash
npx wordup export 
```

Wordup will export your /src folder to a zip file, based on `.distignore` and your wordup settings. 

You have also the posibilty to export your whole project. [Export docs](https://github.com/wordup-dev/wordup-cli#wordup-export-type)


## Happy Coding!!

For more information visit [wordup.dev](https://wordup.dev)

{% github wordup-dev/wordup-cli %}
Explain TimeComplexity Like I'm Five
Tags: python, complexity
Published: 2019-05-09 16:07:18

Hello Everyone, currently I was working on time complexity for python programs  ... I know about time complexity and yeah I reduced the complexity from a huge amount of seconds but still, I can't figure out some reasons i.e.,

1. Why adding some external functions(like logging.debug()) in my algorithm somewhere results in an increase the run time of an algorithm?

2. what if I choose a mathematical equation over iterations, assignment and return process. How can the time complexity affect our algorithm in this case?

3. Time complexity is an essential part to calculate but in some cases, it may affect the average clock and CPU usage by keeping one cpu busy. How to resolve this problem?
Help a brother's Product Hunt launch out!
Tags: ai, machinelearning, marketing, saas
Published: 2019-05-09 15:55:48

---
title: Help a brother's Product Hunt launch out!
published: true
description: We're launching one of our models on product hunt and need your help
tags: ai, ml, marketing, saas
---

![demo](https://thepracticaldev.s3.amazonaws.com/i/v0d7enkof2anryamqwnq.gif)

If you guys have a moment, I'd really appreciate some love for the SugarKubes Object Detection on product hunt https://www.producthunt.com/posts/object-detection-by-sugarkubes.

SugarKubes is a container marketplace. Think Github + Docker Hub with business models attached. I'm launching our first model today and could use some help :) 

Hugs, 

AP