teleren/devto huggingface dataset:
Exploring Clojure: HashMap 🤠🔍
Tags: todayilearned, clojure, todayisearched
Published: 2019-10-22 02:32:43

## How is it working? 
**Like a dictionary** ... Basically, a **HashMap** allows you to store items with identifiers. 
They are stored in a table format with the identifier being hashed using a hashing algorithm.
Typically they are more efficient to retrieve items than search trees etc.. 
It's commom represented by `{key:value}` syntax.

A **HashMap** is a collection that maps keys to values. They have various names in other languages; Python refers to them as **dictionaries**, and JavaScript’s **objects** essentially work like **hashmaps**.


You can see more  about **HashMap** [here](https://en.wikipedia.org/wiki/Hash_table).

# How I can use this on Clojure?
  
*Clojure* works with a syntax where we first define what we are going to do, that is, the action and then what we want to pass to it, very similar to the mathematical functions.
  
So we have two ways to define a HashMap, for this  let's assume we have a stock of which we have 2 backpacks and a t-shirt.

# Dumb way 
![](https://media1.tenor.com/images/1875464c214d0d8b3bc5f12e537e5cc3/tenor.gif?itemid=7296218)
```clojure
(def store {"backpack" 2 "t-shirt" 1})
(println "We have" store)
```
This way isn't the best because it's implements a *string* as *key*, the most correctly is the use of *keyword*, let's see how we use in *Clojure*.

# The correctly way 
![](https://media.giphy.com/media/d3mlE7uhX8KFgEmY/giphy.gif)
```clojure
(def store {:backpack 10 :t-shirt 5})
(println "We have" store)
```
Why I need keyword? Well, unlike strings, keywords can be used as functions to extract values from a **hashmap** no need for `get` or `nth` !

Using only string will retrieve to us an exception when we try to access like example above
```clojure
("backpack" store)
```
This returns an **ClassCastException** `java.lang.String cannot be cast to clojure.lang.IFn`

But when we use the correctly way returns to us exactly value of keyword we access
```clojure
(:backpack store)
;returns 2
```

# Bonus track 🎉🎊
![](https://media.giphy.com/media/XR9Dp54ZC4dji/giphy.gif)
##   Handling hashmaps
In Clojure symbols like array, hashmaps, etc... are immutable, so when we handle a value then return to us a clone of the symbol with a modified value

### Assoc (adding a :key and value)
```clojure
(def store {:backpack 10 :t-shirt 5})
(println (assoc store :pen 2)
;returns {:backpack 10 :t-shirt 5 :pen 2}
```
### Dissoc (remove a :key)
```clojure
(def store {:backpack 10 :t-shirt 5})
(println (dissoc store :t-shirt)
;returns {:backpack 10}
```

### Update (using a function to update our hashmap)
```clojure
(def store {:backpack 10 :t-shirt 5})
(println (update store :backpack inc))
;retunrs {:backpack 10 :t-shirt 6}
```

  
Just for today, anything from hello in the comments to discuss this wonderful language 🍻
Why Yes, I’ll Accept Those Nested Attributes
Tags: rails, codenewbie
Published: 2019-10-22 02:13:55

Building forms in Rails has been a fun exercise of demystifying what happens behind the scenes on your favorite sites. Those fun quizzes you’ve answered and comments left on a blog post are being collected by companies and saved to a database, to be used for whatever purposes later on. Good times. 

Forms can be simple endeavors, such as a generic search form or a form to update your account profile page. But oftentimes, forms are complex where you may need to update more than a single object at a time. 

Let’s say you have a form that allows you to create a trainer and its new Pokemon at the same time.

![pokemon gif](https://66.media.tumblr.com/tumblr_lzpu4cIKBh1rn95k2o1_500.gifv)

{% gist https://gist.github.com/kat-star/88986be334ccddc3621d69280b8f323d %}

With Active Record, it simplifies this process by allowing you to save attributes on associated records through the parent model using the accepts_nested_attributes_for class method. **In a one-to-many relationship, the accepts_nested_attributes_for method always lives on the parent/has_many model.**

By default, nested attribute updating is turned off so you will have to enable it using accepts_nested_attributes_for. By using this Active Record macro, it will add a new writer method to your model that will be named after the association. 

     pokemons_attributes=(attributes)

Your trainer model should reflect the has_many Pokemons relationship.

     Class Trainer < ActiveRecord::Base
         has_many :pokemons
         accepts_nested_attributes_for :pokemons
     end

Your controller should be updated to declare the permitted parameters before you pass the parameters to the model.

{% gist https://gist.github.com/kat-star/4a3159d198cc208653ec730614cfa1ba %}

As for when you might need to write a custom association writer method, #accepts_nested_attributes_for is not able to help us avoid duplicates. For the purposes of this exercise, a trainer can only have one Pokemon of the same name, just like the Pokemon universe hero Ash Ketchum.

Our custom method, which will be written in the trainer model, will use the Active Record query method find_or_create_by to look to see if that Pokemon already exists in the database, and if not, will instantiate that Pokemon for us and associate it to our trainer by adding it to the trainer’s Pokemon collection.

{% gist https://gist.github.com/kat-star/fc7158232fc4312d0332ebf7c9378c7a %}

**An important thing to note is that accepts_nested_attributes_for and custom setter methods are not necessarily mutually exclusive.**  You will have to evaluate the needs of your specific use case and go with the approach that makes the most sense for your application. 


[Active Record Nested Attributes](https://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html)
[Basic Nested Forms](https://learn.co/lessons/basic-nested-forms)
Day 16 : How Far
Tags: hiphop, code, coding, lifelongdev
Published: 2019-10-22 01:34:48

_liner notes_:
- Saturday : Radio show day. Had a great time. You can listen to recording at https://kNOwBETTERHIPHOP.com

![Our show episode cover graphic of a manmade volcano with text saying October 19th 2019 and Thank you Elijah Cummings](https://thepracticaldev.s3.amazonaws.com/i/3w1svhe2wjz8rsfa4xxg.jpg)

- Sunday: Got more done than I planned. haha I originally thought I would do some post radio show work, attend the station's staff meeting and then go watch "Dolemite is My Name" (Great movie by the way!) While waiting for the station meeting, I was able to start adding keyboard navigation to my personal site. I had some time between the meeting ending and the start of the movie, so I finally just scrapped the Git repository I had before for my personal site and just started over again.

- Professional : Today, started off with a whirlwind. Someone found some inconsistent wording in the documentation when the software was upgraded, so I fixed it and did a pull request. Also had to set a Gravatar image for our website. No matter what I did, I could not get the image to upload successfully to the website. After trying every option, I used my personal laptop and it worked on the first try. Worked with a team member to get the pull requests for the tutorial reviews I did a couple of weeks ago finalized and merged into the master branch. This marked my first pull requests being merged into master! Not only one, but like 3 pull requests! Even though this is the start of my fourth week, I'm happy with how far I have come. Rest of the day, I went through the review of the draft of my Use Case write up. Got some really great feedback.

- Personal : After work, spent some time on Twitter. haha Also had an Orlando Developers board meeting. Watched some coding videos and researched some technology for some upcoming personal projects. Re-familiarized myself some old side project code that I'll be reviving.

![Arial view of Brocton, England](https://thepracticaldev.s3.amazonaws.com/i/eaa7kts4cj1bwhdz95ev.jpg)

Tomorrow, I'm hoping to refactor some code for the Application I made for work. Learning more about React Hooks and implementing it into what I have. Got a couple of meetings, so not sure how much dedicated coding time I'll get.

Have a great night and day tomorrow!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube TQ7smE3dZug %}
Using Bunyan with Sequelize
Tags: javascript
Published: 2019-10-22 00:36:57

---
title: Using Bunyan with Sequelize
published: true
description: Using the logging option in Sequelize
tags: Javascript
canonical_url: "https://thomasstep.com/blog/using-bunyan-with-sequelize"
---
While trying to use Bunyan logger with Sequelize ORM, I ran across [this issue on GitHub](https://github.com/trentm/node-bunyan/issues/350) that I tried to use to solve my problem. It worked and the error that I was getting before was not there anymore; however, it was giving me extra information that I did not necessarily want. The information it gave me was about attributes and other options in Sequelize. I did not want to see that every time something was logged in Sequelize though. After some more digging, I learned that the `logging` option in Sequelize just takes a function that it passes a message into to be logged. I did a quick and dirty fix to this by creating a function with a message parameter and logging it with Bunyan. It looks like this:

```

const logger = (msg) => {
  log.info(msg);
};
...
  logging: logger
...

```

The `logging: logger` part goes into your options object that's passed in during connection. I had not seen this solution anywhere, so I commented on the issue thread and thought I would share here as well.
Animated headline, Placeholder page, Code highlighting | Module Monday 60
Tags: showdev, githunt, webdev, javascript
Published: 2019-10-22 00:15:33

---
title: Animated headline, Placeholder page, Code highlighting | Module Monday 60
published: true
description: Module Monday 60
tags: showdev, githunt, webdev, javascript
cover_image: https://res.cloudinary.com/component/image/upload/b_rgb:ffffff,c_lpad,h_350,w_800/v1571700593/headline_owct91.gif
canonical_url: https://guide.anymod.com/module-monday/60.html
---

## Everything below is open source 
It's free to use 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.

## Animated headline
Fade in and down intro content section.
<a class="btn btn-sm" href="https://anymod.com/mod/headline-section-ralbmd?preview=true">View mod</a>
<a href="https://anymod.com/mod/headline-section-ralbmd?preview=true">
  <img src="https://res.cloudinary.com/component/image/upload/v1571700593/headline_owct91.gif"/>
</a>

## Placeholder page
Easily start collecting emails before your official launch.
<a class="btn btn-sm" href="https://anymod.com/mod/coming-soon-landing-page-llookd?preview=true">View mod</a>
<a href="https://anymod.com/mod/coming-soon-landing-page-llookd?preview=true">
  <img src="https://res.cloudinary.com/component/image/upload/v1571700597/eventually_j6mgpl.gif"/>
</a>

## Code highlighting
Automatically format your blocks of code on any page.
<a class="btn btn-sm" href="https://anymod.com/mod/formatted-display-html-css-js-etc-akbra?preview=true">View mod</a>
<a href="https://anymod.com/mod/formatted-display-html-css-js-etc-akbra?preview=true">
  <img src="https://res.cloudinary.com/component/image/upload/v1571700593/code_v3vcds.png"/>
</a>

## Image hue changer
Upload an image and display it with edited hue.
<a class="btn btn-sm" href="https://anymod.com/mod/image-hue-change-dkklrn?preview=true">View mod</a>
<a href="https://anymod.com/mod/image-hue-change-dkklrn?preview=true">
  <img src="https://res.cloudinary.com/component/image/upload/v1571700593/hue_f0n9oi.gif"/>
</a>

## Transitive side nav
Side navigation element based on the Transitive theme
<a class="btn btn-sm" href="https://anymod.com/mod/navbar-llkrla?preview=true&dark=true">View mod</a>
<a href="https://anymod.com/mod/navbar-llkrla?preview=true&dark=true">
  <img src="https://res.cloudinary.com/component/image/upload/v1571700593/sidenav_alltaz.gif"/>
</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 ✌️
Good news, my project got 8k GitHub stars.
Tags: opensource
Published: 2019-10-22 00:09:18

I built it for fun, but this is truly a milestone for me. Thanks to all the lovers.

https://github.com/unbug/codelf

![image](https://user-images.githubusercontent.com/799578/67251749-add7ef80-f4a2-11e9-9482-ead3cc3a0c3d.png)
NPM - Cannot read property "match" of undefined
Tags: npm, troubleshooting, errors
Published: 2019-12-17 13:48:06

---
title: NPM - Cannot read property "match" of undefined
published: true
date: 2019-10-22 00:00:00 UTC
tags: npm, troubleshooting, errorhandling
canonical_url: https://stephencharlesweiss.com//2019-10-22/cannot-read-property-match/
---

When trying to run an `npm` command, you can’t install the packages, you may get the error:

```shell
 stephen  ~/_coding/remine/revolution   master  👉 npm run setup

> revolution@0.0.1 setup /Users/stephen/_coding/remine/revolution
> lerna link && lerna bootstrap

lerna notice cli v3.15.0
lerna info Symlinking packages and binaries
lerna notice cli v3.15.0
lerna info Bootstrapping 6 packages
lerna info Installing external dependencies
lerna ERR! npm install exited 1 in '@revolution/web'
lerna ERR! npm install stderr:
npm ERR! Cannot read property 'match' of undefined

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/stephen/.npm/_logs/2019-10-11T17_31_46_811Z-debug.log

lerna ERR! npm install exited 1 in '@revolution/web'
lerna WARN complete Waiting for 5 child processes to exit. CTRL-C to exit immediately.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! revolution@0.0.1 setup: `lerna link && lerna bootstrap`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the revolution@0.0.1 setup script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/stephen/.npm/_logs/2019-10-11T17_31_46_935Z-debug.log
```

While not a root-cause solution, a [workaround](https://github.com/npm/npm/issues/20954) is:

1. Delete `node_modules` _and_ `package-lock.json`
2. Run `npm install` again
A CodeNewbie on Hacktoberfest
Tags: hacktoberfest, codenewbie, beginners, html
Published: 2019-10-21 22:49:19

It's October 21, so you probably know what is [Hacktoberfest](https://hacktoberfest.digitalocean.com/), even if you are a newbie.
But just in case, here is the short:
Hacktoberfest it a month when all devs come together to contribute 4 PRs to Open Source projects to get a free T-shirt lol

Anyways, so I got 2 PRs in and was struggling to find good projects then Yesterday I started a [#discuss here](https://dev.to/pachicodes/help-beginners-with-hacktoberfest-o44) asking for help, so this post is based on the answer I got there and my experience so far, and I hope it can help other beginners on my position.

**First**. I had no idea but I learned that PR's on your own projects count, yey.

**Second**. You can always go on GitHub and search for good-first-bugs and sort by language, but I felt overwhelmed doing that, so I personally don't recommend it.

**Third**. Go check projects that you thing are cool and that maybe you would like to work with beyond Hacktoberfest. 


So basically what I am doing is, contributing to 2 projects I would like to work with in the future, one with a small JS enhancement and the other with a little HTML change. My last 2 probably will be some update on some of My repos on gitHub, since I have lots of those lol 
Fell free to start a issue on my [very simple but cool Harry Potter app](https://github.com/pachicodes/harry-potter) 

Hope this post can be of help to some,
now let me go back to those PR's.

Have a good week you all!

XOXO
Combine many ngrx selectors with combineLatest in Angular
Tags: angular, ngrx, combinelatest, rxjs
Published: 2019-10-21 22:26:41

Let us suppose we have an area of store that hold the status of a save operation.  Our status can have the values InProgress, Completed and Failed.

We have two selectors already defined...
```javascript
export const getOperationFailed = createSelector(
  getOperationState,
  state => state.status === 'Failed'
);

export const getOperationCompleted = createSelector(
  getOperationState,
  state => state.status === 'Completed'
);
```

Now suppose we have a stop button on our angular template that should be disabled if the status is either Completed or Failed.  It would be pretty simple to do the following in our component...
```javascript
this.getRunProgressCompleted$ = this.store.select(getRunProgressCompleted);
this.getRunProgressFailed$ = this.store.select(getRunProgressFailed);

<button
      (click)="stop()"
      [disabled]="(getOperationCompleted$ | async) || (getOperationFailed$ | async)"
>Stop</button>
```
Instead, we can use the power of the rxjs combineLatest operator to combine our selectors.

![combineLatest marble diagram](https://thepracticaldev.s3.amazonaws.com/i/c4nj7kit8ygrq3i5h52e.PNG)

There are two key facts about combineLatest...
    1. When any observable emits a value, emit the last emitted value from each.
    2. combineLatest will not emit an initial value until each observable emits at least one value.

So we can create a single observable that resolves as true if the operation either completed or failed:
```javascript
this.getOperationCompletedOrFailed$ = combineLatest(
  this.store.select(getOperationCompleted),
  this.store.select(getOperationFailed),
  (failed, completed) => failed || completed
);
```
And bind our button like this:
```javascript
<button
  (click)="stop()"
  [disabled]="getOperationCompletedOrFailed$ | async"
>Stop</button>
```
It's good practice to minimise the number of local variables on your components.  CombineLatest is one of those little tools that helps.
My First Alexa Developers Blog
Tags: alexa, cli, voice, devrel
Published: 2019-10-21 22:22:21

When you're a pro developer, especially when you're working on multiple projects, you may have to juggle multiple sets of credentials. If you are a professional Alexa Skills developer, the profiles feature in the Alexa Skills Kit CLI can help with that.

Check out my first blog post as a member of the Skills Kit developer education team.

[How to manage multiple sets of credentials in ASK CLI with profiles](https://developer.amazon.com/blogs/alexa/post/4cb2a698-7f77-4376-9b9e-6955a9cddd21/how-to-manage-multiple-sets-of-credentials-in-ask-cli-with-profiles).
Modern React interview questions for junior developers (pt. 2)
Tags: react, beginners, javascript, codenewbie
Published: 2019-10-21 21:46:41

React hooks are important for more modern interviews. If you show your updated knowledge when in an interview (if asked a React question), this will definitely impress your interviewer.

Here's one of the easier way to learn React Hooks - learn them by updating a basic tutorial that's already out there!

In the video below, I also walk through how to approach this problem as if it was given in an interview setting

Please consider subscribing by clicking here if you found this information useful!
[YouTube - Matt Upham](https://www.youtube.com/mattupham?sub_confirmation=1)
{% youtube w_SxZ9u6_sY %}

React Hooks are a much more concise way of handling stateful logic, and once you'll learn them, you'll be hooked 😜

If you found this video useful, please consider subscribing to my YouTube Channel! I talk about software & tech, life in Silicon Valley, and self-improvement!

Join our growing [Discord](https://discord.gg/9RGdMcF) community! 

**Subscribe Here**
[YouTube - Matt Upham](https://www.youtube.com/mattupham?sub_confirmation=1)

Thanks for reading!
What is GraphQL ?
Tags: graphql, node, api, rest
Published: 2019-10-21 21:29:41

---
title: What is GraphQL ?
published: true
description: The future of APIs
cover_image: 
tags: graphql, nodejs, api, rest
---

Hi everyone, this is my first ever blog. I have been thinking of starting one like 6 months ago. I was short of ideas and unconfident a little bit. So today, I have decided that it is time to write and share with the world my modest knowledge. 
The topic is **GraphQL**. What is GraphQL? Is it some new trend? Is it really worth gambling on it? … 
So, before diving in, I admit that you already know what is APIs and especially REST APIs.
#What is GraphQL ?
*GraphQL is a query language for APIs*, which means it helps the user fetch data from the server. And not only that, it also helps mutate data (add, update and delete data). The same as CRUD operations in REST APIs. So GraphQL and REST are doing the same things!! What’s so special about GraphQL?
GraphQL is the future of APIs and is an alternative to REST (sounds like I’m advertising GraphQL XD). Why? 
##1. Data, data & data problems
One reason is that most of apps nowadays gets more and more complicated, thus, the management and organization the data and the architecture of the app becomes more and more difficult. Sometimes when fetching the data, we want freedom to fetch the most possible necessary data with one call from the server, and that is not possible with REST APIs. Even if we can manage to do it, we will have multiple lines of complicated or incomprehensible code.
 ![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/xd9lg8b1g2bpsfqxva8i.png)
Yet, with GraphQL we can fetch whatever data we want without having headache.
##2. Endpoints problems
As your app grows, the management of endpoints also becomes more difficult. For example, you may want to search for some comments of a post of a special user in a group. It’s a pain using REST. But trust me, the pain disappears when dealing with such stuff with GraphQL. The fact is there is just one and only one enpoint: http://localhost:4000/graphql (I will get to the technical stuff in a later article).
##3. For mobile devs
I am sorry, I’m not one but GraphQL first was made for mobile development to make easier. Then it turned out that is useful for both web and mobile (Please correct me if I am wrong, I am not sure of this point). 
##4. Simple to use & a fast growing community
GraphQL is open source. It is used by big companies such as Coursera, Github and Twitter. If you are stuck you will surely find help in stackoverflow or github. There lot of tutorials out there, and I recommend howtographql.com or simply the official docs.

Finally, this article comes to an end. In my next article, I will give a real example on how to use GraphQL with NodeJS and MongoDB.
Hope you enjoyed it. Questions or discussions are welcomed. 
Here is some ressources and references: 
https://graphql.org/learn/
https://www.howtographql.com/basics/0-introduction/
The image is taken from https://undraw.co/