teleren/devto huggingface dataset:
How I am Handling Promises - Traditional way vs Modern way
Tags: javascript, react, webdev, node
Published: 2020-11-01 04:20:48

Handling **Promises** are very hard now a days, but there’s an easy way to deal it!

**Traditional Way:** so many _then_ and _catch_ blocks 🥴

![old way of handling promises](https://dev-to-uploads.s3.amazonaws.com/i/58fn2bchrcmu8jwjux8o.png)
 
**Modern Way:** With the help of _async_ and _await_ we can get rid of _then_ and _catch_ blocks and improves code readability! 🥳

![modern way of handling promises](https://dev-to-uploads.s3.amazonaws.com/i/7forxcbz57k457efysye.png) 

_Comment your thoughts and share to your friends_
my first flask app for everyone to share something
Tags: flask, css
Published: 2020-11-01 04:13:04

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/egz9n78ifzzkwg5xtp37.png)
[Visit here!](https://tellmeeverythingflask.herokuapp.com)
[Github](https://github.com/ayushbasak/tell-me-everything)
I created this flask app **tell-me-everything**
for people to share something (literally any text you want) with everyone on  *THE WALL*.

It is a very simple app designed with CSS. Please do give it a visit! 😊

PS: 
I was 6 hours into the project and deployed it happily to Heroku, excited to share it with my friends when I realized Heroku restarts its free dynos frequently so SQLite was not the best database to work with (smh 🤷‍♂️). I am thinking about moving to PostgreSQL but I'm very lazy. 😜.
How to deploy your Jekyll Website on Github pages
Tags: github, git, opensource, ruby
Published: 2020-11-01 04:09:46

Hola amigos!
![How to deploy your Jekyll Website on Github page](https://miro.medium.com/max/820/0*N8RG95bKJnnF-wpL.png)

Hope you learnt something new in my previous post - __[How to install Jekyll on your local machine](https://dev.to/vkassingh/how-to-install-jekyll-on-your-local-machine-3l5o)__.

Well, today's post is a __HOWTO TUTORIA__L on __How to deploy your Jekyll Website on Github pages__ or __create a free blog on Github using Jekyll__

For this you need:
1. Github account
2. Ruby windows installer (as I am a windows user)
3. Jekyll installed 

If you want to learn How to install Jekyll, then you should read my previous post - [How to install Jekyll on your local machine](https://dev.to/vkassingh/how-to-install-jekyll-on-your-local-machine-3l5o)

Without any further due let's get started.

➜ First, open command prompt window on your system.

➜ Now check the version of Jekyll installed on your local machine.
__Jekyll -v__

__NOTE: If you haven't installed Jekyll. Then refer to my previous post which is also a HOWTO Tutorial to install Jekyll on your local machine - [How to install Jekyll on your local machine](https://dev.to/vkassingh/how-to-install-jekyll-on-your-local-machine-3l5o)__.

➜ Switch to the folder where you want to do your entire work.
__cd Documents__

Like here, I switched to my Documents folder as I want to do my entire work there.

➜ Now go to the terminal and run this command to create a new blog using Jekyll
__Jekyll new [blogname]__

__Jekyll new vkasblog__

Like here I created a blog named __vkasblog__ .

➜ Now again switch to the new blog "vkasblog".
__cd vkasblog__

➜ Now to see the new blog "vkasblog" on your server , run this command.
__bundle exec jekyll serve__

__NOTE__: For the first time, you have to use __bundle exec_ before __jekyll serve__. By the next time, you can use only __jekyll serve__.

➜ Now open this link to see your freshly created blog on your server.

Link: (https://localhost:4000/)

Now you can see your Jekyll blog on localhost: 4000.Congrats we did it together. If you get stuck on any point, ask in the comments sections.


__Connect with me on__
__Instagram__
https://www.instagram.com/p/CFqrvobFlsL/?igshid=j3lhn2qi3og0

__Twitter__
https://mobile.twitter.com/_SinghVikas_
Remote Work Reimagined?
Tags: question, remote, socialprogramming
Published: 2020-11-01 03:56:38

######*This might be a dumb idea, so call me out on this if it is. With that out of the way, here we go:*

I've been working on something that I'll be opening up to the community shortly. So, since I'm in the foundation phase, I've decided to start streaming my work through twitch (only one screen, my other is for "work"). Though no one watches my streams, it would be cool to have peer programming for pre-open source projects. Just a thought, but it might be fun. I could see this expanding into our workplaces. I could imagine it as an extension for Slack/Mattermost/etc, where you could turn it on or off. 

So tell me, is this even worth attempting to implement or is this just after another pipedream project? ...Or worse...it already exists... Anyone interested in "*#SocialProgramming* (can I claim that term?)" with my on a typescript lib using twitch or just watching and giving opinions on why my code is "all wrong"...lol. If anyone is interested, I can schedule sessions as an experiment .
Code Smell 13 - Empty Constructors
Tags: codenewbie, oop, beginners, coding
Published: 2020-11-01 03:44:55

*No-Parameterized constructors are a code smell of an **invalid** object that will dangerously mutate.
Incomplete objects cause lots of issues.*

> TL;DR: Pass the essence to all your objects so they will not need to mutate.

# Problems

- Mutability

- Incomplete objects

- Concurrency inconsistencies between creation and essence setting.

- Setters

{% post https://dev.to/mcsee/nude-models-part-i-setters-5c9i %}

# Solutions

1. Pass the object's essence on creation

2. Create objects with their immutable essence.

{% post https://dev.to/mcsee/the-evil-powers-of-mutants-1noo %}

# Examples

- Some persistence frameworks in static typed languages require an empty constructor.

# Exceptions

- Stateless objects. Always better solution than static class methods.

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/d9d34fad693fd4f6309d68636a5010e5)
```javascript
class AirTicket {
   constructor() {     
  }
}
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/2e8f884045798f699399bf1ba9c26ab2)
```javascript
class AirTicket {
   constructor(origin, destination, arline, departureTime, passenger) {     
     
  //...     
  }
}
```

# Detection

Any linter can warn this (possible) situation.

# More info

%[https://codexposed.hashnode.dev/constructors-demystified]

{% post https://dev.to/mcsee/the-evil-powers-of-mutants-1noo %}

{% post https://dev.to/mcsee/code-smell-10-too-many-arguments-4o67 %}

# Tags

- Essence

- Incomplete

- Mutable

# Conclusion

Always create complete objects. Make their essence immutable to endure through time.

Every object needs its essence to be a valid one since inception.

We should read Plato's ideas about immutability and create entities in a complete and immutable way.

These immutable objects favor bijection and survive the passing of time.

# Credits

Photo by Brett Jordan in Pexels

* * *

> In a purely functional program, the value of a [constant] never changes, and yet, it changes all the time! A paradox!

_Joel Spolski_

{% post https://dev.to/mcsee/software-engineering-great-quotes-26ci %}

* * * 

This article is part of the CodeSmell Series.

{% post https://dev.to/mcsee/how-to-find-the-stinky-parts-of-your-code-1dbc %}

*Last update: 2021/06/18*
5 Benefits of Using Open Source Intelligence
Tags: opensource, soft, datascience
Published: 2020-11-01 03:33:28



Open-source intelligence is a rather new concept that gained popularity as technology developed. Some many businesses and companies have open-source teams. These teams collect data from the internet and analyze it, making it possible to identify any possible threat of cyber-attack. This is essential for every business that wants to protect its data and gain trust from its customers. Because as technology develops, so do the teams of cyber hackers that wait for the perfect occasion to use those breaches in your security. <a href="https://dzone.com/articles/common-problems-with-open-source">anchor</a> 

Open-source intelligence comes with problems, not only with benefits. However, these can easily be counteracted by having more diverse projects and keeping up the pace with all these technological advancements. Open-source intelligence is a nice and helpful resource
We All Suck At Finishing Projects
Tags: advice, productivity, webdev
Published: 2020-11-01 03:19:52

We do! 

Go @ some of the biggest names out there in the industry. Ask them how many unfinished projects they have. They couldn't tell you. It's an uncountable number! Jobs are lost, families are made, boredom grows, interests change. Whatever the reason, sometimes it's just unavoidable. My point is, don't get discouraged because of this *very normal* thing that happens to everyone throughout their entire career. Just like imposter syndrome, this is something that will follow you forever. It's as common as weekends, and you have to learn to live with this reality.

Now, I'm not saying you should just give up and accept that you won't ever finish a project in your life, because you will. Out of the sea of ~80% complete app ideas in your private github repos that you'll make in your lifetime, you will look back and revel at the select few you've seen through to the end. Maybe you have one or two already, maybe you don't. The fact of the matter is you'll get there eventually. And when you do, you'll be saying the same thing I'm saying to anyone who needs to hear it.

I have a few bits of advice that I try and keep in mind whenever starting a new project. They help me stay on track and not lose sight of the finish line. I was going to publish one big post about all of them, but 1) I personally wouldn't want to read all of what I wrote in one sitting, and 2) This sort of advice isn't a "complete guide to" sort of thing. I'm always adding new lessons to my mental tool belt, so rather than editing my dumb-huge post every time I learn something new, I'd rather just make a new post about it. I'm starting with this particular tidbit because before even going into tips on staying on track, everyone needs to understand that unfinished projects are inevitable. So don't feel bad if you start to realize that the project you're currently on is not going to be a project you finish. The faster you can get over being disappointed in yourself, the faster you can get back out there and get coding. ✌
Learning How to Divide and Conqueror
Tags: ruby, computerscience, beginners, algorithms
Published: 2020-11-01 03:14:16

Last week I discussed the concept of [memoization](https://dev.to/123jackcole/learning-memoization-1gp7). This week I wanted to continue discussing concepts needed for dynamic programming and focus on using the method of divide and conqueror.

## **What Is Divide and Conqueror**

Divide and conqueror is an algorithm paradigm based on multi branch recursion. More specifically you take the initial problem and breaking it down into sub-problems until the sub-problems are simple enough to effectively solve. The solutions of the sub-problems are then combined to form the solution of the original problem.

Divide and conqueror is often used to solve problems such as sorting and multiplying large numbers. To show an example I'll show the implementation of merge sort and quick sort. Since I've previously covered these in a post on [sorting algorithms](https://dev.to/123jackcole/sorting-algorithms-in-javascript-5f4b) this time I've coded them in Ruby!

Remember that these methods are going to be following the following three steps.
* **Divide** the problem into sub-problems
* **Conqueror** the sub-problems
* **Merge** the results of the sub-problems into the final solution

In my implementation I use two functions to clearly illustrate the process of dividing and conqueror. The first method divides the input into smaller arrays that can easily be sorted. The next methods then sorts the smaller arrays and then combines the sorted numbers to return the solution.

![Merge Sort Divide](https://dev-to-uploads.s3.amazonaws.com/i/gpt6b93j0vrkxhil8u86.png)

![Merge Sort Sort](https://dev-to-uploads.s3.amazonaws.com/i/4lmkshm0uhx26cbls89d.png)

In the implementation of quick sort these concepts are also applied in a single method.

![Quick Sort](https://dev-to-uploads.s3.amazonaws.com/i/3glgqlj3bc08sn50ofn5.png)

Thanks for reading! The code for this lesson can be found [here](https://github.com/123JackCole/Divide-and-Conqueror).
Release 0.2 Part 4: A disappointing end to an otherwise interesting month
Tags: opensource
Published: 2020-11-01 03:09:32

Note to self: Don't work on issues pertaining to technologies that you have no experience with. Too much time was lost in this.

Last time, I wrote a name validation script to validate inputted names for a console application to simulate registration.

This time, we talk about my last PR. Not what I was hoping for, but honestly, it's for the best. So I was originally working on an issue regarding Jest, and Enzyme. The project was setup for testing and a test was needed. The problem, however, was that the webpack.config.js settings there were not configured for enzyme. This was important because I couldn't make any tests for the React component that I was supposed to work on for the issue. I decided to find another project to work on. I found this one:

https://github.com/ayaqdop/frontend/issues/10

It's react front-end project, but this time, the issue I worked on for this issue was different in nature. The issue was to make a contributors and code of conduct markdown files for the project. These 2 files are very critical files since they dictate how developers contribute to the project and exactly what is expected of them. The issue had a nice template to follow, however, I used multiple templates in order to write down the two files I made. I wrote the files down, made the commit, then made the PR.

https://github.com/ayaqdop/frontend/pull/18

What a month. I'm thankful for my prof, David, giving me the opportunity to work on real open-source projects. This release has open my eyes to open-source work, but it's also opened me up to the rigorous work that's required to work on projects. It's stuff that I can bring to life in my capstone project's implementation course (BTS630 next semester). I feel bad that most of my work may not be up to the caliber of other students in this course and I still have lots to learn about this type of work. Next month, we're going to be working on our 3rd release, which is to rewrite the front-end of the RSS feed website that last year's students wrote, Telescope. You can view that finished work here:

https://telescope.cdot.systems/ 

Living up to last year's students work will almost be a challenge that may be impossible for us to do. They wrote the entire website after all. We're going to move it from Gatsby.JS to Next.JS, which recently had a conference talking about Next v10. It's mostly written with React which is something that I'm familiar with. I'll certainly make mistakes along the way, but I believe that in life, you have to make mistakes in order to improve, and although my work this month may not match other student's PRs, I'm proud of what I've done. Marks will come and go, but the work will always stay with you. 

Next time, Telescope. The nerves are still getting to me. I hope I can make you proud, David. 

Small note: David actually quoted a piece of my blog on his Twitter account. I actually found out from another student. It was crazy. Next time, you got my permission to quote my name if you intend to use my words again, professor!
Complex Forms in Rails
Tags: ruby, rails, tutorial
Published: 2020-11-01 02:34:50

Rails offers all kinds of intuitive solutions for programmers, one of which is form helpers. In this post, I'll be breaking down the steps for creating a nested form - which is basically a form within a form. Formception.

When creating my first Rails project, I found myself searching for guidance on creating this type of form. While there are many sources that show you how to do this with a `has_many` association, I struggled to find examples for `belongs_to`. So, we will be working with a complex form for a joins table.

We're building a mood diary. We have two models to work with regarding our nested form: Entry and Emotion.

Entry is our joins table and so it's association is `belongs_to :emotion`, while Emotion `has_many :entries`.
When imagining the functionality of our form, we can conclude that we want to have the ability to create our Entry and either assign it an existing emotion or create a new one.

First, we want to use `accepts_nested_attributes_for` class method in our Entry model. This method defines an attributes writer for the specified association, in this case, Emotion.
Going along with the Rails penchant for convention over configuration, a good rule of thumb to remember when setting up nested forms is:
If the association 'belongs to' a singular model (e.g., emotion) we will maintain the singular form of reference. If the association 'has many' plural model[s] (e.g., entries) we will maintain the plural form of reference throughout our code.

![](https://i.imgur.com/DbqPMHsl.png?1)

Now we will need to modify our declared permitted parameters to accommodate the nested attributes. Following our example, we will add this to our EntriesController. In the code below I have added a key for association attributes, where the association is the relationship you want to 'nest' into your form. Put simply, it's the one you added to `accepts_nested_attributes_for`. This key holds the specified association's attributes that we want passed in.

![](https://i.imgur.com/UwBbMV3h.png)

Note: In this example, `:emotion_id` is included outside of `emotion_attributes:` - As shown in the Rails guide we can also use:
```
def entry_params
    params.require(:entry).permit(:content, emotion_attributes: [
         :id, :name
    ])
end
```
Finally, we are ready to create our form!

![](https://i.imgur.com/4NW9Cvyh.png)

The magic happens within the `fields_for` tag which, when associated with `accepts_nested_attributes`, renders a block once for every element of the association. We then use the `build_association` method which instantiates the object from the passed attributes and sets a link through the foreign key.

Note: Pay close attention to `build_association` method. Not to be confused with `collection.build`, which instantiates an object from the passed attributes and creates a foreign key. The latter is a method made accessible when declaring a `has_many` association.

Our final product (plus a bit of CSS) looks like this, with the option to select or create an emotion:

![](https://i.imgur.com/noG5u0g.png)
Una breve reflexión del Hacktoberfest
Tags: hacktoberfest, opensource, spanish
Published: 2020-11-01 02:24:43

---
title: Una breve reflexión del Hacktoberfest
published: true
tags: hacktoberfest, opensource, spanish 
---

Aunque no soy muy asiduo a escribir algunos párrafos, sí considero que hay que darse un pequeño tiempo para poder difundir un poco el famoso Hacktober Fest. Hoy recién finalizó el periodo de validación de los 4 PR que subí a Github.

### ¿Qué hice en estos 4 PR?

3 de mis 4 PR estuvieron centrados en un proyecto con Svelte, el cual comencé con la traducción al español. 

{% github TorstenDittmann/OmniaWrite %}

Esta traducción la hice antes del inicio del mes, así que no contó propiamente dentro del objetivo del mes. Sin embargo, sí realicé otras cosas que colaboraron. Por ejemplo, hablando con el dueño del repositorio, vía issues, logramos consensuar que MomentJS debía ser reemplazado del proyecto, ya que los mismos desarrolladores lo dieron por finalizado. Es así como llegué a migrar a [date-fns](https://date-fns.org/), y mediante su guía, pude entender acerca de cómo funcionan los códigos helper en svelte.

Aunque me quedaron cosas pendientes, propias de la implementación y que date-fns aún no provee, como un selector de idioma para la carga dinámica (o importar dinámicamente), pude comprender el cómo se relacionan los elementos de svelte con su lógica de implementación y la estructura del proyecto.

Este repositorio logró más avances por otros desarrolladores, como la lógica de pruebas de las unidades de traducción con un comando npm, o revisar los selectores (dropdown) para un buscador de palabras.

### Reflexión y conclusión
Aunque generalmente somos consumidores de Código Abierto (Open Source), nos dedicamos poco tiempo a colaborar y quizás ayudar a los desarrolladores más pequeños a conseguir que su código pueda ayudar a más personas. Es posible que no podamos comprender la facilidad que poseemos en poder colaborar, en especial siendo desarrolladores que vemos código todo el día.

La intención no debe ser dedicarnos tiempo completo a esta tarea, pero sí debemos considerar que ayudar un 10 % de tiempo a la semana o mes (2 a 3 horas), podría mejorar muchos diversos repositorios y desarrollos que podrían ayudar a miles de personas.

Por mi parte, este mes he descubierto que queda mucho camino por delante, y la organización de proyectos de este tipo (casi 100 % frontend) no hay que tenerle miedo, sino que respeto y organización a la hora de comenzar desde 0.

(imagen: https://commons.wikimedia.org/wiki/File:Father_and_son_learning_to_ride_a_bike!.jpg, dadblunders, CC-BY 3.0)
Solving LeetCode - Add Two Numbers
Tags: javascript
Published: 2020-11-01 01:54:24

# Question

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

Example 1:
```
Input: l1 = [2,4,3], l2 = [5,6,4]
Output: [7,0,8]
Explanation: 342 + 465 = 807.
```
Example 2:
```
Input: l1 = [0], l2 = [0]
Output: [0]
```
Example 3:
```
Input: l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
Output: [8,9,9,9,0,0,0,1]
```

Constraints:

* The number of nodes in each linked list is in the range [1, 100].
* 0 <= Node.val <= 9
* It is guaranteed that the list represents a number that does not have leading zeros.

## Let's Go!

Solve by using [PREP](https://dev.to/phariale/prep-technique-for-algorithms-in-js-5b0g).
* **P** -  Two non-empty linked lists representing two non-negative integers.
* **R** - Return a linked list of the two numbers added
* **E** - Examples provided by question. (See Above)
* **P** - See Below

Before I knew about Node List...
```javascript
var addTwoNumbers = function(l1, l2) {
    const reverseOfL1 = reverseArr(l1)
    const reverseOfL2 = reverseArr(l2)
    let list = []
    let carry = 0
    
    for (let i=0; i<l1.length; i++) {
        const sum = reverseOfL1[i] + reverseOfL2[i]
        if (sum > 9) {
            list.push(sum%10+carry)
            carry = 1
        } else {
            list.push(sum+carry)
            carry = 0
        } 
    }
        
    return list
}

function reverseArr(arr) {
    return arr.reduce((newArr,num) => {
      newArr.unshift(num)
      return newArr
    }, [])
}

```

Realizing my mistake and reading up on NodeList and Linked Lists. Answer below:

```javascript
let addTwoNumbers = function(l1, l2) {
    let dummyHead = new ListNode(0);
    let p1 = l1;
    let p2 = l2;
    let current = dummyHead;
    let carry = 0;
    
    while (p1 !== null || p2 !== null) {
        let x = (p1 !== null) ? p1.val : 0;
        let y = (p2 !== null) ? p2.val : 0;
        let sum = x + y + carry;
        
        carry = Math.floor(sum / 10);
        current.next = new ListNode(sum % 10);
        current = current.next;
        
        if (p1 !== null) {
            p1 = p1.next;
        }
        if (p2 !== null) {
            p2 = p2.next;
        }
    }
    
    if (carry > 0) {
        current.next = new ListNode(1);
    }
    
    return dummyHead.next;
};

```

### Conclusion

& Remember... Happy coding, friends! =)

#### Sources
* https://leetcode.com/problems/add-two-numbers/
* https://developer.mozilla.org/en-US/docs/Web/API/NodeList
* https://www.freecodecamp.org/news/implementing-a-linked-list-in-javascript/