teleren/devto huggingface dataset:
Wordpress hooks
Tags: php, help, wordpress, hooks
Published: 2020-06-07 20:30:28

###Background 

I'm working on a project for a non-profit and they've asked for a user to only be able to ask for mentoring support after completing a course. This makes it easier to set expectations and confirm they understand the code-of-conduct.


###My Issue

I've managed to sort out adding a user to a membership when they sign-up using some custom code in my functions.php

```php
// Hook into Gravity Forms User Registration. Runs after user has been registered
add_action( 'gform_user_registered', 'memberpress_membership_account_prep', 10, 4);

// Setup lifetime MemberPress membership
function memberpress_membership_account_prep( $user_id, $feed, $entry ) {

    $url     = rest_url( 'mp/v1/transactions' );
    $headers = [ 'Authorization' => 'AUTHCODEHERE' ];

    $data = [
        'member'     => $user_id,
        'amount'     => "0.00",
        'total'      => "0.00",
        'membership' => "237", # MemberPress membership ID here
        'status'     => "complete",
        'gateway'    => "manual",
        'expires_at' => "0000-00-00 00:00:00"
    ];

    $response = wp_remote_post( $url, [
        'method'  => 'POST',
        'headers' => $headers,
        'body'    => $data
    ] );

}
```
But now I'm have trouble. The following snippet can be used when a particular course has been finished.
```php
// Hook into Learndash Course Completion
add_action("learndash_course_completed", function($data $course_id) {
//Called when course is completed
}, 5, 1);
```
But I can't figure out how to use the data to pass it into the **_memberpress_membership_account_prep_** function.

Any help would be very appreciated.

Thanks.
Create REST API using deno
Tags: deno, rest, api
Published: 2020-09-07 12:16:40

---
title: Create REST API using deno
published: true
date: 2020-06-08 00:00:00 UTC
tags: Deno,REST,API
canonical_url: https://www.loginradius.com/engineering/blog/create-rest-api-in-deno/
---

Deno, the creation of Ryan Dahl is a simple, modern, and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust. As Deno 1.0.0 has released, there is much-awaited curiosity amongst developers around working with this new stack. When it comes to learning a…

   
[Read On](https://www.loginradius.com/engineering/blog/create-rest-api-in-deno/)
Youtube iFrame API - YT.Player is not a constructor
Tags: javascript, youtube, api, troubleshoot
Published: 2020-06-12 04:09:58

---
title: Youtube iFrame API - YT.Player is not a constructor
published: true
date: 2020-06-08 00:00:00 UTC
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/d35vtug7qiov6jpyoo2v.jpg
tags: javascript, youtube, api, troubleshoot
canonical_url: https://sung.codes/blog/2020/06/08/youtube-i-frame-api-yt-player-is-not-a-constructor/
---

As I was playing around with [YouTube Player API Reference for iframe Embeds](https://developers.google.com/youtube/iframe_api_reference), I was getting the following error,

> TypeError  
> YT.Player is not a constructor

The error occurred when I was creating a new `YT.Player` instance.

```js
new YT.Player("player", {
  height: "390",
  width: "640",
  videoId: "M7lc1UVf-VE",
  events: {
    onReady: onPlayerReady,
    onStateChange: onPlayerStateChange
  }
});
```
I was looking at [this reply](https://stackoverflow.com/a/54848637/4035) for the question, Uncaught [TypeError: YT.Player is not a constructor](https://stackoverflow.com/questions/52062169/uncaught-typeerror-yt-player-is-not-a-constructor) but it didn't really answer what the "fix" is.

After some digging I found a working CodeSandbox sandbox, [https://codesandbox.io/s/youtube-iframe-api-tpjwj](https://codesandbox.io/s/youtube-iframe-api-tpjwj) (this uses jQuery), which used a undocumented API, `YT.ready()`.

It seems to wait until the player instance is "ready" to be created similar to [DOMContentLoaded](https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event) for DOM.

So the fix it to wait within the callback of `YT.ready`.

```js
function setupPlayer() {
    /**
     * THIS FAILS!!!!!
     */
    // player = new YT.Player("player", {
    // height: "390",
    // width: "640",
    // videoId: "M7lc1UVf-VE",
    // events: {
    // onReady: onPlayerReady,
    // onStateChange: onPlayerStateChange
    // }
    // });

    /**
     * Need to wait until Youtube Player is ready!
     */
    window.YT.ready(function() {
      player = new window.YT.Player("video", {
        height: "390",
        width: "640",
        videoId: "M7lc1UVf-VE",
        events: {
          onReady: onPlayerReady,
          onStateChange: onPlayerStateChange
        }
      });
    });
  }
```

The working Sandbox (I converted the jQuery version to Vanillia JS) - [https://codesandbox.io/s/soanswer52062169-mem83?file=/src/index.js:406-1242](https://codesandbox.io/s/soanswer52062169-mem83?file=/src/index.js:406-1242)

* * *
Image by [SplitShire](https://pixabay.com/users/SplitShire-364019/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=407212) from [Pixabay](https://pixabay.com/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=407212)
Remove page or site from Google search results
Tags: seo, google, www
Published: 2020-06-08 14:22:22

---
title: Remove page or site from Google search results
published: true
date: 2020-06-08 00:00:00 UTC
tags: SEO, google, www
canonical_url: https://solrevdev.com/2020/06/08/remove-page-or-site-from-google-search.html
---

 **Background**

What do you do when you have a website that you do not want Google or other search engines to index and therefore NOT display in search results?

**Robots!** 🤖

In the past, you have simply been able to add a [robots.txt](https://www.robotstxt.org/robotstxt.html) file.

This is a file that website owners could use to inform web crawlers and robots such as the [Googlebot](https://support.google.com/webmasters/answer/182072?hl=en) about whether you wanted your site indexed or not and if so which parts of your site.

If you wanted to stop all robots from indexing your site you created a file called `robots.txt` in your site root with the following content

{% gist https://gist.github.com/solrevdev/b0f05c422ac359168bff77e319b6b7ff %}

While still used, it is no longer the recommended way to block or remove a URL or site from Google.

**Google’s Removal Tool** ✂

Your first step should be to head over to the [Google Search Removal Tool](https://search.google.com/search-console/removals?resource_id=sc-domain%3Awww.yourdomain.com) and enter your page or site into the tool and submit.

For more information you can [read about it here](https://support.google.com/webmasters/answer/9689846?hl=en).

Doing this will remove your page or site for up to 6 months.

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

**Meta Tags** 📓

To permanently remove it you will need to tell Google not to index your page using the [robots meta tag](https://developers.google.com/search/reference/robots_meta_tag).

You add this into any page that you do not want Google to index.

```html
<meta name="robots" content="noindex">
```

For example:

```html
<!DOCTYPE html>
<html>
<head>
    <meta name="robots" content="noindex" />
    <title>Robots</title>
</head>
<body>
You do not want Google to index this page
</body>
</html>
```

**Inspect** 🔎

Once you have removed your page or site using the removal tool and used meta tags to stop it being indexed again in the future you will want to keep an eye on your domain and inspect the page(s) or site you removed.

To view your pending removals login to the [Google Search Console](https://search.google.com/search-console/about) and choose the Removals tab.

From here you can submit new pages for removal and generally inspect your website and how it is managed by Google’s index.

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

**Summary**

To recap, when you want to remove a page or site from Google search index you need to…

- Use the [Google Search Removal Tool](https://search.google.com/search-console/removals?resource_id=sc-domain%3Awww.yourdomain.com) to remove temporarily.
- Permanently remove using [robots meta tag](https://developers.google.com/search/reference/robots_meta_tag)

Hope this helps others or me from the future!

Success 🎉
Build A Simple CLI Tool using Deno
Tags: deno, cli, programming
Published: 2020-09-10 05:47:37

---
title: Build A Simple CLI Tool using Deno
published: true
date: 2020-06-08 00:00:00 UTC
tags: Deno,CLI,Programming
canonical_url: https://www.loginradius.com/engineering/blog/build-a-cli-tool-using-deno/
---

What is Deno? Deno is a JavaScript/TypeScript runtime with secure defaults and great developer experience. It's built on V8, Rust, and Tokyo. I suggest you watch these talks by Ryan: He talks about his mistakes with Nodejs here and a more in-depth look into deno here Features…

   
[Read On](https://www.loginradius.com/engineering/blog/build-a-cli-tool-using-deno/)
How to be anti-racist , according to Black folks who work in tech
Tags: blacklivesmatter, wecoded
Published: 2020-06-07 23:50:06

It's been another tough week, amongst many in the last ten years where black, brown and queer people of colour are inundated with requests and commentary on the heightened awareness of what the world realizes is their daily experience, at least for the duration of the news cycle. 

I want to direct us to the voices of people that have been speaking out on the issue for years. If you would like to support, please follow them and give their media a read. Don't just *like* this post.

Bookmark their links, follow them online, use them to find more resources, or act on their suggestions. Doing anti-racism is very difficult and challenging, and the ideas that are featured in so many company statements all started from their experiences.

{% twitter 1268927181897564166 %}

[The Failed Allyship of the Booming Tech Industry](https://blacktechpipeline.substack.com/p/the-failed-allyship-of-the-booming) By [Pariss Athena](https://twitter.com/ParissAthena)

[White Guyde To The Galaxy](https://tatianamac.com/posts/white-guyde/) and [Save the Tears: Save the Tears: White Woman's Guide](https://tatianamac.com/posts/save-the-tears) by Tatiana Mac


{% twitter 1269515872558817282 %}

{% twitter 1269307760891424773 %}

{% twitter 1268991726556938240 %}

{% twitter 1269766814675992577 %}

{% link https://dev.to/kawhyte/i-m-a-software-engineer-wearing-a-mask-but-it-s-not-covid-19-related-35n3 %}

{% twitter 1269396203738812416 %}

{% twitter 1266542602997977088 %}
How to Create a Minecraft Server: Server Optimizations
Published: 2020-06-07 23:34:50

The following optimizations can be made in game using the Minecraft command line. This is accessed by the `/` key.

### Modifying Gamerules

You can read more about gamerules on the [Offical Minecraft Wiki](https://minecraft.gamepedia.com/Commands/gamerule)

Next we want to disable fireTick, this prevents fire from spreading. This reduces lag from accidental fires, and lava lakes burning down an entire forrest. We change the gamerule by typing:

```
/gamerule doFireTick false
```

The gamerules that I change are:

1. doFireTick=false: to prevent lag and destructive accidents
2. doPatrolSpawning=false: prevent patrols from spawning and thus triggering raids in villages. This may be contriversial, but I have a limited amount of time in a day to play, and I do not want to spend it all dealing with raids. If I ever want a raid, I can turn it back on

### Pre-generating terrain

Minecraft can read the `level.dat` file much faster than it can generate terrain. The `level.dat` file contains all information about the entities and blocks in a Minecraft world, Only the information about the areas that have been visited by the user. So before you have a bunch of players join and run arround each of them forcing the server to generate the areas they are exploring you will experience lots of lag. To avoid this I recommend flying around in spectator mode to load in the main area. I typically try and generate all the area within 1 2000-4000 block radius. (\*Note that this will make your world file size reach into the GB).

You can enter spectator mode using the following command:

```
/gamemode spectator
```

You can then get back to survival mode by:

```
/gamemode survival
```

The reason you want to use spectator mode over creative mode is that you can use the scroll wheel to change the speed that you are able to fly around.

For more information on this watch [Xisumavoid's video on Pre-Generating minecraft worlds](youtube.com/watch?v=eA35S2GW-jI&t=515s). Note that his version of pre-generating is far more complicated than mine.
How to Create a Minecraft Server: Choosing a Host
Tags: minecraft, linode, ubuntu
Published: 2020-06-07 23:16:42

For this I chose [Linode](https://www.linode.com/). Honestly I am a sucker for advertising and I have heard a million YouTubers mention Linode, and I was able to get a bill credit using one of their affiliate links.

I am also aware that there are cheaper alternates that require much less work than what I did, but I wanted to exercise my knowledge on servers and have as much control over it as possible. 

### Initial Setup

To start I selected the $10/Month plan which gives you:

* 2 GB RAM
* 1 CPU Core
* 50 GB SSD
* 2 TB Transfer
* 40 Gbps Network In
* 2000 Mbps network Out

This worked okay for the first little bit when there where just two people on my Minecraft server. You will also be using 100% of your CPU core 100% of the time. Linode will remind you of this with a weekly email.

I decided to upgrade to the next tier to improve performance. I know that [Digital Ocean](https://www.digitalocean.com/) has a larger range of tiers to choose from (which are typically $5 /month cheaper than Linode), but I was already with Linode and changing seemed link a pain at the time. I may end up making the switch in the future.

### Current Setup

My current package from Linode costs $20/Month + $2.5/Month for automatic backups. This gives me the following specifications:

* 4 GB RAM
* 2 CPU Cores
* 80 GB SSD
* 4TB Transfer
* 40 Gbps Network In
* 4000 Mbps Network Out

## Setting Up The VPS

I started off with making sure the packages I wanted were installed with the following command:

```bash
sudo apt install default-jre vim ufw screen wget
```

* `default-jre` is the java runtime environment used to run our Minecraft server
* `vim` is my editor of choice (you can also use nano, both of these editors are often installed by default)
* `ufw` is an **U**ncomplicated **F**ire**W**all
* `screen` is a terminal multiplexor that is required for running the Minecraft server
* `wget` is used to download files from the internet

### Creating the users

For security purposes we are going to create two users, one with `sudo` and one without.

**Adding the privilaged user**:

```bash
useradd -m <username> -G wheel -s /bin/bash
passwd <username>
```

**Adding the non-privilaged user**

```bash
useradd -m minecraft -s /bin/bash
passwd minecraft
```

Why create 2 users? I have not ready any other tutorials that use this method, but I like the idea of my servers files and processes being owned by a user that does not have root privileges. You don't need root privileges in order to run a Minecraft server, and therefore, I think you should not have it. 

For more information you can read the Debian wiki post [Why Sudo?](https://wiki.debian.org/sudo)
Monitor Amazon Price Changes
Tags: amazon, pricemonitoring, webscraping
Published: 2020-06-07 22:59:12

This article demonstrates how to use the web site monitor to check a product's price on Amazon periodically and send email when price changes.

## Amazon Page Info
Let's pick an Amazon Kindle as an example. The shopping URL is
```
https://www.amazon.com/All-new-Kindle-Oasis-now-with-adjustable-warm-light/dp/B07F81WWKP/ref=sr_1_9?dchild=1
```
* Use Chrome browser to open the URL. Right click on the price area and select "Inspect" menu.
  
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mys8nosjsbleuizygbjb.png)

  The HTML source is shown below:
    ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qogvavzz37sikb5dk9i6.png)

  So we can look for a "td" node with "id" being "priceblock_ourprice_lbl", and its text node value is "Price:", and the real price is in the subsequent "span" node with "id" being "priceblock_ourprice".  

## Configure SMTP server
    
SMTP server needs to be configured first for sending email on alarm

1. Select "Setting/SMTP Server" menu:
![SMTP](https://dev-to-uploads.s3.amazonaws.com/i/f5w819qagfo4w6c6t82y.png)

2. Enter SMTP server parameters. We use gmail as an example:
![SMTP](https://dev-to-uploads.s3.amazonaws.com/i/uyptpte58nwi9186ozsz.png)

  Then press "Send Test Mail" to check if the SMTP server has been configured successfully.
  

  
## Configure [SysUpTime](http://ireasoning.com/network-monitoring-software.php)

* Add a web site monitor:  
  ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/a9xap38e9biby4gz094x.png)

    In the URL field, enter
  ```
  https://www.amazon.com/All-new-Kindle-Oasis-now-with-adjustable-warm-light/dp/B07F81WWKP/ref=sr_1_9?dchild=1
  ```

* Press "Configure" button next to the "Threshold settings".  
  ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/f3y0n0d9lmh0xxmizfzo.png)

  Move "body response time" to the left and move "content match" to the right panel.

* Configure it to use simple content match, and choose
"Line contains" radio button, enter. 
  ```
  engine_daemon_container_states_containers{state="running"}
  ```
  to the text field of "Line contains". In the token field, enter "2".
  The value is the second token of the line.
  ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/357nu3yitbp764rck66p.png)

* In the threshold field, enter 340, so that an alarm will be raised when price drops below 340.
  ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/pzkqqlxiaib58lmuxqy7.png)

  Press "Ok" buttons to go back to the screen at step 1.
* In the following screen
  ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/a9xap38e9biby4gz094x.png)

  Press "Configure" button next to the "Actions"

* Enter your email address to receive email notification when price drops below threshold:  
  ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/aa9ies1ai7tqgp11o87c.png)
    
* Press "Ok" buttons to save the monitor.

* (Optional) In the "Manage Monitor" dialog, select the newly created monitor and press "Chart" button to see the real time chart.
  ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0hb9ssbu0dj0ywn4cpcv.png)
Immutability and Mutability in Javascript
Published: 2020-06-07 22:57:53

I usually think that a variable is mutable only if its value can be changed. This may be true to some extent but I find it confusing. A quote from [MDN about Mutable variable](https://developer.mozilla.org/en-US/docs/Glossary/Mutable)

> /Mutable/ is a type of variable that can be changed. In [JavaScript](https://developer.mozilla.org/en-US/docs/Glossary/JavaScript) , only [objects](https://developer.mozilla.org/en-US/docs/Glossary/Object) and [arrays](https://developer.mozilla.org/en-US/docs/Glossary/Array) are mutable, not [primitive values](https://developer.mozilla.org/en-US/docs/Glossary/primitive) .

So, a number or string are immutable but array and objects are mutable. But also if I have a variable:

```js
var number = 5;
var string = 'Bola';

console.log(number); // Outputs 5
console.log(string); // Outputs Bola

number = number + 1;
string = string + ' Buari';

console.log(number); // Outputs 6
console.log(string); // Outputs Bola Buari
```

This means the variable `number` was changed from `5` to `6` and the variable `string` was changed from `Bola` to `Bola Buari`.🤔

These variables were changed but that does not make them mutable. This means that when `number` and `string` was changed, they became a new value.

A good example to illustrate this is copying the variables and changing the copied variable. if the variable is mutable the original variable is changed, if it's immutable the original variable is not changed since chasing it creates a new variable of its own.

```js
var originalNumber = 20;
var copiedNumber = originalNumber;
copiedNumber = copiedNumber + 10;

console.log(originalNumber); // Outputs 20 (Not changed)

var originalString = 'Bola';
var copiedString = originalString;
copiedString = copiedString + ' Buari';

console.log(originalString); // Outputs Bola (Not changed)

var originalArray = [1, 2];
var copiedArray = originalArray;
copiedArray.push(3, 4, 5);

console.log(originalArray); // Outputs [1,2,3,4,5] (Changed)

var originalObject = { name: 'Bola', gender: 'Male' };
var copiedObject = originalObject;
copiedObject.job = 'Developer';

console.log(originalObject); // Outputs {name: 'Bola', gender: 'Male', job: 'Developer'} (Changed)
```

As seen in the above examples, when copies of array and object are changed, the original variable is changed while for primitive types like string and number, the original variables are not changed.

What makes me understand immutability more clearly is this, immutable variables are variables that do not change when their copy is changed while mutable variables changes when their copy is changed.

### Resources

- [Mutable - MDN Web Docs Glossary: Definitions of Web-related terms | MDN](https://developer.mozilla.org/en-US/docs/Glossary/Mutable)
Security Troller
Tags: security, php, base64, binary
Published: 2020-06-07 22:56:19

---
title: Security Troller
published: true
description: A simple project for fun
tags: security, php, base64, binary
//cover_image: https://direct_url_to_image.jpg
---

Hello, i have developed a small library to crypt and decrypt a string

Hope you will enjoy using it

Git: https://github.com/salimmejdoub/security.troller
Material Tab Styling in Angular for a CSS Tool
Tags: angular, material, typescript
Published: 2020-06-07 22:39:16

Angular's View Encapsulation design, sometimes makes it almost impossible to write a style for Material components. One of them is the mat-tab.
```typescript
 <mat-tab-group>
   <mat-tab  *ngFor="let item of data; index as i" [label]="i">
    <ng-template mat-tab-label>
      <div class='mytabstyle'>
      {{i}}
      </div>
    </ng-template>
     <div class='margin1em'>
        // Your content here for each item
     </div>
   </mat-tab>
 </mat-tab-group>
```

Change the mat-tab-labels display style.

```typescript
  ngAfterViewInit() {
    let mt = 
    (document.getElementsByClassName('mat-tab-labels'))[0] as HTMLElement;
    mt.style.display='grid';
    mt.style.gridTemplateColumns='repeat(auto-fit, minmax(3em, 1fr))'
  }
```
We use the now famous HTML5 grid, setting each tab width to 3em.

Here's the tab template CSS class 'mt'
```css
.mt {
    align-items: center;   
    box-shadow: 0px 1px 1px inset midnightblue;
    box-sizing: border-box;
    cursor: pointer;
    display: grid;
    grid-template-columns: 3em;
    height: 27px;
    justify-content: center;
    opacity: 0.6;
    white-space: nowrap;
}
```


It's a good start, but there's still some work to do on the selected tab underline... Note we did not parse a single style sheet, it was already done by the browser, we just pulled the parsedText to display here.

![csslexer](https://dev-to-uploads.s3.amazonaws.com/i/pi9x6kfq4jths21eb24a.gif)

JWP2020 CSS parser
JWP2020 Material Tabs