teleren/devto huggingface dataset:
FCM push notification with ruby on rails
Tags: fcm, ruby, rails, firebasepushnotification
Published: 2019-10-09 18:19:25

**FCM** is one of the best-known ways to notify the client iOS, Android, or web/JavaScript via push notification as it is free and backed by Google.

Push notification is a very popular communication channel to notify users about important events in the application 🔔.

This is about how to enable push notification send to app using Google's Firebase Cloud Messaging.

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

**Setup FCM**:

1. Go to the [Firebase Console](https://console.firebase.google.com/) page and click on Add new project.

2. If you don't have an existing Firebase project, click Add project and enter either an existing Google Cloud Platform project name or a new project name.

3. Get a server key from settings.

**FCM with Ruby on Rails**:

 1. Install [fcm gem](https://rubygems.org/gems/fcm/versions/0.0.1) and just  gem 'fcm' include in your Gemfile.

 2. Get the registration token or devices token from the devices where App 
    installed. There can be multiple devices registered for an app.

 3. Call and setup your the fcm_call_notification function when you send 
    the notification. 
```ruby
require 'fcm'
def fcm_push_notification
    fcm_client = FCM.new(FCM_SEVER_KEY) # set your FCM_SERVER_KEY
    options = { priority: 'high',
                data: { message: message, icon: image },
                notification: { 
                body: message,
                sound: 'default',
                icon: image
                }
              }
    registration_ids = ["registration_id1", "registration_id2"] ([Array of registration ids up to 1000])
    # A registration ID looks something like: “dAlDYuaPXes:APA91bFEipxfcckxglzRo8N1SmQHqC6g8SWFATWBN9orkwgvTM57kmlFOUYZAmZKb4XGGOOL9wqeYsZHvG7GEgAopVfVupk_gQ2X5Q4Dmf0Cn77nAT6AEJ5jiAQJgJ_LTpC1s64wYBvC”
    registration_ids.each_slice(20) do |registration_id|
        response = fcm_client.send(registration_id, options)
        puts response
    end
end
```
Set options according to your requirement with fcm_push_notification function will notify the client apps with the image also.

Now, your notification should be ready for appearing.

Thank you for reading!🤗

This blog was originally published on Medium 📝
{% medium https://medium.com/@nehanakrani004/fcm-push-notification-with-ruby-on-rails-64097685ce66 %}
Como criar um usuário por linha de comando no RabbitMQ
Tags: dev, cli, rabbitmq, tutorial
Published: 2019-10-22 02:03:19

---
title: Como criar um usuário por linha de comando no RabbitMQ
published: true
date: 2019-10-09 17:47:47 UTC
tags: Dev,cli,rabbitmq,tutorial
canonical_url: https://marquesfernandes.com/2019/10/09/criar-usuario-por-linha-de-comando-no-rabbitmq/
---

Abaixo segue um snippet rápido de como criar um usuário por linha de comando com privilégios de administrador no [RabbitMQ](https://www.rabbitmq.com/).

```
# Criamos um usuário "admin" com a senha "password"rabbitmqctl add\_user admin password# Adicionamos a tag de "administrador "para o usuário "admin"rabbitmqctl set\_user\_tags admin administrator# Adicionamos as permissões para o usuário "admin" no vhost "/"rabbitmqctl set\_permissions -p / admin ".\*" ".\*" ".\*"
```

O post [Como criar um usuário por linha de comando no RabbitMQ](https://marquesfernandes.com/2019/10/09/criar-usuario-por-linha-de-comando-no-rabbitmq/) apareceu primeiro em [Henrique Marques Fernandes](https://marquesfernandes.com).
Solving MakeArrayConsecutive2 on CodeSignal
Tags: elixir, challenge
Published: 2019-10-09 17:44:04

---
title: Solving MakeArrayConsecutive2 on CodeSignal
published: true
description: 
tags: elixir, challenge
---

The challenge:

Input: [6, 2, 3, 8]
Output: 3

To explain better the input and output relationship I need to sort the numbers first
[2,3,6,8]

You see that the numbers that are missing are 4,5, and 7.
How many numbers are missing? Exactly, 3. 3 is the answer.

Input: [0, 3]
Output: 2

Input: [5, 4, 6]
Output: 0

Input: [2]
Output: 0

[The link to the challenge](https://app.codesignal.com/arcade/intro/level-2/bq2XnSr5kbHqpHGJC)
[An invite link to join CodeSignal](https://app.codesignal.com/signup/z9AzBTkKZkpoWaR3s/main)

My first attempt:

```elixir
defmodule MakeArrayConsecutive do
  # statues = [6, 2, 3, 8]
  # makeArrayConsecutive2(statues) = 3
  def makeArrayConsecutive2(statues) do
    statues
    |> Enum.sort()
    |> 
  end

  
  # What am I trying to do here?
  defp number_of_holes(sorted_list) do
    Enum.reduce(list, [],
      fn(x, []) ->
        [x]
      end
      fn(x, [head | tail] = whole_list) -> 
        if x - head =
      end
    )
  end
end
```
My second attempt, still not the full solution, but very close. I didn't account the case [0,3].
```elixir
defmodule MakeArrayConsecutive do
  # statues = [6, 2, 3, 8]
  # makeArrayConsecutive2(statues) = 3
  def makeArrayConsecutive2(statues) do
    case check_singleton(statues) do
      0 ->
        0
      list ->
        list
        |> Enum.sort()
        |> number_of_holes()
        |> return_difference()
    end
  end

  defp check_singleton(xs) do
    case xs do
      [x] -> 0
      list -> list
    end
  end

  defp return_difference({x, y}) do
    y
  end

  defp number_of_holes(sorted_list) do
    Enum.reduce(sorted_list, {0, 0}, fn(x, acc) ->
      case acc do
        {0,0} ->
          {x, 0}
        {number, difference} ->
          if x - number <= 1 do
            {x, difference}
          else
            {x, difference + (x - number - 1)}
          end
      end
    end)
  end
end
```
Discuss: Has anyone here built their own home server or home lab?
Tags: discuss
Published: 2019-10-09 16:50:07

I am planning on buying some old hardware soon to play around with a home server and some VM's.

PC --> https://www8.hp.com/ca/en/campaigns/workstations/z420.html

VM management --> https://www.proxmox.com/en/proxmox-ve


Operating Systems:

(1) Windows 10 LTSC
(2) Debian
(3) ClearOS --> https://distrowatch.com/table.php?distribution=clearos


For fun: 
https://wyze.com

+

maybe some self-hosted cloud storage 
😛



Curious to hear everyone's experience doing such projects at home and any advice you have!

Cheers,

Chris
Would you want an "imposter" on your team?
Tags: discuss
Published: 2019-10-09 16:32:02

---
title: Would you want an "imposter" on your team?
published: true
tags: discuss
---

Inspired by a [previous question](https://dev.to/nalcaraz/ways-to-deal-with-impostor-syndrome-38ol) on Dev...

In all my years of IT, it's felt like I've encountered two main types of people. "Imposters" and "Experts". Understand that the terms I'm using probably aren't what you might be thinking. In my use, here:

- "Imposters" are as described in the linked-to question. 
- "Experts" are those people that feel that their shiny, new McCertification gives them license to tell you The Right Way&trade; to do things
Byte Sized Episode 5: Birth of the B-tree
Tags: computerscience, algorithms, bytesized, history
Published: 2019-10-09 16:17:51

---
title: Byte Sized Episode 5: Birth of the B-tree
published: true
description: Do you know what the "B" in B-tree stands for? The answer is surprising.
cover_image: https://cl.ly/87740ca388fa/Image%202019-10-09%20at%2012.08.47%20PM.png
series: Byte Sized Season 1
---

Today's episode of Byte Sized is about the [B-tree](https://en.wikipedia.org/wiki/B-tree). In computer science, a B-tree is a self-balancing tree data structure that maintains sorted data and allows searches, sequential access, insertions, and deletions in logarithmic time.

You can find more info about b-trees here...

{% link https://dev.to/vaidehijoshi/busying-oneself-with-b-trees %}

Follow **Byte Sized** for an adventure through computer history, a few minutes at a time. More great episodes to come.

{% organization bytesized %}

<center>
# **Today's Sponsor**
</center>

{% organization heroku %}

{% link https://dev.to/devteam/why-dev-hosts-on-heroku-and-how-we-configure-our-service-1caj %}
Xamarin 101: Part 5 - Xamarin.Forms MVVM with XAML
Tags: xamarin, tutorial, beginners, mobile
Published: 2019-10-09 16:17:10

---
title: Xamarin 101: Part 5 - Xamarin.Forms MVVM with XAML
published: true
description: MVVM is the heart and soul of Xamarin.Forms - learn how to use it!
tags: xamarin, tutorial, beginners, mobile
series: xamarin101
---

# Xamarin 101: Part 5 - Xamarin.Forms MVVM with XAML

Model-View-ViewModel (or MVVM) is the heart and soul of Xamarin.Forms. It allows you to add a ton of application logic to your app, but without dirtying up your views with that code. Separation of concerns FTW!

And XAML is tailor made to implement MVVM - with specific attributes allowing for binding of properties and commanding. 

What does that all mean? Check out this short video to find out more!

{% youtube VqZeTAjsgFQ %}

## Learn More!

* [A self-paced course on learning MVVM with Xamarin.Forms](https://docs.microsoft.com/learn/modules/design-a-mvvm-viewmodel-for-xamarin-forms?WT.mc_id=xamarin101-c9-masoucou)
* [A self-paced course on data binding with Xamarin.Forms](https://docs.microsoft.com/learn/modules/separate-your-ui-and-code-with-xamarin-forms-data-binding?WT.mc_id=xamarin101-c9-masoucou)
* [Data binding basics](https://docs.microsoft.com/xamarin/xamarin-forms/xaml/xaml-basics/data-binding-basics?WT.mc_id=xamarin101-c9-masoucou)
* [From data binding to MVVM](https://docs.microsoft.com/xamarin/xamarin-forms/xaml/xaml-basics/data-bindings-to-mvvm?WT.mc_id=xamarin101-c9-masoucou)

Happy mobile coding! And as always, if you have any questions - please ping me on Twitter at [@codemillmatt](https://twitter.com/codemillmatt).
#Hacktoberfest / Issue with Nuxt.js, TypeScript and Element-UI
Tags: hacktoberfest, contributorswanted, discuss, typescript
Published: 2019-10-09 15:35:32

Hi,

does anybody know if we can add a workaround for this issue to the repository, such that our Github Action doesn't fail anymore and it can be used without manually adding the workaround?

Here's the issue:

{% github https://github.com/sirixdb/sirix-web-frontend/issues/18 %}

Happy coding and have a great day :-)

Johannes
Hacktoberfest 2019 - finished!
Tags: hacktoberfest
Published: 2019-10-09 15:09:25

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/4hnhparr04qim8f5wo4m.png)
I am very happy to finish this Hacktoberfest. It was my first one. Very exciting! Will definitely participate next year too! And now I know how to find issues :D
Algorithms behind RuboCop complexity metrics
Tags: ruby, rails, rubocop, softwarecomplexity
Published: 2019-10-09 14:37:01

I published a series on **Medium.com**, explaining the algorithms behind RuboCop complexity metrics. The third part reveals the mathematical connections between different metrics. The series will help you with configuring **cyclomatic complexity**, **perceived complexity**, and, **ABC size** values for RuboCop analysis, which are not completely random.

- In the **[first part](https://medium.com/@avmnusng/ruby-software-complexity-metrics-part-one-prerequisites-b6f86d76a4a5)** we cover syntactic representation of Ruby source code. It provides all the information required to get started with the algorithms.
- In the **[second part](https://medium.com/@avmnusng/ruby-software-complexity-metrics-part-two-calculations-a00fbab610d2)** we go through the pseudocode of the algorithms and solve a couple of problems to see how to calculate the complexity values without drawing control flow graphs.
- In the **[third part](https://medium.com/@avmnusng/ruby-software-complexity-metric-part-three-interdependence-2fc9407c3f45)** we do mathematical analysis to establish a relationship between the metrics and not use a random RuboCop configuration.

I would love your feedback. Thanks!
Welcome Thread - v44
Tags: welcome
Published: 2019-10-09 14:34:28

---
title: Welcome Thread - v44
published: true
description: Welcome to DEV! A thread of hellos and intros.
tags: welcome
---

![olá,salut,hallo,hola,hello](https://media.giphy.com/media/26xBwdIuRJiAIqHwA/giphy.gif)

### Welcome to DEV!

1. Leave a comment below to introduce yourself! You can talk about what brought you here, what you're learning, or just a fun fact about yourself.

2. Reply to someone's comment, either with a question or just a hello. 👋 

**Great to have you in the community!**
Daily Challenge #86 - Wouldn't, not Would.
Tags: challenge
Published: 2019-10-09 14:15:54

---
title: Daily Challenge #86 - Wouldn't, not Would.
published: true
series: Daily Challenge
description: Write a function that will append "n't"
tags: challenge
---

This challenge is for all those times your mouth said something your brain didn't tell it to.

Write a function that will find a misspoken word in your `speech` using the following `words`:

are - aren't
can - can't
could - couldn't
did - didn't
do - don't
had - hadn't
has - hasn't
have - haven't
is - isn't
might - mightn't
must - mustn't
should - shouldn't
was - wasn't
were - weren't
would - wouldn't

Add or remove the suffix `n't` where needed. Beware of the word "can" and extra suffixes like `'ve`.

`speech`:
I do like pizza.
I haven't seen you wearing that hat before. 
I could see why you would say that. 
I didn't say it! It wasn't me!
YES, WE CAN

Good luck!

***
_This challenge comes from dinglemouse on CodeWars. Thank you to [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!_
Embedding Videos in Your Gatsby.js Sites
Tags: gatsby, react, jamstack, javascript
Published: 2019-10-09 14:12:30

---
title: Embedding Videos in Your Gatsby.js Sites
published: true
description: Learn how to embed videos in gatsby.js sites
tags: #gatsbyjs, #react, #jamstack, #javascript
canonical_url: https://scotch.io/tutorials/embedding-videos-in-your-gatsbyjs-sites
---

Media elements like images, videos, and GIFs in blog posts and websites are becoming prominent day by day. Also, Gatsby-powered websites are the recent trend and people are very excited about #JAMstack. 

When we talk about embedding/rendering these media elements we find different ways of doing it. Moreover, the process is not the same. It varies from one framework to another. 

Talking about Gatsby specifically, then videos can be embedded either through a custom <iframe> solution or by using `remark` plugins.

I'll be sharing an easier way of doing it. There is this incredible Gatsby plugin called `gatsby-remark-embed-video` which helps you embed videos from multiple video hosts like YouTube, Vimeo, etc.

I have written an in-depth tutorial where you can learn the entire process. **[You can find it here →](https://scotch.io/tutorials/embedding-videos-in-your-gatsbyjs-sites)**

Go through it and trying adding videos yourself. Let me know if you come across any difficulty. I'll be glad to assist.

I also tweeted about it and you can follow me [@MaeadhBatool](https://twitter.com/MaedahBatool)

{% twitter 1181926159505907712 %}
Weekly Picks #96 — Development Posts
Tags: webdev, javascript, react
Published: 2019-10-09 13:48:06

* [Stop Console.Logging! This is How to Use Chrome to Debug JavaScript](https://app.dailynow.co/r/2c732ac8d2bf81a2d092086b35b3d193)
* [Become a Git Ninja: 7 Productivity Tips](https://app.dailynow.co/r/e2aae509fe8a1996ca2ea0ad4c6df59d)
* [Tips to write better Conditionals in JavaScript](https://app.dailynow.co/r/58d74c2d8463a528bf7505c272ac8e3e)
* [Clean code... Why bother? - Part 2](https://app.dailynow.co/r/d968ac8bb4e674b0a564cb1980e92189)
* [3 React concepts which can be forgotten ?](https://app.dailynow.co/r/c47591aaad768dc4ea77e74468e12229)
* [Generate API In Less than 10 minutes](https://app.dailynow.co/r/787d5ba03dca6e1b16068013327c508d)
* [How I Make Sense of RxJS](https://app.dailynow.co/r/345318c05aa28b0b339257cd58358e5f)
* [Use cases for the Stack data structure in JavaScript](https://app.dailynow.co/r/1552b9e2ee1239294a999848dec900a2)
* [What is the difference between prototype and __proto__ in JavaScript?](https://app.dailynow.co/r/82c05d09fd4a4dbe607ff60276858d67)
* [Top Skills You Will Need to be a Front-End Developer](https://app.dailynow.co/r/4d355815cdce0ac3f592e81036d30009)

* * *

[_Thanks to Daily_](https://www.dailynow.co/) _developers can focus on code instead of searching for news. Get immediate access to all these posts and much more just by opening a new tab._

[![Daily promotion cover](https://cdn-images-1.medium.com/max/1024/1*7bwIhcH467BKX5Ni8XWpQg.jpeg)](https://www.dailynow.co/)
Solving The GET and POST Dilemma
Tags: codequality, webdev
Published: 2019-10-09 13:45:19

Weather you should use GET or POST, the debate is endless. Each one has its own preference. So, what is the need of another article on it? Because, weather it’s POST or GET, you can achieve the same results from both. So, in this article I’ll put more emphasis on WHY use one over other, instead of WHERE to use one over other. Check out full article below. 

https://aarvy.me/blog/2019/10/09/solving-the-get-and-post-dilemma/
We just open-sourced​ our SDKs
Tags: cms, opensource, webdev, javascript
Published: 2019-10-09 13:44:57

Agility CMS is a Headless CMS with SDKs for Javascript and .Net, and many more coming soon.

Previously, only our Javascript SDKs were available on GitHub.  You can see them here:

###   Fetch API SDK
-  Access your Agility CMS data easily in JS - works in node.js and client-side apps.
-  https://github.com/agility/agility-content-fetch-js-sdk

### Gatsby Starter
-  GatsbyJS has taken the world by storm.  [Read the guide](https://www.gatsbyjs.org/docs/sourcing-from-agilitycms/) on sourcing content for Gatsby from Agility CMS and get rolling!
-  https://github.com/agility/agility-gatsby-starter


Now, we have taken our .Net SDKs and made them available too.

###  Fetch API SDK for .Net 
-  Targeting .Net standard 2, this library provides access to your Agility CMS data.  Future releases will support strong data types, whereas this version features only dynamic types for your Contnet and Module Definitions.
-  https://github.com/agility/agility-content-fetch-dotnetcore-sdk

### Content Sync SDK for ASP.Net Core
-  This SDK access data using our Sync API, which pulls your Agility CMS content down to your web server.  
-  This code has been around for quite a while, and we are pleased to make it available to our community.
-  If you are interested in contributing, get in touch, or take a look at the open issues and submit a pull request!
-  https://github.com/agility/Agility.AspNetCore


### 🤩 Contributors Welcome! 🤗
We've really embraced the idea of a strong developer community here at Agility CMS.  We believe developers are the most powerful influencers in the world, and we want to provide you with a great experience. 😍

If you want to build an Agility CMS SDK, get in touch with us and we can help you get started. 👍

### 🆓 Get started with a Free Account 🆓
If you are really serious about contributing, you are going to need a free account to play around with. 

[Sign up for that here](https://account.agilitycms.com/sign-up?leadsource=devto)

### 🎟 Conferences and Events 🎤
Agility CMS also hosts conferences and events aimed at educating developers.

[Check out what's coming up next](https://agilitycms.com/community#events)
Intro to bitwise operations
Tags: computerscience, bitwise
Published: 2019-10-09 13:39:47

Bitwise operations are really useful and fast for storing and operate on certain values. They are way more used in systems where resources are more limited like video-games or embedded devices.

In this first article about bitwise operations, we get a quick introduction to them with a drawing (new format!) and some written content but I plan on sharing more 🙂.

## What are bitwise operations?
They're operations that deal with bits directly. Bits are 1s and 0s and it's how everything is stored internally in a computer so being able to operate with them directly is very efficient because the processor is able to do those operations natively. [Wikipedia says](https://en.wikipedia.org/wiki/Bitwise_operation):

>  ...typically, bitwise operations are substantially faster than division, several times faster than multiplication, and sometimes significantly faster than addition...

## The three basic operators
There are more but let's take a look today at the three most basic operators:

### NOT
NOT is very simple, if there's a 1 we get 0. If there's a 0, we get 1.

It's represented by _~_ in most programming languages so for example: 

```
~0101011 = 1010100
```

### AND
AND is like the boolean equivalent you already use in if conditions but with one difference, this operates at the level of bits:
```c
1 & 1 = 1
1 & 0 = 0
0 & 1 = 0
0 & 0 = 0
```

### OR
The same goes for the OR operation, represented with the | symbol in many programming languages.
```c
1 | 1 = 1
1 | 0 = 1
0 | 1 = 1
0 | 0 = 0
```

## How they operate with more than 1 bit
The key here is to remember that when we have a bitwise operation with more than 1 bit, we do it bit by bit. For example:

```c
// Bitwise OR
111010
001100
-------
111110
```

Or in an AND operation:
```c
// Bitwise AND
111010
001100
-------
001000
```

## Real life example:
![Intro to bitwise](https://josemdev.com/images/intro-bitwise.png "Intro to bitwise")
<span class="photo-credit"><a target="_blank" href="https://josemdev.com/images/intro-bitwise-full.png">Full drawing here</a></span>

<br>
In a future article we'll see other operators because you can do some very efficient calculations with numbers but we need more than just these three. See you soon!
Apollo GraphQL Question: How to handle invalid network requests for mutations with optimistic UI?
Tags: graphql, apollo, question
Published: 2019-10-09 13:34:46

Hey fellow dev.to readers and writers! Today I have a quick question regarding Apollo GraphQL.

I'm currently working on an offline support feature so we can schedule mutations offline and show optimistic UI responses for them while the server does not respond.

That works fine while being offline, so everytime I submit a chat message, I get an immediate response from the Optimistic UI cache but if I go offline and send messages, I won't get any optimistic UI responses if the network requests are failing.

Am I missing something crucial on that concept?

Would love to hear from you!

Thanks!