teleren/devto huggingface dataset:
How to update WordPress with WP-CLI
Tags: wordpress, wpcli
Published: 2019-12-16 13:05:18

---
title: How to update WordPress with WP-CLI
published: true
description: How to update WordPress with WP-CLI
tags: WordPress,WP-CLI
---

When updating WordPress it is convenient to use [WP-CLI](https://wp-cli.org/).

## How to use

### Display the installed version

```
wp core version

# Show extended version information
wp core version --extra
```

### Update to the latest version

```
wp core update
```

### Update in your preffered language

```
wp core update --locale=ja
```

### Update to a specific version

```
wp core update --version=5.3
```

### Downgrade to an old version

```
wp core update --version=5.2 --force
```
On becoming a better developer
Tags: todayilearned, beginners, career, programming
Published: 2019-12-16 13:00:11

*TL;DR style notes from articles I read today.*

### [5 developer environment hacks to increase productivity](http://bit.ly/2LFZNR9)

- Use iTerm2 or Bash to know which Git branch you are working on and its status. 
- Use Tmux to manage multiple window splits with fast shortcuts and hot-keys. The screen function also lets you suspend sessions and return to them later.
- Shell Aliases are handy to remember the syntax for tedious commands and long-winded texts.
- Organising code directories helps differentiate between cloned repositories and something you might be tinkering with locally.
- Ripgrep is way faster than git-grep and can blaze through lines and lines of code to find what you’re looking for quickly. 

*[Full post here](http://bit.ly/2LFZNR9), 4 mins read*

---

### [Become a better developer by mastering the superpower of deep work](http://bit.ly/2RIOCeB)

- Deep work is the ability to focus without distraction on a cognitively demanding task, to produce results in less time. To develop a good deep work habit, add routines to your work life. 
- Check your agenda for important meetings and plan your day’s deep work sessions, breaks, and shallow work.
- Arrive at work well before colleagues, when there is no noise, no meetings & no demands that require context switching.
- Once your teammates arrive, take a social break or do some shallow work - answer emails, check feeds, engage in the daily scrum. Then tackle another deep work session.
- Create a shutdown ritual to end the day - answer important emails, update task statuses and do small tasks that help you prepare for tomorrow. 
- Once you leave, practice stopping to think about work. If you can, turn off work-related notifications. 

*[Full post here](http://bit.ly/2RIOCeB), 15 mins read*

---

### [How to be a rock star developer](http://bit.ly/358ZPZt)

- Write utility code that can be used by all and collaborate with other developers on projects beyond your scope of work.
- Don’t give in to FOMO. Spend time doing the essential work that gets you real results.
- At crunch times, rise to the occasion with a leadership mindset to rally, organize and collaborate.
- Try to be essential but not indispensable. Indispensability eventually leads to burnout.
- Focus on your work integrity, adaptability and the desire to do excellent work. 

*[Full post here](http://bit.ly/358ZPZt), 5 mins read*

---

*[Get these notes directly in your inbox every weekday by signing up for my newsletter, in.snippets().](https://mailchi.mp/appsmith/insnippets?utm_source=devto&utm_medium=post08&utm_campaign=is)*
From TDD to DDD: Building a .NET Core Web API - Part 7
Tags: tdd, ddd, netcore, xunit
Published: 2019-12-16 12:23:29

The complete project can be found here: [https://github.com/lucianopereira86/CRUD-NetCore-TDD](https://github.com/lucianopereira86/CRUD-NetCore-TDD)

## Technologies

- [Visual Studio 2019](https://visualstudio.microsoft.com/pt-br/downloads/)
- [.NET Core 3.1.0](https://dotnet.microsoft.com/download/dotnet-core/3.1)
- [xUnit 2.4.0](https://www.nuget.org/packages/xunit/2.4.0)
- [Microsoft.EntityFrameworkCore 3.1.0](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore/3.1.0)
- [FluentValidation 8.6.0](https://www.nuget.org/packages/fluentvalidation)

## Post User • Theory 
### Red Step • Age

Let's do a **Theory** for the "Age" attribute.

```cs
[Theory]
[InlineData(0, 102)]
[InlineData(-1, 102)]
[InlineData(33, 102)]
public  void Theory_PostUser_Age(int Age, int ErrorCode)
{
    var user = new User
    {
        Age = Age
    };

    CheckError(new PostUserValidator(), ErrorCode, user);
}
```

If you run the tests, there will error for all the values because we have not implemented the validation for the age yet. It must be greater than zero.

### Green Step • Age

Inside the PostUserValidators constructor, add the following lines:

```cs
public PostUserValidator()
{
    RuleFor(x => x.Name)
        .Cascade(CascadeMode.StopOnFirstFailure)
        .NotEmpty()
        .WithErrorCode("100")
        .MaximumLength(20)
        .WithErrorCode("101");

    RuleFor(x => x.Age)
        .Cascade(CascadeMode.StopOnFirstFailure)
        .GreaterThan(0)
        .WithErrorCode("102");
}
```

Run the tests again and this will be the result:

![print12](https://thepracticaldev.s3.amazonaws.com/i/15abr0ay7m3lqkb60qmw.JPG)

Only the valid value (33) has not returned any error, so our tests are working correctly again!

## Post User • Fact II

### Refactor Step II

There is no need for another **Theory** for the "PostUserTest" but another **Fact** is required to validate the data. Rename the "Fact_PostUser" method to "Fact_PostUser_NoValidation" and create another one:

```cs
 [Fact]
public void Fact_PostUser()
{
    // EXAMPLE
    var user = new User(0, "LUCIANO PEREIRA", 33, true);

    var val = new PostUserValidator().Validate(user);

    // ASSERT
    Assert.True(val.IsValid);

    if (val.IsValid)
    {
        // REPOSITORY
        user = new UserRepository(ctx).Post(user);

        // ASSERT
        Assert.Equal(1, user.Id);
    }
}
```

This time we are using the "Assert" class to ensure that the validation will be true before accessing the repository. Run the test again.

![print13](https://thepracticaldev.s3.amazonaws.com/i/n4vr7qpbegc6ko1k0u9j.JPG)

This must be your project so far:

![print14](https://thepracticaldev.s3.amazonaws.com/i/zpa2i9tq9182ppqb52gj.JPG)

## Coming soon...

The PUT method will be the next to receive tests, repository and validation.
From TDD to DDD: Building a .NET Core Web API - Part 4
Tags: tdd, ddd, netcore, xunit
Published: 2019-12-16 12:23:00

The complete project can be found here: [https://github.com/lucianopereira86/CRUD-NetCore-TDD](https://github.com/lucianopereira86/CRUD-NetCore-TDD)

## Technologies

- [Visual Studio 2019](https://visualstudio.microsoft.com/pt-br/downloads/)
- [.NET Core 3.1.0](https://dotnet.microsoft.com/download/dotnet-core/3.1)
- [xUnit 2.4.0](https://www.nuget.org/packages/xunit/2.4.0)
- [Microsoft.EntityFrameworkCore 3.1.0](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore/3.1.0)
- [FluentValidation 8.6.0](https://www.nuget.org/packages/fluentvalidation)


## Post User • Fact
### Refactor Step

We will concentrate the database operations inside a repository class for the user entity.  
Firstly, modify the "Fact_PostUser" method like this:

```cs
[Fact]
public void Fact_PostUser()
{
    // EXAMPLE
    var user = new User(0, "LUCIANO PEREIRA", 33, true);

    // REPOSITORY
    user = new UserRepository(ctx).Post(user);

    // ASSERT
    Assert.Equal(1, user.Id);
}
```

As you can see, it must be created a "UserRepository" class with a "Post" method that must execute that same operations from before.  
Inside the Infra project, create another file inside the "Repositories" folder named "UserRepository.cs" with the following code:

```cs
using CRUD_NETCore_TDD.Infra.Models;

namespace CRUD_NETCore_TDD.Infra.Repositories
{
    public class UserRepository
    {
        private readonly MyContext ctx;
        public UserRepository(MyContext ctx)
        {
            this.ctx = ctx;
        }
        public User Post(User user)
        {
            ctx.User.Add(user);
            ctx.SaveChanges();
            return user;
        }
    }
}
```

Just import the "UserRepository" class inside the "PostUserTest" file and it will compile.  
Run the test again:

![print07](https://thepracticaldev.s3.amazonaws.com/i/ixfdyf5a2b71716snbjl.JPG)

Our refactoring is complete!  
If you have followed the instructions faithfully until here, then your project must be like this:

![print08](https://thepracticaldev.s3.amazonaws.com/i/j7w0bocj6lcgosrku260.JPG)

## Next

We are still far from finishing the POST tests. It's necessary to validate the user attributes before persist them in the database, so let's create our first **Theory**.
From TDD to DDD: Building a .NET Core Web API - Part 2
Tags: tdd, ddd, netcore, xunit
Published: 2019-12-16 12:22:32

The complete project can be found here: [https://github.com/lucianopereira86/CRUD-NetCore-TDD](https://github.com/lucianopereira86/CRUD-NetCore-TDD)

## Technologies

- [Visual Studio 2019](https://visualstudio.microsoft.com/pt-br/downloads/)
- [.NET Core 3.1.0](https://dotnet.microsoft.com/download/dotnet-core/3.1)
- [xUnit 2.4.0](https://www.nuget.org/packages/xunit/2.4.0)
- [Microsoft.EntityFrameworkCore 3.1.0](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore/3.1.0)
- [FluentValidation 8.6.0](https://www.nuget.org/packages/fluentvalidation)


## Topics
- [Test Project](#test-project)
  - [Post User](#post-user)
    - [Fact](#fact)
      - [Red Step](#red-step)

## Test Project

It's time to begin the fun!  
We will build tests for each CRUD method of the User entity by using Entity Framework Core structure.
There will be two types of unit tests: **Fact** and **Theory**.  
**Fact** is a method with a unique result without parameters.  
**Theory** allow multiple parameters expecting for different results.

## Post User

Add a folder named "Tests" to the Test Project with a file named "PostUserTest.cs" with the code below:

```cs
using Xunit;

namespace CRUD_NETCore_TDD.Test.Tests
{
    public class PostUserTest
    {
        #region THEORY
        #endregion
        #region FACT
        [Fact]
        public void Fact_PostUser ()
        {

        }
        #endregion
    }
}

```

### Fact

#### Red Step

Our first test will run what we really want: to register a new user to the database. Write this code inside the **Fact_PostUser** method:

```cs
[Fact]
public void Fact_PostUser ()
{
    // EXAMPLE
    var user = new User("LUCIANO PEREIRA", 33, true);

    // REPOSITORY
    ctx.User.Add(user);
    ctx.SaveChanges();

    // ASSERT
    Assert.Equal(1, user.Id);
}
```

At first, there are no **User** class. Also, the "ctx" object should be an instance of the **DbContext** class, but there is no EF Core library installed yet to make the code to compile.
That is the **Red** step. We know what we want and what we have to do.  
Before going to the **Green** step, change the method's name from "Fact_PostUser" to "Fact_PostUser_NoModelNoRepository", so it becomes clear what is missing for the method to run.


## Next

Let's implement the **Green** step.
PHP jQuery form formData 50: input text textarea checkbox using ajax ($.ajax)
Tags: php, jquery, form, ajax
Published: 2019-12-16 11:26:21

<hr />

<center>Happy Coding</center>

<hr />

index.php

		<form method="post" action="process.php" >

			Firstname: <input type="text" name="firstname" />
			<br />

			Lastname: <input type="text" name="lastname" />
			<br />

			Description: <textarea name="description" rows="10" cols="50" ></textarea>
			<br />

			Hobby (single): <input type="checkbox" name="hobby" value="studying" /> Studying
			<br />

			<hr />

			<input type="submit" value="Submit" />

		</form>

		<hr />


display result form server

		<div id="output"></div>

get formHTML element and add onsubmit event, and create formData, then call ajax function with arguments formHTML, formData and output display ("#output") 

		<script>

			/* submit form */

			// https://api.jquery.com/jquery.each/
			/*
			 *	array.each( function( index, element ) )
			 *	$.each( array, callback )
			 */

			// https://www.w3schools.com/jquery/misc_each.asp

			/* get all form */
			$( "form" ).each( function () {

				/* each form add onsubmit event */
				$( this ).bind( "submit", function (event) {

					event.preventDefault(); // return false


					var formHTML = event.target; // $( this ) => not work !!

					console.log( formHTML ); // formHTML element


					// https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects
					var formData = new FormData( formHTML );

					console.log( formData );


					// https://api.jquery.com/jquery.ajax/
					// https://www.w3schools.com/jquery/ajax_ajax.asp
					// https://www.w3schools.com/jquery/jquery_ref_ajax.asp

					/* AJAX request */
					ajax( formHTML, formData, "#output" ); // ajax( form, data, destination )

				} );

			});

		</script>

ajax function

		<script>

			function ajax( form, data, destination )
			{

				$.ajax({

					method: form.method,
					url: form.action,

					data: data,

					/*
						result type data
						JSON.parse(data)
						http://api.jquery.com/jQuery.ajax/
						https://stackoverflow.com/questions/14322984/differences-between-contenttype-and-datatype-in-jquery-ajax-function
						https://forums.asp.net/t/2087039.aspx?what+is+difference+between+dataType+and+contentType+in+jquery
					*/
					dataType: "HTML",

					/* formData */
					contentType: false, // formData with $_POST or $_FILES in server (PHP)
					processData: false

				})

				/* handle success */
				.done( function(result) {

					$( destination ).html( result );

					console.log(result);

				} )

				/* handle error */
				.fail( function(error) {

					alert("Cannot Set Data!");

					console.error(error);

				} );

			}

		</script>

<hr />

process.php

    echo "<pre>";

    var_dump($_POST);

    echo "</pre>";

<hr />

Demo <a href="https://repl.it" >repl.it</a>

<ul>
  <li><a href="https://repl.it/@antelove19/jQuery-form-formData-50" >Editor</a></li>
  <li><a href="https://jquery-form-formdata-50.antelove19.repl.co/" >Live</a></li>
</ul>

<hr/>

<center>Thank for reading :)</center>

<hr/>
A job ad that helps bring in a diverse talent to developer relations field
Tags: discuss, devrel, beginners, career
Published: 2019-12-16 10:59:26

I am typical "white male after 30" kind of person, who does lots of public speaking, conferences, events, teaching, coaching and alike. I've been in developer relations for 11+ years and it is mostly people like me. Talking sort of to people like me... I think it is not right, and we can do better in this industry.

For the last 2-3 years, I've been part of many "women in tech" initiatives and have been vocal about diversity and inclusion in any event I'd organise or even participate.

Now I have a chance to focus more on bringing more women and minorities to developer relations, empowering speakers and raising a new wave of role models. But there's a question I'd like to open up to this community to discuss. A job ad question.

It has been widely discussed how to craft job ads to look appealing to women and minorities. I think King (I've enjoyed 4 years there) is a [true role model](https://king.com/jobs) in this regard. 

####But can we go even further on?
Now I am consulting a company where there'd be a place for two _junior vue.js programmers_ who I'd help to leap to a developer relations role. Sounds like a perfect opportunity to attract more diverse people to devrel, a craft that often requires 5-6 years in a specific programming field. 

But...can we limit the job ad to women and minorities or am I leaping too far off?

Dev community, would you please share your opinions on gender-specific job ads in tech? From one side, there's nothing gender-specific in the junior programmer/devrel role. From the other side, it is a perfect opportunity to bring more diversity to devrel and help bring up diverse public speakers, role models who'd inspire people like them.
Create ODBC connection in SSMS with Devart ODBC Drivers

Tags: ssms, odbc, odbcdriver, software
Published: 2019-12-16 10:18:22

With Devart open database connectivity drivers, you can setup an ODBC connection to a whole range of on-premise and cloud databases and applications, such as PostgreSQL, Sybase ASE, or BigCommerce in SSMS. Eliminate the unnecessary complexity of dealing with data from heterogeneous data storages by configuring an ODBC data source and linking it to your SQL Server instance in SQL Server Management Studio.

Key Features

- Direct mode
- Secure connection
- SQL data type mapping
- ANSI SQL-92 standard support for cloud services

Learn more at [https://www.devart.com/odbc/ssms/](https://www.devart.com/odbc/ssms/)
My Journey (Part 2)
Published: 2019-12-16 09:52:03

Ok so this is like 1998 and the World Wide Web is a very different world. Google is a prototype, no one posted food pictures from there smartphone, in fact, smartphones didn't even exist and we certainly were not ordering everything we could ever need from Amazon. The web simply was more of an information point, referencing material and lots of wording. Some flashing GIFS helped to deliver some interactive points but it really was just a reference more than a way of life like today. So learning HTML at this time seemed daunting! A crazy undertaking that at the age of 16 kept me up into the night and trying to keep myself busy. I remember my Dad actually asking why I was wasting my time, it would never amount to anything. 

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/k5qhd5a8z4w24b5dwkos.jpg)

One of the main loves from this time was plugging in internet cable into the phone line and my browser and settings coming on the 'Freeserve disk'. Writing simply hello worlds and journalling my computer build was a seriously fun activity, of course, we still had time for fun and kicking back to some Championship Manager 97/98, still one of the best football sims around. This went on for a while and 1p per minute internet with Freeserve helped my cause when I was trying to get online! But then sometime in 2000, we moved house and AOL was now a thing with ADSL! For the first time, I could have the Internet on and the phone would keep working which meant I would no longer hear my Dad yell 'Get off that god darn Internet'! But this also bought with it 256kbs! Yep, no more 56k dial intones, no more watching a page load and man I remember this day! Watching the Foo Fighters Live on AOL! Remember we had no Youtube! All videos were sent via articles and now live-streamed by your web start page!

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/uiwjmtxgo5co977vcwi3.jpg)

This era was amazing and technology moved so fast and had so much to offer. 3D graphics improved, web delivery started to be more complex and most of all I gave up on being a developer! I went into print and had my career set out printing magazines and books! I listened to those around me who said this would never take off and there are no jobs in this industry. I listened and went off to train to run Print Machines and start my career on World of Warcraft! But I think that story is another post at another time and maybe another realm. Man, that game took some chunks of my life. So until 2010, I built hardware to further my quest in Azeroth and gave the development the good old kick in the back.

But I reached 29 years old and felt a longing, to do something I always dreamed of doing and to achieve more than the dying printing world had to offer. So I jumped online, hit a company called Computeach and started a CIW in web development...
[ 🇬🇧 ] Move from an IBM Cloud account to another 
Tags: cloud, migration, devops, ibmcloud
Published: 2019-12-16 09:43:41

A few weeks ago, we had to move from an IBMCloud account to another , the cause was some enterprise constraints , you know the movie 🤷‍♂‍ .

As IBMCloud doesn’t provide tools out of the box for it, our migration was based on our daily CI/CD pipeline! Wow 🤦‍♂‍

Now, let's see what we need to move to the new Cloud:

➡️ 30 CloudFoundry
➡️ 10 PostgreSql
➡️ 2 MongoDB
➡️ 3 AppID (OPIDC)
➡️ 4 domain names

Okey 49 assets to move, seems good.

Now we have seen the most asset we have, the idea is to use CI/CD pipelines for *most* of our deployments.
 
So, what's about our application’s pipeline:

- ✅ Some applications are deployed with GitlabCI pipeline => should be OK
- ❌ Some applications are deployed with IBMCloud Devops pipeline => which is not cloud agnostic 
- ❌ No Infrastructure as code for BDD, AppId ...etc. => Hmm manually provisioning ?  
- ✅ Data migration? all our assets have an API for import/export => it's should be OK. 

We have some bad and good thinks, moving all that stuff with a minimal down want be the best way , so without too much thinking 

💡 Blue Green deployment is the best way 
*More about blue green deployment from Martin Fowler  [here](https://martinfowler.com/bliki/BlueGreenDeployment.html)* 

![Dak'aa](https://media.giphy.com/media/d3mlE7uhX8KFgEmY/giphy.gif)

The Gif below describe in visual way how we proceed: 

![migrationgif](https://thepracticaldev.s3.amazonaws.com/i/bwr1poqwae3xayog2xbn.gif)

The process can be splitted to 6 steps describes as below: 

**Step 1** - unifying our deployment Pipeline by moving all our CI/CD pipeline to GitlabCI. 

**Step 2** - Move all non-production assets . As we are working in an agile mode we move the dev environment first then, when needed, staging , sandbox

**Step 3** - Move the production assets, then data migration, then push the provisional production URL to the Business analyst / Product Owner for a Go/No GO 

**Step 4** - Once we have the GO -> Migrate the domain name from the legacy cloud to the New IBMCloud 

**Step 5** - Remove the death pipeline code , and remove the old assets from legacy Cloud 

**Step 6** Celebrate with the Team. 🎊 🎉🎊 🎉

So, without going too deep into details of every step , this how we do the work . 

---
In the end, it's been not easy, and having a devops culture helps a lot and i can resume what we have learn : 

1- **we have to be cloud agnostic:** 
 A toolchain must be a cloud agnostic. If we want a change our 
  deployment strategy, it must me smooth.

2 - **Devops culture is a must**
The pipeline source must be versioned, involved with the code source. **The dev Team is the owner of the pipeline**

3 - **Start Easy** 
  Dev environment first, as we work on agile , the other environments will be **deployed in an iterative and incremental way**

4 - **If it’s hard manually, then script it .**
  Special attention to the Data migration for every type of asset. ( AppId , SQL , NoSql , Cloud object Storage …etc ) 

That's all folks, and how will you do in the same situation ?
Service Class by PORO
Tags: rails
Published: 2019-11-07 10:20:10

---
title: Service Class by PORO
tags: rails
published: true
---

## 👍 Idea
Don't make it just a process
Think about encapsalation

- Naming
  - Verb + Noun
- Design
  - Decide only one method as kick point
    - ex: .run, .call, ..etc
  - One Class One Responsibility
  - Wite main process into instance method
    - because
      - thread-safe
      - easier handling than class method
  - comment should be converted to private method

## 👍 Recipe

```ruby
class CreateDownloadFileService
  include Rails.application.routes.url_helpers
  
  def self.call(hoge:, fuga:)
    new(hoge: hoge, fuga: fuga).call
  end

  def initialize(hoge:, fuga:)
    @hoge = hoge
    @fuga = fuga
  end

  def call
    # do something
  end

  private
  attr_reader :hoge, :fuga, :type, :user_agent
end

class MeetingController < ApplicationController
  def file_download
    file = CreateDownloadFileService.call(hoge: session[:hoge], fuga: request.user_agent)
  end
end
```

## 🔗 Parent Note
{% link n350071/my-rails-note-47cj %}