teleren/devto huggingface dataset:
Subjects in RxJava with Kotlin
Tags: android, rxjava, kotlin
Published: 2020-12-14 02:09:53

## Prerequisites

You need to know the difference between an Observable and an Observer to get the most out of this post.

## What are Subjects

Subjects act both as an Observable and as an observer at the same time. Because it is an observer, it can subscribe to one or more Observables, and because it is an Observable, it can pass through the items it observes by reemitting them, and it can also emit new items. Subjects receive the next events and emit them to their subscribers.

  

## Types of Subjects in RxJava

-   PublishSubject
-   BehaviorSubject
-   ReplaySubject
-   AsyncSubject

In this post, we will talk about *PublishSubject*.

## PublishSubject

You can use Publish subject when you want new subscribers to be notified of new events that will come after they've subscribed.


## Example in kotlin
```kotlin 
// create publish Subject
val publishSubject = PublishSubject.create<String>()

// send element to publish subject
publishSubject.onNext("event 1")

// create subscriber to publish subject
val subscriber1 = publishSubject.subscribeBy(
        onNext = {println("subscriber 1 $it")}
)

// send element to publish subject
publishSubject.onNext("event 2")

// create another subscriber to publish subject
val subscriber2 = publishSubject.subscribeBy(
        onNext = {println("subscriber 2 $it")}
)

// send element to publish subject
publishSubject.onNext("event 3")

// dispose subscriber1
subscriber1.dispose()

// send element to publish subject
publishSubject.onNext("event 4")

// send complete event to terminates publish subject observable sequence
publishSubject.onComplete()

//dispose subscriber2 because there is no more events will come for it
subscriber2.dispose()
```

The output will be:
 
 
subscriber 1 event 2
subscriber 1 event 3
subscriber 2 event 3
subscriber 2 event 4


That's it for PublishSubject, I hope you've learned something new, please drop me a comment if you didn't understand something, I also love to hear suggestions for improving, so if you have any, please drop me a comment.
SSL certificate for Azure API Management with Cloudflare
Tags: azure, cloudflare, ssl, tutorial
Published: 2020-12-14 01:14:41

**`<TLDR>`** Want to add a custom domain to your APIM instance? Using Cloudflare? Generate a free SSL certificate in minutes. **`</TLDR>`**

When new API Management instance is created it's reachable with a default hostname from Azure: `your-apim-name.azure-api.net`.

If you add a `CNAME` record pointing to that hostname (e.g. `api.your-company.com`) and query the cname, you will get the `HTTP Error 503. The service is unavailable.` error. That's because APIM uses the hostname to route the request internally (to the gateway / developer portal / management portal). And at this point it doesn't know anything about `api.your-company.com`.

In order to add a custom domain to APIM you need to present a valid SSL certificate for that domain.

If you have the certificate (purchased or generated with LetsEncrypt) you can upload that (and you're done).

In case you don't have it yet, and in case you use Cloudflare as a caching/protection layer (orange cloud ON) on top of your API it's very easy to generate a SSL certificate for API Management.

It takes 3 steps.

## Generate origin certificate in Cloudflare

1. Log in to Cloudflare dashboard
2. Go to **SSL/TLS** tab
3. Go to **Origin Certificates** / **Create Certificate**
4. Check if you need to add anything to the hostnames list, otherwise keep the default settings. Click **Next**
5. Choose `PEM` key format. Save **Origin Certificate** to `api.your-company.com.pem` file and **Private Key** to `api.your-company.com.key` file

## Convert generated certificate from PEM to PFX

Cloudflare lets you export a certificate in `PEM` format (common file extensions are `.pem`, `.crt` and `.cer`).
Azure wants the binary `PKCS#12`/`PFX` certificate format (common file extensions are `.pfx` and `.p12`).
You can convert between these 2 formats using `openssl` command line tool (available in OS X and \*nix).

In the folder where you saved `.pem` and `.key` files run:

```bash
openssl pkcs12 -export -out api.your-company.com.pfx -inkey api.your-company.com.key -in api.your-company.com.pem
```

Optionally provide a password.

## Import PFX certificate to APIM

1. In Azure Portal, go to the API Management instance.
2. Go to **Custom Domains** / **Add**
3. Select the APIM component you're adding custom domain to (API Gateway / Management Portal / Developer Portal)
4. Provide the hostname: `api.your-company.com`
5. Certificate: Custom / Select the pfx file.
6. Add.

It will take a few minutes to process the upload. Confirm `api.your-company.com` no longer returns 503 but responds with valid APIM responses.

*If you like this type of content you can [follow me](https://twitter.com/max_v_i) on Twitter for the latest updates.*
Scraping Instagram reels with instascrape
Tags: python, showdev, datascience, contributorswanted
Published: 2020-12-14 00:57:49

```python
from instascrape import Reel
```

In this blog post, I'm going to show you how to scrape Instagram reels using the Python library [`instascrape`](https://github.com/chris-greening/instascrape)'s latest feature! 
 
<p align="center">
  <img src="https://dev-to-uploads.s3.amazonaws.com/i/ph2r4iousf7tscaiqnmc.png">
</p>

{% embed https://www.christophergreening.com %}

# Introducing the Reel scraper 

With the release of [v1.5.0](https://github.com/chris-greening/instascrape/releases/tag/v1.5.0), `instascrape` now provides the `Reel` object for scraping Instagram reel's in just a few lines of code:

```python
from instascrape import Reel 
google_reel = Reel('https://www.instagram.com/reel/CIrJSrFFHM_/')
google_reel.scrape()
print(f"This reel has {google_reel.video_view_count:,} views.")
>>> This reel has 48,593 views.
```
And that's it! `Reel` is a subclass of the `Post` scraper so all expected behaviors and methods carry down for easy usage. 

# Additional `instascrape` content

If you're interested in seeing some more `instascrape` content, check out some of my other blog posts 

{% link https://dev.to/chrisgreening/dynamically-generate-embeddable-instagram-html-using-instascrape-3o4b %}
{% link https://dev.to/chrisgreening/scraping-25-000-data-points-from-joe-biden-s-instagram-using-instascrape-1026 %}

and drop by the [official repo](https://github.com/chris-greening/instascrape) and [introduce yourself](https://github.com/chris-greening/instascrape/discussions)!

{% github chris-greening/instascrape %}
{% embed https://www.christophergreening.com %}
class and objects in c++
Tags: cpp, programming, computerscience
Published: 2020-12-14 00:49:07

hey there, today we will talk about class and instances in c++. 

**Class**

c++ supports object-oriented programming and often called user defined data types.
A class is a blueprint of the object. Data and functions within a class are called member of the class.

```
definition of class

class Circle{
      public:
        double radius; //radius of the circle
}; 
```
class definition is starts with keyword class followed by classname. Here public means members of the class are accessible from outside the class from anywhere within scope of the class.

**Class Objects**
```
Circle circle1; //Declare circle1 of type Circle
Circle circle2; //Declare circle2 of type Circle
```
class objects/instances are defined by exactly the same way we define basic variables. class name followed by object name.

```
#include <iostream>
#include <cmath>

using namespace std;

class Circle{
     public:
       double radius;
};

int main(){
  //Objects instantiations
Circle circle1;
Circle circle2;
double area = 0.0; //Store the area of the circle here

circle1.radius = 2.1;
circle2.radius = 5.3;

// Area of the circle1
area = 3.14 * pow(circle1.radius, 2);
cout << "Area of the circle is " << area << endl;

// Area of the circle2
area = 3.14 * pow(circle2.radius, 2);
cout << "Area of the circle is " << area << endl;

return 0;
}
```
when above code compiled and executed, it will produce a follwing result.
```
Area of the circle is 13.8474
Area of the circle is 88.2026
```
My First Flatiron Project!
Published: 2020-12-14 00:47:48

For my very first project at Flatiron, I was given the task of building a Ruby CLI Application, by either scrapping or utilizing an API from a public website. 

Initially I struggled with ideas for my project. I went through so many different APIs before deciding to build an app that would utilize data on the newly developing islands in the Caribbean. 

My application uses the Rest Countries Caricom regional bloc API, which allows any user to list a few of the Caribbean Community, better known as the Caricom countries along with their capital cities and population. 

First thing I needed to do was build an API class, which gathered all the information from my url. Secondly, a Country class which initializes object instances for my Caricom countries. And last but not least, a CLI class which interacts with the user/users. 

Overall, I am very happy with how my project came out. My hardest struggle was not being able to properly execute my ideas in the CLI class, but after weeks of ferociously coding and with the help of my tutor Brandon, I can proudly say I am very happy to be able to immerse myself in greater depths of understanding Ruby!
Masonry Layout en Ionic 5
Tags: ionic, angular, design
Published: 2020-12-14 00:31:04

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qs0k8vjgv2ain4zo8xzp.png)

Implementacion del masonry layout con ionic 5
https://youtu.be/mqbA6DGw1xQ
Hackathon Idea: dev.to View Count Graphs
Tags: dohackathon, idea
Published: 2020-12-14 00:28:00

I was reading the post for the current Hackathon

{% link https://dev.to/devteam/announcing-the-digitalocean-app-platform-hackathon-on-dev-2i1k %}

and wasn't sure I would have an idea. But then yesterday, my post [Dotfiles - Put your home directory under `git`](https://dev.to/coreyja/dotfiles-put-your-home-directory-under-git-51l9) got a some views, and I was checking the view count during the day and wished I could have a cool graph seeing the view counts over time 🤔

Today I realized that would be a great little project to build for this hackathon!

So far, I've checked out the dev.to API docs, and it seems like I should be able to get article counts and everything from that, which is awesome!

The one drawback I noticed is that the OAuth is in private alpha right now, so I'll have to use the 'personal access' token style, which means a single instance may only be able to serve a single user, but that's ok! (I'd love an invite to the private alpha if that's an option too 😉)

What do you guys think? Would anyone want to see some fun graphs of your different dev.to articles view count over time?

I think I'm gonna give it a whirl!

<span>Photo by <a href="https://unsplash.com/@isaacmsmith">Isaac Smith</a> on <a href="https://unsplash.com/s/photos/graphs">Unsplash</a></span>
I've published my first WordPress plugin!
Tags: wordpress, php, sql, webdev
Published: 2020-12-14 00:21:42

Showing users things near them is a really common user need for all sorts of apps and websites.

It could be used to power anything from "branch finder" features on retail sites to nearby drivers on a ride-hailing app. 

For my day job, I need to build this kind of functionality roughly once every few months, so I was keen to find a way to package it up into something reusable.

I've implemented it in Node.js and Rails before, but I was curious about a WordPress implementation - which is what _this_ is.

![Example screens from a location-aware app](https://dev-to-uploads.s3.amazonaws.com/i/ryfopq1g4xhk2wwc5nmx.jpg)

_After making over half a dozen apps [like this](https://github.com/jhackett1/age-uk-boost), you start to wonder if there's a better way!_

## How it works

It's a three step process:

1. You provide a **geocoded** dataset to search. They could be shops, offices, childminders, zoos—anything, really. You make sure that they have latitude and longitude metadata.

2. The user provides their location with a text input, which we also geocode. We use [Nominatim's excellent free API](https://nominatim.openstreetmap.org/ui/search.html) to do this.

3. Finally, we use the [haversine formula](https://en.wikipedia.org/wiki/Haversine_formula) in SQL to calculate the distance to each point in the dataset. It takes into account the curvature of the earth, so we get super-accurate results even on international scales!

## The plugin

[Take a look and tell me what you think!](https://wordpress.org/plugins/wp-geo-search)

It's my first WP plugin that I've actually gone to the extra effort of publishing, so I'm keen to keep adding features.
S3E9 Learn JMeter Series - Loop and Transaction Controller
Tags: testing, webperf, performance, tutorial
Published: 2020-12-14 00:12:25

Welcome to Learn JMeter Series!

In this Season 3, Episode 9, you will learn following:

🔹 Loop and Transaction Controller

{% youtube _BfWJDuKs5Y %}

☑ Buy me a tea 🍵 : https://www.buymeacoffee.com/qainsights
☑ [My Blog](https://qainsights.com)
☑ [My Udemy Course](https://www.udemy.com/course/performance-testing-using-truweb)

{% github QAInsights/Learn-JMeter-Series%}
Add Web Monetization to your sites with Snippet Injection
Tags: blogvent, webmonetization, netlify
Published: 2020-12-15 02:06:26

---
title: Add Web Monetization to your sites with Snippet Injection
published: true
date: 2020-12-14 00:00:00 UTC
tags: blogvent, webmonetization, netlify
canonical_url: https://www.netlify.com/blog/2020/12/14/add-web-monetization-to-your-sites-with-snippet-injection/
---

Welcome to Blogvent, day 14!

In case you haven’t heard of it before, [Web Monetization](https://webmonetization.org/) is “a JavaScript browser API that allows the creation of a payment stream from the user agent to the website.” It’s currently being proposed as a W3C standard at [the Web Platform Incubator Community Group](https://discourse.wicg.io/t/proposal-web-monetization-a-new-revenue-model-for-the-web/3785), and uses the open protocol [Interledger](https://interledger.org/) to transfer money.

## I want that!

If you want to enable Web Monetization in your websites, you first set up a web monetized wallet, and a payment pointer. Right now you’ll want to use one of these Interledger-protocol-enabled providers to do so:

- [Uphold](https://uphold.com/)
- [GateHub](https://gatehub.net/)

Your payment pointer will be something that looks like a URL but starts with a `$` sign, like `$wallet.example.com/something`.

Now, with that payment pointer, you can use the `monetization` meta tag!

```html
<meta name="monetization" content="$wallet.example.com/something">
```

## Where do I put this tag?

You can add it into the `<head>` of your website, and it’s done! But, if you don’t want to make code changes in your repo, there’s an even simpler way with **Snippet Injection.**

Head do your Site Settings on Netlify, then Build & Deploy, then down to Snippet Injection. Make a new snippet, make it “Insert before ”, and add your tag in the HTML, like so:

![Snippet injection panel with monetization meta tag](https://www.netlify.com/img/blog/snippetmonetization.png "Snippet injection panel with monetization meta tag")

Now, your web monetization will be automatically added into your site’s build, without you having to update your `<head>` across your codebase.

Enjoy! 🤑
How to redirect to a webpage in a browser using JavaScript?
Tags: javascript
Published: 2020-12-14 00:00:00

---
  title: How to redirect to a webpage in a browser using JavaScript?
  published: true
  tags: JavaScript
  date: Mon Dec 14 2020 05:30:00 GMT+0530 (India Standard Time)
  canonical_url: https://melvingeorge.me/blog/redirect-to-webpage-in-browser-using-javascript
  cover_image: https://melvingeorge.me/_next/static/images/main-d86485094f4bdb68529a03160cb33ceb.jpg
  ---
  [Originally posted here!](https://melvingeorge.me/blog/redirect-to-webpage-in-browser-using-javascript)
  
To redirect to a webpage in browsers using JavaScript, we can use the `location` property on the global `window` object.

Let's say our redirect url is `https://google.com`, all we have to do is set the `window.location` value to the redirect URL.

```js
// redirect to a webpage
window.location = "https://google.com";
```

Along with the above solution, JavaScript is lovely enough to provide us with there are 3 more other ways to achieve the same thing,

- Changing the value of `window.location.href` to the redirect URL. This way is similar to a user clicking on a link.

```js
// redirect to webpage
// similar to user clicking on a link
window.location.href = "https://google.com";
```

- Passing the redirect URL as an argument to the `assign()` method on the `window.location` object.

```js
window.location.assign("https://google.com");
```

- Passing the redirect URL as an argument to the `replace()` method on the `window.location` object.

```js
window.location.replace("https://google.com");
```

### Feel free to share if you found this useful 😃.

---
How to sort numbers in ruby
Published: 2020-12-13 23:22:57

This is a simple module to sort numbers from lower to higher:

```ruby
module Sort

  def numbers(array)
    n = array.length - 1
    x = 0
    while x <= n - 1
      first = x
      y = x + 1
      while y <= n
        first = y if array[y] < array[first]
        y += 1
      end
      array[x], array[first] = array[first], array[x] unless x = first
      x += 1
    end
  end

end
```

Now you can use this module like this:

```ruby
  nums = [14,2,290,13,54,254,66,72,918,90]

  puts "Numbers to sort: #{nums}"

  data = Sort.numbers(nums)
  puts "Sorted numbers: #{data.inspect}"

  x_data = data.shuffle
  puts "Shuffled numbers: #{x_data.inspect}"

  y_data = Sort.numbers(x_data)
  puts "Sorted again: #{y_data.inspect}"
```
Why do we close the door?
Tags: opensource, sideprojects, hobbies
Published: 2020-12-13 23:12:38

Recently, I was reflecting about the way in which I've created my side projects. After many years of try-fail-and-forget, I wondered where those projects ended up. Where were those once upon a time exciting projects? The vast majority on a private repo where dust and glory covered them.

I imagined myself locked in a room, full of enthusiasm and joy building something I think will change the world because what a good idea! However, a new idea or technology appears. It's more exciting, has newer and more powerful features, and maybe, I can focus on that one instead. So, I leave my piece of work in the desk, close the room behind me, and knock on the next door.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/v3e6xi318leoesfrr9bg.jpg)

I discovered that many of the implementations I intended could have had a better life in other people's hands, instead of just a null instance in life. Maybe there are some golden pieces in there that someone else could take and group them together and continue. Even more, I instantly ruined the opportunity to gain community traction and even support from others, and nobody will never know about what the original idea was.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/h564wbrya9kwrlrwh1ji.jpg)

At the end, I decided not only to not throw the key anymore but to leave the door behind me opened. Why, after investing many hours do we close that door, lock it down, throw the key and knock on the next one? We are closing it after creating fine art, fantastic code that deserves its place in posterity, no matter if it's not perfect, it's our code and we invested time and passion building it. From now on, **my side projects will be Open Source**.

So, why not leave it open?

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/fm1t1cm5rxetlt9vsjxl.jpg)

Pictures:

<span>Cover image: Photo by <a href="https://unsplash.com/@pdr_ramos?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Pedro Ramos</a> on <a href="https://unsplash.com/s/photos/open-door?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span>

<span>[1] Photo by <a href="https://unsplash.com/@bhautik_andhariya?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Bhautik Andhariya</a> on <a href="https://unsplash.com/s/photos/gold-rock?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span>

<span>[2] Photo by <a href="https://unsplash.com/@thommilkovic?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Thom Milkovic</a> on <a href="https://unsplash.com/s/photos/closed-doors?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span>

<span>[3] Photo by <a href="https://unsplash.com/@murai?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Murai .hr</a> on <a href="https://unsplash.com/s/photos/open-door-art?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span>
First Class Functions
Tags: javascript, 100daysofcode, programming, beginners
Published: 2020-12-13 22:42:16

Today i learned that JavaScript is a lightweight, interpreted,or JIT(Just In Time) compiled language with first class functions.
What are __first class functions__? Well a programming language is said to have first class functions when functions in that programming language are treated like any other variable.Example
```javascript
// Assigning a variable to a function
const foo = () => {
  console.log("FooBar");
}
// Invoking the function
foo();
```
You can also have a function that returns another function, for example
```javascript
const sayHello = () => {
   return () => {
      console.log("Hello!");
   }
}
// Method 1 of function invoking
const myFunc = sayHello();
myFunc();
// Method 2 of function invoking
sayHello()();
```
Functions that return other functions are called __Higher-Order Functions.__
Why I wanted to study Software Engineering
Tags: softwareengineering, coding, programming, codingbootcamp
Published: 2020-12-13 22:02:44

About a year ago, I was out to dinner with a friend of mine and we were discussing how (against our better judgement, perhaps) we really missed being in school. Not for the exams, or homework, or GPA-induced pressures, but because we missed *learning.*

At this same time, I was working as an Associate Producer at a small video game studio and getting ramped up on a project that would require me to learn how to use Unity and write some simple Lua. This task was not exactly within my job description as a project manager, but it was through this project that I really began to understand that coding is a skill that requires constant learning. The ups and downs of learning something new, getting stuck, and then learning something new to get unstuck was something that spoke directly to my desire to grow and gain new skills that school and college had once satiated. 

I started to do some self-directed learning outside of work, mostly focused on HTML and CSS. I found myself losing huge chunks of time totally engrossed in making cute mini websites for myself. One of my favorite things to do is acquire new hobbies (another perk of being a developer is the financial stability it provides that allows people to explore their personal tech and non-tech hobbies), and this felt like the ultimate hobby to take up. 

At that same job, I had wonderful colleagues who saw my passing interesting in coding, and encouraged me in it. At a certain point, the interest became less of a passing one, but rather one I wanted to pursue full time. So, here I am at the start of that journey-- I can't wait to see where it takes me!