teleren/devto huggingface dataset:
How to access micro-services (pods) in Kubernetes that are not publicly available
Tags: kubernetes, docker
Published: 2020-01-31 20:19:27

Imagine this scenario: You are developing an API on your machine and everything works well, then you deploy it on a Kubernetes cluster. Now you want to test if the API works on Kubernetes, but without exposing it to the public.


To demonstrate this, I have a fresh install of [Minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/) so:
```shell
❯ kubectl get pods
No resources found.
```
I will deploy a simple **echoserver** image to have something to make requests to.
> echoserver is like an API that returns (echoes) back what you sent it

I have a `yaml` config in this [gist](https://gist.github.com/solev/4ff8c43e0d003b99b76a99082196575c) for that

```shell
❯ kubectl apply -f https://gist.githubusercontent.com/solev/4ff8c43e0d003b99b76a99082196575c/raw
deployment.apps/echoserver created
❯ kubectl get pods
NAME                          READY   STATUS    RESTARTS   AGE
echoserver-867b47487f-rhc62   1/1     Running   0          28s
```

The pod is running now and is configured to listen to port `8080` as configured in the yaml. Now if we try to do a request, it will fail because the pod is not accessible:
```shell
❯ curl localhost:8080?hello=world
curl: (7) Failed to connect to localhost port 8080: Connection refused
```

In order to access it, there is a command called `port-forward` in **kubectl** that lets you forward any request on your local machine to a specific deployment on kubernetes.

```shell
❯ kubectl port-forward deployment/echoserver 3000:8080
Forwarding from 127.0.0.1:3000 -> 8080
Forwarding from [::1]:3000 -> 8080
```

What this means is now every request on `localhost` port `3000` will be forwarded to the `echoserver` pod on port `8080`. So now if we try the same request:

```shell
❯ curl localhost:3000?hello=world
CLIENT VALUES:
client_address=('127.0.0.1', 56394) (127.0.0.1)
command=GET
path=/?hello=world
real path=/
query=hello=world
request_version=HTTP/1.1

SERVER VALUES:
server_version=BaseHTTP/0.6
sys_version=Python/3.5.0
protocol_version=HTTP/1.0

HEADERS RECEIVED:
Accept=*/*
Host=localhost:3000
User-Agent=curl/7.55.1
```

And that's about it. Thanks for reading, catch ya in the next one.
How do you make your old MacBook work?
Tags: help
Published: 2020-01-31 11:39:41

---
title: How do you make your old MacBook work?
published: true
description: Is it possible to resurrect a zombie?
tags: help
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/yxgdcs8gfpelfy13jfhu.png
---

I'm a web developer.

My main working machine is `iMac` and it's fantastic.

My portable device is `MacBook Air` (5yo) and working on it becomes torture when I deal with big projects (Node.js mostly), several parallel processes and a decent IDE.

I like the laptop because it's small (13-inch) lightweight and works long hours without a recharge. But I hate the experience of dealing with frozen processes and slowly running compilers.

Did (or do) you have a similar experience? Do you have any tricks to make an old machine work faster? Probably some alternative software or CLI tools for web developers to make life easier?

I'm aware of the common ways to enhance macOS performance (_like [this one](https://macpaw.com/how-to/speed-up-mac) or similar_), but I'm looking for dev-specific tips (_like "use vim instead of VS Code", or "roll back to older macOS version", or something_), hidden gems to let my old aluminum friend live and work for a year or two more.

**Please, share your experience, I would highly appreciate any small advice!**

_Also if you have practical experience of comparing old machines' performance with newer "slim" options (12- and 13-inch MacBooks of 2019) for development purposes, please share that as well. It would greatly help me to decide do I need a new Pro-line laptop or lighter version would be enough._
DYK: Inspect and trigger media queries in chrome
Tags: productivity, webdev, tooling
Published: 2020-01-31 14:53:29

Did you know you can trigger media queries right in chrome?

Open the developer tools (`F12` / `Ctrl+Shift+I`), select device mode ![devicemode](https://dev-to-uploads.s3.amazonaws.com/i/7qc0tvqg4ltg9grguptj.png) and then click on the top bar right below the preset screen sizes!

![media queries](https://dev-to-uploads.s3.amazonaws.com/i/8w591owia8syk62dtjt6.png)

![select bar](https://dev-to-uploads.s3.amazonaws.com/i/syipb6h91wg4o3rvjdt3.png)

Aaaaand you can test your media queries with this little tool!
How to Deploy Node.js and MongoDB easily?
Tags: node, mongodb, deploy, cloud
Published: 2020-01-31 22:02:09

---
title: How to Deploy Node.js and MongoDB easily?
published: true
description: This is a guide to deploy Node.js apps with MongoDB easily on the cloud
tags: node, mongodb, deploy, cloud
---

Deploying web apps with database isn't an easy task at all specifically when you want your app to load smoothly and fast and also be scalable. So in this guide you'll learn how to deploy your web app easily on the cloud.
### 1. Create Account on DPLYR
DPLYR is the tool we're using today. To create an account go to [https://dplyr.dev](https://dplyr.dev/) 
![DPLYR front page](https://ph-files.imgix.net/062f4ddb-ab8d-4016-bb2c-5c33fe3d72ce?auto=format&auto=compress&codec=mozjpeg&cs=strip&w=379.7389213328753&h=380&fit=max&dpr=2)
### 2. Create a VM on your favourite cloud services provider
Choose the cloud provider you love. I found that DPLYR has made a complete guide on how to create a VM on AWS EC2 [Here it's](https://blog.dplyr.dev/how-to-create-a-aws-ec2-vm-for-dplyr/)
### 3. Fill the new deployment form 
When you sign in you'll find yourself in your home page where you can find your past deployments click on the new deployment button and fill the form fields note that if you used the DPLYR VM guide you won't need to fill the username field. Choose the technology "Node.js" and the database "MongoDB" the database username password are the ones you used in your connection string pick whatever you want. In the project URL field put the git repo containing your web app link.
![DPLYR form page](https://ph-files.imgix.net/bf2a3828-c0cf-4970-8319-2197f8ec91c2?auto=format&auto=compress&codec=mozjpeg&cs=strip&w=681.8843683083512&h=380&fit=max&dpr=2)
### 4. VOILA!!! the website is now deployed
DPLYR magically deploys your app and gives you the link of the website
Laravel Pipeline Interpretation with Example
Tags: laravel, pipeline, designpattern
Published: 2020-01-31 19:27:00

Hey Artisan,

Today we learn about pipeline design pattern. Using laravel pipelines you can pass an object between several classes in a fluid way to perform any type of task and finally return the resulting value once all the “tasks” have been executed.

Larval uses the Pipeline Design Pattern in a couple of places throughout the framework. This means everything we need to implement this pattern is already part of the foundation of your application!

https://www.codechief.org/article/laravel-pipeline-interpretation-with-example
[VIDEO] Creating Model Relationships in a Swift API 🌚♥️🌝(Swift 5.1/Vapor 3)
Tags: thetealpickle, backend, swift, vapor
Published: 2020-02-01 12:58:13

---
title:[VIDEO] Creating Model Relationships in a Swift API 🌚♥️🌝(Swift 5.1/Vapor 3) 
published: true
description: 
tags: #thetealpickle #backend #swift #vapor
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/bcjxcgj2dularn9fll98.png
---

In this video, @THETEALPICKLE walks through creating relationships between models within a Swift-based API. The Swift API created in this video leverages the Vapor 3 framework. Models naturally interact with other models and in Vapor these model interactions are made possible by creating relationships. There are two types of relationships, one-to-many and many-to-many.<br>

Code for this video can be found on @THETEALPICKLE’s GitHub at 👉🏾 [cheese-api-swift repository](https://github.com/thetealpickle/cheese-api-swift)<br>
Want to follow along? Get the starter code at the cheese-api-swift repository on the 👉🏾 [vapor-relationships-start branch](https://github.com/thetealpickle/cheese-api-swift/tree/vapor-relationships-start) 



{% youtube 0O1gUAOloQg %}


<h1>One 👆🏾 to Many ✋🏾✋🏾✋🏾✋🏾✋🏾</h1>
A one-to-many relationship is referred to as a Parent/Child relationship. There is one parent model object which can map to many child objects. For example, a pet owner can have multiple pets, while each individual pet has one owner. In this scenario, the Owner model is the Parent model and the Pet model is the Child model. 

<h1>Many ✋🏾✋🏾✋🏾✋🏾✋🏾 to Many ✋🏾✋🏾✋🏾✋🏾✋🏾</h1>
A many-to-many relationship is referred to as a Sibling relationship. Each sibling model object can map to many objects of the other sibling model, and vice versa. Continuing with the pet example, a pet can play with multiple toys and multiple toys can be played with by multiple pets. In this scenario, the Pet model and Toy model have a sibling relationship. Each model can map to multiple objects of the other model.<br>

<h1>Relationships in Vapor</h1>
Vapor makes setting up relationships between models relatively straight forward. With Parent/Child relationships, the models are extended to have a computed property which returns the parent/children. With Sibling relationships, the models are linked using a Pivot model which stores the mapping between the sibling object ID’s. The pivot acts as the middle-women between the two models, the Sibling models are then extended to have a computed property based off of the pivot which manages and returns the siblings.<br>


Working with Parent/Child relationships differ from Sibling relationships, as a safe guard must be added in the form of a foreign key constraint. Adding a foreign key constraint prevents the following (1) a child from being added to a nonexistent parent object, (2) the parent model table from being deleted prior to deleting the child model table, (3) the parent model object is not deleted until all children objects are deleted.<br><br>



<b>@thetealpickle on the internet. Namaste.<br> 
Brought to you by JESSICA JEAN JOSEPH © THETEALPICKLE</b>
Change cursor animation in VSCODE
Tags: webdev, vscode, settings
Published: 2020-02-01 17:41:20

## Introduction

Today I want to share a very basic configuration to change the cursor animation in the visual studio code editor.


## Steps

1. Click on the option ```code``` -> ```preferences``` -> ```setting```.

2. We look for the ```Cursor Blinking``` settings in the search bar.

3. We choose the animation that we like most in the drop-down.

4. Let's enjoy it. :stuck_out_tongue_winking_eye:


## Animations demo

#### Smooth

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

#### Phase

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

#### Expand (my favourite) :heart:

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

#### Solid 

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


So far this configuration thanks for reading me. :blush:
Typed Properties In PHP Are Neato
Tags: php
Published: 2020-02-01 23:17:15

Until recently, for a PHP and JavaScript developer, avoiding bugs caused by variables being the wrong type was difficult, beacuse the langues are not strongly-typed. Thanks to PHP7 and TypeScript, we can opt-in to more type safety, which I like.

PHP7 added scalar type hinting to function parameters, as well as return types. This makes the getter and setter pattern very useful. By protecting a property and a protected property, we can prevent a property from being set to the wrong type -- from outside of the object's scope. This pattern looks like this:

```php
class User {
	/** @var string */
	protected $firstName;

	public function getFirstName(): string {
		return $this->firstName;
	}
	public function setFirstName(string $firstName) : string
	{
		$this->firstName;
		return $this;
	}
}
```

That's cool, and while it's a lot less boilerplate than it would be in PHP5, it's still a pretty complex way to implement a string property on an object. This class has two public methods that need test coverage, which adds up. 

Having a property that acts public, but also is constrained by type, is nice. I think the popularity of Laravel backs up this opinion. And yes, [I can use magic methods](https://torquemag.io/2016/05/wordpress-developers-need-know-php-magic-methods/) to make something like a Laravel model.

Also, [PHP 7.4 has typed properties](https://laravel-news.com/php7-typed-properties) and they are neato.

## Refactoring PHP With Typed Properties

So, I can now rewrite that class, with no methods:

```php
class User {
	public string $firstName;
}
```

In addition to being less code, I don't need to write a test for this. However this class gets used in integration tests by other classes, my IDE and [a static analysis tool](https://github.com/phpstan/phpstan) all prevent it from being used wrong.

In the first example, nothing stopped me from setting `$firstName` to an array from another method of this class. Now the program will not let me make that mistake. Machines are better at remembering stuff than me, so that's great.

## But Wait. There Is A Catch!

One catch though, Ok, technically, it's a potential error that you can catch...

You can not read a property before it is set for the first time:

```php
//This works
$user = new User();
$user->firstName = 'Roy';
echo $user->firstName;

//This throws an error
$user = new User();
echo $user->firstName;
```

This problem is also present in the older method. In both cases, a default value of the property could be set. Or I could just not use the property before setting. Depends on how the program is run. I don't like the possibility of the code being used wrong, beacuse lots of people I don't know run code I write.

One solution is to hardcode the default value:

```php
class User {
	public string $firstName = 'Roy';
}
```

That keeps the code minimal, which is nice. I do think writing the class so that the property HAS to be set on initialization is a good option as well:

```php
class User {
	public string $firstName;

	public function __construct(string $firstName)
	{
		$this->firstName = $firstName;
	}
}
```
Replication in AEM(Adobe Experience Manager)-Part 2
Tags: aem, java
Published: 2020-07-07 16:09:26

In my previous [post](https://dev.to/jerinraj55551/replication-api-in-aem-adobe-experience-manager-405n), I have explained Replication in detail. In this post, I will explain how to activate/deactivate the content(asset and web page) by reading the path from an excel file.

* Once I get the path of the excel file from the servlet then need to check if the path exists in the system or not.
* If the file exists in the asset folder then convert it as a Workbook and read the row and column.
* If the data in the cell is valid and the path exists then the page and assets paths are replicated one by one.

```javascript 
       String path = "/content/dam/sample.xls"
	Session session = resolver.adaptTo(Session.class);
	if (session.itemExists(path)) {
// Creating a Workbook from an Excel file (.xls or .xlsx)
Workbook workbook = WorkbookFactory.create(asset.getOriginal().getStream());
// Getting the Sheet at index
Sheet sheet = workbook.getSheetAt(sheetNo);
// Create a DataFormatter to format and get each cell's value as String
DataFormatter dataFormatter = new DataFormatter();
for (Row row : sheet) {
    Cell cell =row.getCell(columnId);
    String cellValue = dataFormatter.formatCellValue(cell);					 
      if(StringUtils.isNotBlank(cellValue) && 
               (cellValue.startsWith("/content")&& 
                  session.itemExists(cellValue))) {
        replicateContent(cellValue,session,isReplicate);
	activatePageAssets(cellValue,session,isReplicate);
}
}
}


```
* The function `replicateContent` will accept session instance, web page link, and status for identifying which operation to be performed.
```javascript 
private void replicateContent( String path,Session session,boolean isReplicate) 
     {

    try {
            if (isReplicate) {
                replicator.replicate(session, ReplicationActionType.ACTIVATE, path);
            } else {
                replicator.replicate(session, ReplicationActionType.DEACTIVATE, path);
            }

    } catch (ReplicationException e) {
            e.printStackTrace();
    }
}
```
* Next, we want to publish the assets as well right? so we need to find the path of the assets associated with the page. 
* The following code snippet will return the path of the assets associated with each page.
```javascript 
AssetReferenceSearch search = new AssetReferenceSearch 
	(jcrNode, DAM_ROOT, request.getResourceResolver()); 
Map<String,Asset> result = search.search();
result.keySet()
```
* Once we get the path of the asset (`result.keySet()`) then we will iterate one by one and replicate the asset  by calling `replicateContent( String path,Session session,boolean isReplicate)` .

If you think there is a more efficient way to achieve the same, please leave a note in the comments. Happy coding😊!
Imagine there's a whole new app like this
Published: 2020-02-09 12:09:27

When I initiated my startup, it was not our original idea. Back then, without an office, we simply worked at this or that cafe. Working remotely was a real challenge. Syncing our thoughts and communicating effectively was tough.

We realized we needed something new: a platform that seamlessly integrated a virtual whiteboard and a meeting room through the cloud. BeeCanvas enables remote teams to be just as productive as if they were sitting in the same room. Let’s shape the future of work together!

Check this out: https://early-access.beecanvas.com/
Daily Developer Jokes - Sunday, Feb 9, 2020
Tags: jokes, dailydeveloperjokes
Published: 2020-02-09 13:00:19

---
title: "Daily Developer Jokes - Sunday, Feb 9, 2020"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
cover_image: "https://private.xtrp.io/projects/DailyDeveloperJokes/thumbnail_generator/?date=Sunday%2C%20Feb%209%2C%202020"
published: true
tags: #jokes, #dailydeveloperjokes
---

Generated by Daily Developer Jokes, a project by [Fred Adams](https://xtrp.io/) ([@xtrp](https://dev.to/xtrp) on DEV)

___Read about Daily Developer Jokes on [this blog post](https://xtrp.io/blog/2020/01/12/daily-jokes-bot-release/), and check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/).___
### Today's Joke is...
![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1259369613c.png)

---
*Have a joke idea for a future post? Email ___[xtrp@xtrp.io](mailto:xtrp@xtrp.io)___ with your suggestions!*

*This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit.*

<!-- 
Joke text:
___Q:___ How does a sysadmin keep a fire going?

___A:___ They rotate the logs.
 -->
How Much a Full Time Open Source Contributor Earn ?
Tags: help, opensource, github, discuss
Published: 2020-02-09 17:45:21

---
title: How Much a Full Time Open Source Contributor Earn ?
published: true
description: 
tags: help , open source , github , discuss
---

To be honest I'm part time open source contributor from Pakistan with 1K+ Contributions in 2019 on github but i earned 0$ from open source and joined two organizations also.

Can you help me to answer these questions? So i want to ask these questions . 
**1) How full time open source contributor earn?
2) How to earn from open source?
3) How much you earn from open source?
4) How much a full time open source contributor earn?**
var, let, or const in Javascript ES6+??
Tags: javascript, es6, beginners
Published: 2020-02-10 00:31:13

In order to keep code clean and purposeful in Javascript, it is necessary to understand the differences between each of the identifiers. Being able to determine when a particular identifier is most appropriate can be a little tricky so here is a quick guide that should clear things up for you. 

## Var (don't use it)

As a general rule, avoid using `var`. `var` declarations are either globally or functionally scoped. They can also be re-declared and updated. The weakness here is that you could accidentally redeclare a `var` without any error, leading to a buggy program. The only place I might use `var` is when testing code in the console.

## Let

`let` is block scoped and can be reassigned but not re-declared. It’s perfect for a loop counter, or a value swap in an algorithm. Since it’s block scoped, the variable will only be used in the block (the code wrapped in {}'s) it’s defined in, which is not always the entire containing function.
 
## Const (a good default)

Similar to `let`, `const` declarations are also block scoped. What sets `const` apart is that it cannot be reassigned or re-declared. This means that every `const` declaration must be initialized at the time of declaration. 

## Summary

Scope is the most significant difference between the old-fashioned `var` and the modern `let`/`const`. To demonstrate the differences in scope:

```javascript
if (true) {
  var foo = 'hello!';
  let bar = 'hi there!';
  const baz = 'howdy!';

  console.log(foo); // 'hello!';
  console.log(bar); // 'hi there!';
  console.log(baz); // 'howdy!';
}

console.log(foo); // 'hello!';
console.log(bar); // ReferenceError: bar is not defined
console.log(baz); // ReferenceError: baz is not defined
```

| keyword 	| scope    	| reassignable? 	|
|---------	|----------	|---------------	|
| var     	| function 	| yes           	|
| let     	| block    	| yes           	|
| const   	| block    	| no            	|

Your go-to identifier in Javascript should be `const`. However, if you know or think you’ll need to reassign it (in a for-loop, switch statement, or in algorithm swapping, for example), use `let`.
How can i catch exceptions in a few methods?
Tags: help, php, laravel
Published: 2020-02-10 03:38:52

Hi everyone!
I have a PHP class for file upload and methods for upload and resize, which return an object of the class.
How i call methods in a controller:
$imageUploader->upload();
or
$imageUploader->upload()->resize();

Each method contains some exceptions. Right now i catch exceptions in each method, what is not correct. I don't want to catch it in the controller. So how can i catch all exceptions in one place?
Web server in pure Java
Tags: java
Published: 2020-02-10 07:49:47

---
title: Web server in pure Java
published: true
description: We talk about how to create a simple web server using only native java code, no libraries and the simple interface used for these actions.
tags: java
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/v9veigkh91cg66x6zf2u.jpg
---

{% youtube KlKVxmeKAzE %}

We talk about how to create a simple web server using only native java code, no libraries and the simple interface used for these actions.