teleren/devto huggingface dataset:
The this parameter in Javascript
Tags: javascript
Published: 2019-10-17 14:07:02

---
title: The this parameter in Javascript
published: true
description: The this parameter is automatically passed on function invocation
tags: javascript
cover_image: https://ferrariwebdevelopment.s3.us-east-2.amazonaws.com/assets/sydney-rae-geM5lzDj4Iw-unsplash.jpg
---

## The this parameter is automatically passed on function invocation.

When a function is invoked, an implicit parameter called `this` is automatically passed to it.

The `this` parameter is very important in Javascript and refers to an object associated with the function invocation, also called the *function context*.

What the `this` parameter points to is influenced by where the function is defined and by how the function is invoked.

As we have seen, there are different ways of invoking functions and each way sets this to a different context.

### Invoking functions

Functions can be invoked in four ways:

As a regular function:

```
hello()
```

As a method, which ties the function to an object:

```
person.hello()
```
As a constructor, which creates an instance of an object:

```
new Person()
```

With the `call()` and `apply()` methods:

```
person.apply(object, array)
person.call(object, argument1, argument2)
```

Note that in each case the function is invoked by adding a set of parenthesis right after an expression that evaluates to a function.

### Function invoked as a function

We invoke, or call, a function as a function when we add a set of parenthesis after a standalone function identifier.
Here's an example of how to invoke a function definition:

```
function animalSound() { return "Bark"; }
animalSound();  // => "Bark"
```
Here's an example of how to invoke a function expression:

```
const sound = function() { return "Moo" };
sound();   // => "Moo"
```

And finally, an example of using an immediately invoked function expression:

```
(function() { return "Meow" })();  // => "Meow"
```

Note that we enclosed the function expression in parenthesis so the Javascript interpreter didn't get confused by the syntax. We then added a set of parenthesis at the end, to invoke the function.
When invoked in this way, and the code is in non-strict mode, the this parameter is set to the global context, which is the window object.
When the code is in strict mode, the `this` parameter is set to undefined.

Here's an example of what the `this` parameter is set to as the global object when we print it out from inside the function:

```
(function() { 
  console.log(this);
  return "Meow"
})();
```

prints out:

```
Object [global] {
  global: [Circular],
  clearInterval: [Function: clearInterval],
  clearTimeout: [Function: clearTimeout],
  setInterval: [Function: setInterval],
  setTimeout: [Function: setTimeout] { [Symbol(util.promisify.custom)]: [Function] },
  queueMicrotask: [Function: queueMicrotask],
  clearImmediate: [Function: clearImmediate],
  setImmediate: [Function: setImmediate] {
    [Symbol(util.promisify.custom)]: [Function]
  }
}
```

Tomorrow we are going to look at what happens when a function is invoked as a method.
Daily Challenge #94 - Last Digit
Tags: challenge
Published: 2019-10-17 14:02:43

---
title: Daily Challenge #94 - Last Digit
published: true
series: Daily Challenge
description: For a given list [x1, x2, x3, ..., xn] compute the last (decimal) digit
tags: challenge
---

For a given list `[x1, x2, x3, ..., xn]` compute the last (decimal) digit of `x1 ^ (x2 ^ (x3 ^ (... ^ xn)))`.

*E. g.,*
`last_digit([3, 4, 2]) == 1`
because `3 ^ (4 ^ 2) = 3 ^ 16 = 43046721`.

*Beware:* Powers grow incredibly fast. For example, `9 ^ (9 ^ 9)` has more than 369 million of digits. `lastDigit` has to deal with such numbers efficiently.

*Corner cases:* We assume that `0 ^ 0 = 1` and that `lastDigit` of an empty list equals to 1.


***
_This challenge comes from Bodigrim on [CodeWars](<https://codewars.com/>), who has licensed redistribution of this challenge under the [2-Clause BSD License](<https://opensource.org/licenses/BSD-2-Clause>)!_

_Want to propose a challenge idea for a future post?  Email **yo+challenge@dev.to** with your suggestions!_
How do you find out about upcoming developer conferences?
Tags: discuss, webdev, conferences
Published: 2019-10-17 14:00:18

---
title: How do you find out about upcoming developer conferences?
published: true
description: How do you find out about upcoming developer conferences?
tags: discuss, webdev, conferences
---

I recently rejoined Twitter and am following a few developers who are posting pictures and tweets at developer conferences. Is there a list of upcoming events that I can reference? I'd love to attend one of these events one day.

These are the two that I found out about via Twitter, but now obviously too late for me to sign up, travel:
{% twitter 1184825498188341255 %}

{% twitter 1183761462017318912 %}
Kubernetes Patterns - The Batch Job Pattern
Tags: kubernetes, devops, docker
Published: 2019-10-17 13:10:22

Pods Common Pattern

A Pod may host one or more containers in which all of them are treated as one unit. There are several ways available to create Pods. For example:

Naked Pods: These are the Pods that you can create directly through a definition file. In general, this is not a recommended practice because a controller does not manage the created Pods. If the Pod is terminated or the node crashed, it will not restart or reschedule on a different node.
ReplicaSet: This controller is suitable for Pods that need to run continuously. It can restart when it fails. For example, web servers and APIs.
DaemonSets: This can be used to run Pods continuously. Also, it ensures that they run on every node of the cluster. A typical scenario for using DaemonSets is when you want to collect logs from the cluster nodes and send them to a log aggregator such as ElasticSearch.
As you can see, the typical pattern here is trying to have the Pod running at all times. This pattern is a common one: you always want your service to continue responding to requests. However, in some cases, you need the container to run once and then get terminated.

For More infomration about the Batch Job see: https://www.magalix.com/blog/kubernetes-patterns-the-batch-job-pattern
Kubernetes Patterns : The Cron Job Pattern
Tags: kubernetes, devops, docker
Published: 2019-10-17 13:07:55

My Cron Job Didn't Start On Time. What Should I Do?
In some cases, the CronJob may not get triggered on the specified time. In such an event, there are two scenarios:

We need to execute the job that didn't start even if it was delayed.
We need to execute the job that didn't start only if a specific time limit was not crossed.
In our first example, the job sends information to an API that expects this information every fifteen minutes. If the data arrives late, it's useless, and the API automatically discards it. The CronJob resource offers the. spec. startingDeadlineSeconds parameter:

.spec.startingDeadlineSeconds: If the job misses the scheduled time and did not exceed that number of seconds, it should get executed. Otherwise, it is executed on the next scheduled time.

otice that if this parameter is not set, the CronJob counts all the missed jobs since the last successful execution and reschedules them with a maximum of 100 missed job. If the number of missing jobs exceeds 100, the cron job is not rescheduled.
For More information see: https://www.magalix.com/blog/kubernetes-patterns-the-cron-job-pattern
My first open source contribution
Tags: opensource, hacktoberfest
Published: 2019-10-17 13:03:41

*Cover image credit to [@yancymin](https://unsplash.com/@yancymin) on [unsplash](https://unsplash.com/)*

For a while I've traversed GitHub and come up with excuses as to why I couldn't step in and help with a particular project. Some of the more frequent ones were: 

- I don't know that language well enough to be of any benefit. 
- They already have so many smarter people working on this, how can I bring value? 

These projects are more than just code - there's documentation, refactoring, testing...everything you would find in a normal project. Yesterday I finally stepped out of that comfort zone and took the plunge to make my first contribution - to dev.to!

![](https://media.giphy.com/media/nnFwGHgE4Mk5W/giphy.gif)

No, I don't know the project very well (it has some great docs). No, I technically didn't write any code. In fact my contribution was fixing lint errors and warnings for a particular subfolder. Sounds pretty straight forward, right? 

I was pretty nervous. Will it be approved? Did I do it right? I've fixed errors like this before... 

Then, the email dropped in my inbox. I felt like a little kid again. My PR was approved!! 

![](https://media.giphy.com/media/7eAvzJ0SBBzHy/giphy.gif)

It felt great to reach outside of that comfort zone and make an impact - even if my contribution was small. If someone out there reading this has been nervous to take the plunge, do it! Its rewarding and the community is happy to help.
Introducing seel — Build Docker images for your Node.js applications without effort
Tags: showdev, docker, node, devops
Published: 2019-10-17 12:55:53

I'm impatient and thrilled to introduce [seel][1], a command-line tool to containerize your **Node.js** application without effort. Not all developers are Docker/container experts and containerizing a Node.js application is not a simple task. For example, you will have to:

- Write a [Dockerfile][3]
- Follow the security best practices
- Build the smallest image possible
- Optimize the Docker build cache
- Define a tagging strategy (e.g. [semantic versioning][2], git commit hash)
- Write and maintain build and publish scripts

## Focus on your application, seel takes care of the containerization

To simplify this **seel** uses opinionated, but configurable, defaults based on the properties defined in the application `package.json` (e.g. name, version, bin/main scripts, description, ...).

The following screencast shows the containerization of an application created from scratch with `npm` (more examples are available [here](https://github.com/kevinpollet/seel#examples)).

{% youtube j01FVlT7tF0 %}

## Some features

- Tree shaking, only the entry module dependencies are packaged
- Automatic image tagging with [semantic versioning][2]
- Automatic image labelling (description, maintainer, version)
- Secure private package registry configuration
- Optimized Docker build cache

## What's next?

**seel** is actively developed and at its early stages. If you want to test it, file issues, request a feature or contribute some code, go to the [GitHub repository][1] and don't miss to give some 💚 and support with a ⭐.

{% github kevinpollet/seel no-readme %}

[1]: https://github.com/kevinpollet/seel
[2]: https://semver.org/
[3]: https://docs.docker.com/engine/reference/builder/
Stupid things I've done as a tech co-founder wannabe
Tags: startup
Published: 2019-10-17 12:51:56

case study 1 - [clickstyle.com.au](https://www.clickstyle.com.au) (just another two-sided marketplace)

- jumped at the opportunity too quick because I was too scared to work on my own ideas.

- tried to solve the problem I wasn't excited about.

- tried to get a .com domain so we could go global one day. ended up with a .com.au domain, and we still failed, in merely one country.

- had an "equity vs contribution" doubt since day 1, but didn't speak up, letting the resentment build up inside.

- rolled my own admin portal while being oblivious to things like [retool.com](https://retool.com/) and [react-admin](https://marmelab.com/react-admin/).

- spent time to learn yet another framework [meteor.js](https://www.meteor.com/) though I would be totally fine with the good old [express.js](https://expressjs.com/) (nothing wrong with meteor.js, nothing wrong with express.js either).




case study 2 - [fuutr.co](https://fuutr.co) (just another e-scooter app)

- jumped at the opportunity too quick (again) because the co-founder said a VC promised a 10m round as long as we got the MVP built, and I would be a CTO leading an army of engineers.

- tried to solve the problem I wasn't excited about.

- worked on the project fulltime, unpaid, meanwhile providing a family of 4 plus mortgage. thought I would be mentally tough enough, but got stressed out 4 months in.

- found out my co-founder was a natural hustler, thought it was indispensable to a successful startup, without realising I got hustled too.

- thought we could win city council trial over Lime with a pixel-perfect app and more feature set.

- rolled my own admin portal (again) while being oblivious to things like [retool.com](https://retool.com/) and [react-admin](https://marmelab.com/react-admin/).
The const issue
Tags: cpp, codenewbie
Published: 2019-10-17 12:46:48

TLDR: *always put `const` AFTER the element you want to specify as constant*

We all love `const` variables and parameters. They are, well, constant. You're sure they won't be changed by a side-effect of your code (or someone else's).
What you usually see in C++ is something like:

```
const int myVar(42);
```

This is pretty clear, right? `myVar` is stores an integer, 42 in this case, and this value won't change until we get out of the current scope. So if we put something like:

```
const int myVar(42);
myVar++;
```

your compiler will yell at you with something like `error: increment of read-only variable ‘myVar’`.

So far so good. But I once again stumbled across an issue using `const` that I, even with my 10+ years of experience, still haven't stuck in my head (but I hope that writing this down will help so I'll guess I should share it).

Let's say you want to declare a constant pointer to an integer. The no-brainer line of code that gets out is:

```
const int *myVarPtr;
```

Following the same logic as before, if I try to modify it:

```
int myVar(42);
const int *myVarPtr;
myVarPtr++;
```

the compiler doesn't complain! And it's normal because, if you stick to its definition, `const` applies to the element to its *left*, unless it's the first element. Then it applies to its *right*.
So what we declared earlier was actually a non-const pointer to a const integer. The original goal would be achieved with this code:

```
int * const myVarPtr;
```

I hate exceptions. This is the typical case where the exception makes the concept confusing. Now I just make sure I'm never in this case.

If you have only one thing to learn from this article it would be this: *always put `const` AFTER the element you want to specify as constant*.
Google Cloud Tools for Application Development
Tags: webdev, cloud, google, app
Published: 2019-10-17 12:38:11

---
title: Google Cloud Tools for Application Development
published: True
description: Top Google Cloud Tools for Mobile and Web App Development
tags: #webdev #cloud #google #app
cover_image: https://thepracticaldev.s3.amazonaws.com/i/s43fumrygjev1jc85pa2.png
---
Top 5 Google Cloud tools for web application development. Google gives a wide scope of instruments and administrations for its clients. As one of the top cloud suppliers, Google must stay aware of the aggressive idea of the cloud and discharge administrations to address the issues of its clients. Like AWS and Azure, there is a scope of Google Cloud apparatuses for clients to look over to help facilitate a portion of the pressure that accompanies the open cloud.

##Top 5 Google Cloud Tools for Mobile and Web App Development

Here are the top 5 google cloud tools for web application development and mobile app development.

###1. Google Cloud Deployment Manager

Designers use content to computerize ordinary assignments and add proficiency to their usage. Framework as code (IaC) is the most complete alternative for scripting on the grounds that it makes a deliberation layer among applications and the basic foundation to mechanize every single operational undertaking.

Google's IaC tool, Google Cloud Deployment Manager, conveys the foundation as a repeatable, decisive code. It can utilize around three record types for every Google Cloud Platform (GCP) sending - an arrangement document in YAML, an outline document and a layout record in Python or Jinja. The arrangement document is the main required record, the other two sorts are discretionary.

The design record is the source code for the Deployment Manager, which audits the document's substance and conveys setups dependent on predefined layouts and condition requirements. These design documents are part of two segments: imports, which are a rundown of records utilized by the setup, and assets, which records all the GCP administrations to be conveyed.

As of now, Deployment Manager doesn't bolster all Google Cloud devices and administrations, yet it works with the vast majority of the center contributions, including Compute Engine, BigQuery and Cloud Storage. While it is a free device, standard charges apply for any related administrations it sends.

###2. Google Cloud Anthos

Endeavors that move to the cloud regularly battle to adjust their inheritance applications to cloud-local administrations. Previously, this issue was tended to however virtualization, yet regarding the cloud as simply one more facilitating condition implied doing without advantages around proficiency, versatility, and adaptability. With Google Cloud Anthos, Google clients don't need to go that course.

Google Cloud Anthos is a cloud-freethinker holder condition that utilizations Kubernetes and Istio for compartment organization and traffic the executives, individually. It's a product stack that can likewise keep running on an association's current equipment.

###The full article source: https://www.decipherzone.com/blog-detail/google-cloud-tools
dotenv but 3 lines of ruby
Tags: ruby, bash
Published: 2019-10-17 12:28:34

*edit: Thanks to Ben Curtis for inspiring me to cut this from 7 lines to 3.*
*edit2: More complex regexp to handle multiline vars.*

Make an executable file with the following contents:

``` ruby
#!/usr/bin/env ruby

regexp = /^(?<a>\w+)=(?:'(?<b>.+?)'|"\g<b>"|\g<b>)$/m

ENV.update File.read(".env").scan(regexp).to_h if File.exist?(".env")
exec(ENV, *ARGV)
```

Make an alias. Here is one with bundle exec also included.

`alias be="/path/to/executable bundle exec"`

Make an `.env` file.

`echo HELLO=WORLD > .env`

Run `be bash -c 'echo $HELLO'`

*edit3: this has an added benefit of being language independent over the regular ruby dotenv as this is a shell program and ruby dotenv runs inside your ruby program.*

*edit4: do the following to have a .gitconfig like transversal up the parent directories.*

``` ruby
#!/usr/bin/env ruby

require 'pathname'
env = Pathname.pwd.ascend.map{|x| x.join(".env")}.select(&:exist?).map(&:read).reverse.join

regexp = /^(?<a>\w+)=(?:'(?<b>.+?)'|"\g<b>"|\g<b>)$/m
ENV.update env.scan(regexp).to_h
exec(ENV, *ARGV)

```
Guide for Applying Financial Aid in AI For Everyone
Tags: machinelearning, python
Published: 2019-10-17 11:21:33

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



###**Hey Everyone! The main reason is to help everyone who is having difficulties. Today I'll be sharing step by step procedure to apply financial aid on AI for Everyone. So let's get started.**

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


**Click on Financial Aid available next to enroll now button.**


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


**Click on Continue to the application, Note: by clicking on enroll and starting learning today will not allow you to apply financial aid.**


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


**Agree by clicking both options and type I agree to the terms above.**



**So the actual application for financial aid starts here**


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


**Fill out all the required information.**


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


**Here you have to write 2 Paragraphs of 150 words each.**


**Tip:** You can calculate words from here: https://wordcounter.net/


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


**Choose No for a low-interest loan question and then explain why you chose no in 4 to 5 lines**


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


**After Submitting the application you will receive an email mentioning that they have received your financial aid and it will take 15 days to get approved.**


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


**Now you can go to the course and complete all the quizzes to get your certificate.**  

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

I've completed AI for Everyone scoring 100% in all quizzes. Best of Luck to everyone. You can verify the certificate here: https://www.coursera.org/account/accomplishments/certificate/4NPZ6295T8QR


##Note: Many of you still have the issue that they have been enrolled in the course so what should they do.

##Umm, let me think!! 

##Yeah. You just have to delete your account. Go to profiles > Delete Account.

##And recreate your account but follow the process that I mentioned above. Don't enroll again. If you want to watch the course, Register it with another email account. Simple! and wait for 15 days to get your financial aid approved.


If you still have any queries. You can message me @tahaadotdev on Instagram. I'll try to help everyone I could.
 
Happy Coding!!
Postman-Newman, wherever you go.
Tags: testing, spring, postman, apitest
Published: 2019-10-17 10:47:11

Postman-Newman

{% github https://github.com/postmanlabs/newman no-readme %}

I have been writing Postman-Newman tests for a couple of years now.
A new carrier move for a software developer will give new challenges to solve. But most of these new challenges could be resolved using a solution/framework/process which he/she is familiar with. 


In my case when I moved to `FREE NOW`(earlier `mytaxi`), there were projects being migrated to Spring Cloud Config. There is documentation on `Steps to migrate` and clearly mentioned do's and dont's.

There were mistakes during past migrations and projects are being misconfigured. However, software engineers learn from mistakes and we thought of some process in place for some kind of identification, later notification and finally rectification.

This is when we came up with `The Hero` (Postman-Newman).

The test or collection of tests includes some bunch of API tests that check whether the configurations are correct or not.

{% github https://github.com/jango89/postman-test-validate-spring-cloud-configuration/  %}

### Why am I so in favor

1. Only need to know Request URI to test.
2. No basic knowledge is required to write assertions. Of course, we write assertions using javascript however, with an effective documentation there is a very less knowledge curve.
3. Easy to plugin the tests to various environments (automated build platforms, docker, linux, mac).