teleren/devto huggingface dataset:
Elixir's Pattern Matching and ExUnit
Tags: elixir, testing
Published: 2020-02-24 22:42:46

While writing tests for a Phoenix app, I found something very strange.
Look at the code below (contrived tests for this example):

```elixir
test "the solution to 2 + 2" do
  assert 2 + 2 == 4
end

test "the solution to 2 + 2" do
  assert 2 + 2 != 4
end
```

Running `$ mix test` in my terminal, I got 2 tests, 0 failures. Strange! Did I write my assertions correctly? Yes I did, but I should be getting 2 tests, 1 failure. Why am I getting them both to pass?

This is Elixir's pattern matching at work! Looking at [ExUnit.Case
Module's code](https://github.com/elixir-lang/elixir/blob/v1.2.2/lib/ex_unit/lib/ex_unit/case.ex#L218), we define a `test` with a string. In the examples above, both test cases have the same string. Therefore, we will never match the second clause because the strings are the same. Because the first clause gets matched, and the first test passes, both tests will pass.

When I further examine the output of my tests, I can confirm this because I see that I get the warning `test/models/user_group_test.exs:23: warning: this clause cannot match because a previous clause at line 19 always matches`.

To get both tests to work as expected, I will need to make my test strings
unique.

```elixir
test "the solution to 2 + 2" do
  assert 2 + 2 == 4
end

test "the solution to 2 + 2 is not this" do
  assert 2 + 2 != 4
end
```

2 tests, 1 failure!
Auto form, Phantom menu | Module Monday 74
Tags: showdev, githunt, webdev, javascript
Published: 2020-02-24 22:27:14

---
title: Auto form, Phantom menu | Module Monday 74
published: true
description: Module Monday 74
tags: showdev, githunt, webdev, javascript
cover_image: https://res.cloudinary.com/component/image/upload/b_rgb:ffffff,c_lpad,h_350,w_800/v1582519560/form_cdrfpd.gif
canonical_url: https://guide.anymod.com/module-monday/74.html
---

## Open source mods

Mods are modules that can be used on any website, web app, or anywhere else. There are hundreds more like these built & shared on [AnyMod](https://anymod.com).

Click a mod to see it along with its source code.

## Auto form
Form with your contact information that works automatically. No backend required.
<a class="btn btn-sm" href="https://anymod.com/mod/form-with-footer-aldako?preview=true">View mod</a>
<a href="https://anymod.com/mod/form-with-footer-aldako?preview=true">
  <img src="https://res.cloudinary.com/component/image/upload/v1582519560/form_cdrfpd.gif"/>
</a>

## Phantom menu
Slide in menu based on the open source Phantom theme by Templated.
<a class="btn btn-sm" href="https://anymod.com/mod/menu-phantom-dknrro?preview=true">View mod</a>
<a href="https://anymod.com/mod/menu-phantom-dknrro?preview=true">
  <img src="https://res.cloudinary.com/component/image/upload/v1582519560/menu_q4b4qd.gif"/>
</a>

## Feature display
Showcase product features with this pre-styled block.
<a class="btn btn-sm" href="https://anymod.com/mod/feature-section-raldor?preview=true">View mod</a>
<a href="https://anymod.com/mod/feature-section-raldor?preview=true">
  <img src="https://res.cloudinary.com/component/image/upload/v1582519560/feature_qkhpfl.png"/>
</a>

## Image cards
Easy to use cards to quickly and professionally highlight your work.
<a class="btn btn-sm" href="https://anymod.com/mod/image-cards-with-call-to-action-llkoro?preview=true">View mod</a>
<a href="https://anymod.com/mod/image-cards-with-call-to-action-llkoro?preview=true">
  <img src="https://res.cloudinary.com/component/image/upload/v1582519560/card_yjck6t.png"/>
</a>

## Simple headline
A basic block of text that anyone on your team can edit without pushing code.
<a class="btn btn-sm" href="https://anymod.com/mod/simple-headline-nkolda?preview=true">View mod</a>
<a href="https://anymod.com/mod/simple-headline-nkolda?preview=true">
  <img src="https://res.cloudinary.com/component/image/upload/v1582519559/headline_bmmwem.png"/>
</a>


<hr>

I post new mods from the community [here](https://dev.to/tyrw) every (Module) Monday -- I hope you find them useful!

Happy coding ✌️
no-loop-func
Tags: eslint, javascript
Published: 2020-02-24 22:16:22

Continuing the eslint path, this was also a query I got earlier today.

The problem...

```js
function myFunc(complexObject) {
    // Checking validity of complexObject
    // checking in a nested property
    for(var i=0;i<complexObject.subArray.length;i++) {
        var item = complexObject.subArray[i];
        var subItemToWorkWith = item.lines.filter(function(line) {
            return line.header_id === complexObject.header.id;
        });
    }
}
```
ESlint will complain about filter having a function definition inside a for-loop which is dependent on a variable outside of the scope of the loop itself. To solve this you have to pass a pre-defined function as a callback-parameter to filter-function.

For this particular example it would be to define a function that takes a parameter for the header id of the complexobject, and then return the function that does the actual filtering.

```js
function myFuncHeaderFilter(headerid) {
    return function(line) {
        return line.header_id === headerid;
    };
}
function myFunc(complexObject) {
    // Checking validity of complexObject
    // checking in a nested property
    for(var i=0;i<complexObject.subArray.length;i++) {
        var item = complexObject.subArray[i];
        var subItemToWorkWith = item.lines.filter(
            myFuncHeaderFilter(complexObject.header.id)
        );
    }
}
```

Again, this makes the code cleaner, easier to read, as long as you group these things in the file or sort them out in a logical structure. It also increases the possibility of code-reuse as well as making it more testable and therefore maintainable.

References that mention the same thing;
https://github.com/eslint/eslint/issues/5044
http://linterrors.com/js/dont-make-functions-within-a-loop
consistent-return
Tags: eslint, javascript
Published: 2020-02-24 21:21:15

In the spirit of either learning something new every day or sharing/teaching someone something new, and in line with the theme of these past few days... Linting.

The first question today was to resolve the "consistent-return" error.

This happens when you have this kind of pattern;

```js
function myFunc(item) {
  if (booleanCheck) { 
    // do something
    return false;
  }
  // do something but not returning anything or returning void or anything but a boolean.
}
```

So the first thing you have to make sure is, is there a consumer of myFunc somewhere in your code that is expecting that false return state and enacting on it? Depending on what you find. If there is a consumer that enacts on the return of the function, then make sure that the function always does return a value of the same type.

If you used the return as a way to exit the function, then change it to being an if-else statement instead or if you don't really need to do anything in the block that returned false before, you can inverse the if-check.

```js
function myFunc(item) {
  if (booleanCheck) { 
    // do something but not continue with normal operations
  } else {
    // do something as per normal operations.
  }
}
```
alternatively

```js
function myFunc(item) {
  if (!booleanCheck) { 
    // do something as per normal operations.
  }
}
```

See: https://eslint.org/docs/rules/consistent-return
Error handling and Logging with Actix (Rust)
Tags: rust, webdev, microservices, tutorial
Published: 2020-02-24 21:05:27

[![Error handling and Logging with Actix (Rust)](https://img.youtube.com/vi/NHaWAWLgtAw/maxresdefault.jpg)](https://youtu.be/NHaWAWLgtAw)
The beauty of build in toLocaleDateString function
Tags: codepen
Published: 2020-02-24 21:02:55

---
title: The beauty of build in toLocaleDateString function
published: true
tags: codepen
---

<p>Did you know that the build in toLocaleDateString function in your browser can give you the name of a month in any language? Give you the time in - say Bangkok, Thailand, just by change the options passed to the method toLocaleDateString?</p>

<p>Play around with the options here.</p>

{% codepen https://codepen.io/netsi1964/pen/KKpNEao %}
I made a video
Tags: webdev, video
Published: 2020-02-24 20:49:31

Hey everyone - not sure if this is right for Dev, but I've been wanting to create some super-simple video tips to help people who manage their own website to improve their online performance. 

I bloody hate getting in front of the camera, but my wife (a LinkedIn superstar) convinced me it was important to raise my professional profile. I want to stop being seen as a freelancer and start looking a bit more professional. Apparently this is the way to do it.

Anyway, [here it is](https://www.linkedin.com/posts/netheavy_webdev-digitalmarketing-onlinesales-activity-6637601108137136128-90er).

I'd appreciate any constructive feedback you'd be happy to offer.

And I'd be curious to know if there's anything you guys are putting out that has helped you raise your professional profile. It's tough out there and I don't know about you, but believe you have any credibility to be telling others what to do is a big challenge - at least for me, who much prefers it here behind the keyboard.
The Hunt
Published: 2020-02-24 20:42:45

While running errands this morning, I shared the story of my job search with a salesperson where he and I’d developed a healthy rapport. He offered encouragement and I recounted the different opportunities in the pipeline. As I was leaving, an email arrived informing me that I was no longer being considered for a role following a screen call last Friday. The role had sounded exciting, working with intelligent search incorporating machine learning for recommendations, and I’d really enjoyed the conversation. However, it wasn’t meant to be. Then I saw another message that told essentially the same tale from a different company. 

I believe both organizations were genuine in their interest and there’s deep appreciation in their willingness to speak with me. Appreciation aside and to be fully transparent, seeing these messages in succession took my breath away. Just for a moment. I really wanted to pursue these opportunities further. But of course I did. I applied, so there was an obvious foundation of desire.

Regardless of what we want, events happen around us that frequently override our individual intent. To varying degrees, we can choose to contest this flow of events or go along with them. This choice is sometimes hard to view except in the former sense. The latter can sound weak or lacking in dedication. It’s also easy to paint a picture of the contestant unnecessarily bristling over circumstances well beyond their control. Neither slant is superior. They are equally potent and simultaneously meaningless, as the world will move on either way. 

So, it would seem a strategy invoking a focus on a high-level objective held in relatively persistent fashion would serve us best. At times, we may find ourselves more contentious, while in others moving fluidly. Both states serve a purpose, an appropriate state for a moment in time. If we review the progression of events nothing else could have happened because nothing else did. All possibilities collapsed in the present and fade in time to distillations we keep on record in memory, cognitive, digital, etc.

There’s a feeling of balance occurring in my perception. Other opportunities are still in play, some I’ve identified, and many more I’ll never notice. This dreamy vignette of threads from the journey I’m recording… Well, I trust it will offer someone else a sense of peace. Much as I found when I contentiously took my next breath. This after the last one had been stolen by unexpected news. Taking this intentional action, unsurprisingly new breaths continue to present themselves. Strange feels of synchronicity. Happy Monday, everyone!
Get hooked on Hooks.
Tags: react, hooks, redux, todayilearned
Published: 2020-02-24 20:41:52

When I was just entering the React-Redux world, the concept of hooks seemed daunting. *so I have to learn React AND Hooks to know React?*

![frustrated monkey on a laptop](https://media.giphy.com/media/hrRJ41JB2zlgZiYcCw/giphy.gif)

It's easy to get overwhelmed when you're not quite sure if your knowledge of vanilla JS will be enough to understand React and Redux, but Hooks are easier than they seem at first glance.

According to the [official documentation](https://react-redux.js.org/next/api/hooks),
>React's new "hooks" APIs give function components the ability to use local component state, execute side effects, and more.

What this means is that you can now favor using Hooks instead of functions like connect() or mapDispatchToProps(). We are able to do this because we are accessing the state directly, we no longer need aids to do so.

# Quick start on hooks

We'll be talking about useSelector() and useDispatch() in order to replace connect(), mapDispatchToProps() and mapStateToProps().

#####useSelector()
This is the equivalent of mapStateToProps. It takes a pure function as an argument that lets it know which part of the state you want to access.

It's also important to note that we're passing a second argument called shallowEqual. By doing this, we are letting it know that it has to use a shallow equality comparison.

You could also opt-out of adding it but rendering is always going to be more expensive than a quick selector check and returning new references will cause unnecessary re-renders whenever we dispatch any actions.

#####useDispatch()
This is the better version of mapDispatchToProps. To use it, we first need to invoke useDispatch into a variable and store it. After that, we're free to manually dispatch any redux action we have defined.

Using both of these hooks will discard the need for Redux's connect since we are pulling and dispatching directly.

# But how does it look like?

Given this quick snippet of a bookList component, we will transform from the traditional connect into hooks.

#####Using connect
{% gist https://gist.github.com/misselliev/6df930edb6f136ab5020023a8129fbf8 %}

#####Refactoring using hooks
{% gist https://gist.github.com/misselliev/797b352135a48d15ba432de3470c8823 %} 

What did you learn today?
![kitty coding master](https://media.giphy.com/media/LmNwrBhejkK9EFP504/giphy.gif)

Got something to add? Please feel free to [reach out](https://twitter.com/miss_elliev) for any question, comment or meme.
Namecheap is Offering Free domain name with Hosting
Tags: webdev, offers, wordpress, beginners
Published: 2020-02-24 20:40:48

Namecheap which is considered as the best domain registrar is offering free domain name (.website domain) for a year and one month of [free shared hosting to its users](https://namecheap.pxf.io/2NdJ0).
It is a wonderful opportunity to grab a free domain name with free hosting for testing purpose or hosting live projects. You don't need to miss this golden chance to get a free domain and hosting setup.
Namecheap has already offered EasyWP managed WordPress hosting trial at a negligible price but this time they are offering shared hosting completely free. 
The websites with .website domain name are not that popular but still useful for testing projects.
I have used Namecheap hosting for a year and there was no problem with that.
You can also read more about their managed WordPress hosting [here](https://holycoders.com/easywp-review-best-managed-wordpress-hosting/) which is based on my personal experience.

You must check this offer if you want to explore and learn about WordPress and SEO.
You can follow me to get more posts like this.

This post contains affiliate links by which I may get some commission.
First programming blog
Tags: software, fullstack, programmer, womenintech
Published: 2020-02-24 20:31:55

I hope everyone has a great weekend! I’m currently in the second module of the full-stack immersive software engineer program at Flatiron. Needless to say, I'm new to everything here. But I'm glad I'm not alone.

About me, I was pretty much just fresh out of college and decided that I cannot follow the major that I was very passionate about, Architectural Design. Changing my career path was definitely a big jump, yet I think it is a good time for me to challenge myself into the tech industry, where the most needed jobs are. Despite a lot of obstacles on my way, I'm amazed at how I've gone quite far in my programming journey at Flatiron. Everyone has a different story to tell - yet we all are here for the same purpose of making the best out of our ability to learn and to collaborate with others.

Why I'm here: I was encouraged by my cousin. Self-learning was very distracting for me. So I worked and saved up money for a coding bootcamp.

I love programming whenever a problem is solved, yet I also love programming when I can see myself struggling at a problem, kept hitting my head onto a wall, and in the end, when I finally understand the core issue of the problem, I always learn something new, learn how to solve a problem in a specific way or learn to approach the problem better.

So far, I've learned about Ruby, CLI application, learned how to connect the database with Ruby logics through Object Relational Mapping, using SQL and Active Record. I also learned how to construct and organize my data models using relationship models. From this knowledge, I was able to create my first CLI app project. Actually, I learned more than these and I can go on forever, but let's keep my first blog short. I'm still in the mindset of somewhere between a non-programmer and a somewhat-programmer. I hope I can move on from a somewhat-programmer to a somewhere-programmer soon. Hope everyone has a good week. Chao!
Vanilla JavaScript
Tags: javascript, css, html
Published: 2020-02-24 20:23:37

Hello,

In this post I just want to talk about what I view Vanilla JS is. I was told by some pretty respectable front end engineers that the meaning of Vanilla JS was writing JavaScript without a framework. I believe this to be the correct definition of the term. Most times when you think of vanilla flavored items you think, "Oh that's the plain flavor", or "That is boring." Well I feel the same about JavaScript. 

Nowadays there isn't a way to throw a rock and not hit at least 4 different frameworks that are all JavaScript related and are all supposed to benefit the developer in some way or form. I am not saying not to use a framework. Quite the contrary. I love using frameworks. They do indeed speed up development. But if you are struggling to understand why a certain concept doesn't work in XYZ framework then you should strip away what you are trying to write in that framework. Break the problem down and write it out using just plain ole JavaScript. From time to time I struggle with why something works with let's say React or why something doesn't work. When I remove React from the equation and try to solve it using vanilla JavaScript I see where I was going wrong. Now granted you can write just plain JavaScript in React and a lot of other frameworks but if you see that you are getting errors when using your framework of choice I suggest ripping that code out. Creating a basic web page with nothing more than some HTML, CSS and JS and see if you are getting the output you were expecting. If it works then you might have to figure out how to modify it to fit in with the framework you are using. Maybe it's expecting a different syntax of some sort. If it doesn't work then I would suggest that you are doing something incorrect and you need to spend some time on learning the basics of JavaScript. I am not in any way shape or form saying you are not a good developer. Please don't think that. I am only saying this because I have been there. As a matter of fact  I am currently working on a set of Vanilla JavaScript projects to reacquaint myself with the basics of the language. 

You can check out my vanilla javascript projects progress over here: https://github.com/RedHoodJT1988/VanillaJavaScriptProjects

Now back to what I was writing about. There has been talks that Vanilla JavaScript is actually JavaScript pre ES6(ES2015), which I think is wrong. ES6 JavaScript can still be written without the use of a framework. ES6 JavaScript still works in a browser just like it would if you were using it with Angular or React. Yes it needs to be transpiled to ES5 in order for some browsers to render the JavaScript but I would not say that Vanilla JavaScript is JavaScript before ES6. What are your thoughts about what constitutes the definition of Vanilla JavaScript? Do you think that it is any JavaScript code written without a framework like React or Vue? Or would you say that it is any JavaScript before ES6?
[Angular] How to get a moment after *ngFor DOM update
Tags: angular, rxjs
Published: 2020-02-24 20:19:04

---
title: [Angular] How to get a moment after *ngFor DOM update
published: true
description: I have *ngFor generated list in Angular and need to fire event on a list updates but after angular render all the elements. How to do that? 
tags: angular, rxjs
cover_image: https://thepracticaldev.s3.amazonaws.com/i/q3zz06gr1cgt1lxu965a.png
---

I have *ngFor generated list in Angular and need to fire event on a list updates but after angular render all the elements. 

How to do that? 

Watch the video to find out.

{% youtube N0jV0wfHTb4 %}

This video series will become a part of my future video-course with advanced techniques of mastering Angular/RxJS. Want to get a notification when it is done? Leave your email here (and get free video-course): http://eepurl.com/gHF0av
Phoenix Framework or Ruby on Rails
Tags: discuss
Published: 2020-02-24 20:06:46

Hello,
Recently, i read the article titled "7 reasons I switched back to PHP after 2 years on Rails" by Derek Sivers. He got good points but article is 13 years old. 😊

So, i asked about his view for today and he answered.
![Derek Sivers answer](https://i.imgur.com/anAWjqe.png)

What you guys think about that? Did you try and move to Phoenix form Rails? Do you really think phoenix could be next big thing?

If you want to read the article here is the link: https://sivers.org/rails2php

Thank you,
Best regards,
Tuna