teleren/devto huggingface dataset:
Data Transfer Object (DTO) in Laravel with PHP7.4 typed properties
Tags: laravel, php, php74, typedproperties
Published: 2020-01-22 07:57:25

---
title: Data Transfer Object (DTO) in Laravel with PHP7.4 typed properties
published: true
description: Data Transfer Objects help in "structuring" data coming from different types of requests and passing it down to various parts of application
tags: laravel, php, php7.4, typed-properties
---

##Pre-requisite
Before reading this article, please read [Working with Data](https://stitcher.io/blog/laravel-beyond-crud-02-working-with-data) chapter of [Laravel Beyond CRUD](https://stitcher.io/blog/laravel-beyond-crud) series by [Brent](https://twitter.com/brendt_gd).


##Introduction

Data Transfer Objects help in "structuring" the data coming from different types of requests ( Http request, Webhook request etc. ) into single form which we can use in various parts of our application. With DTOs, we have confidence that we will not get unexpected data in our application logic.

##Example

```php

class CheckoutData extends DataTransferObject
{

   public int $checkout_id;
   
   public Carbon $completed_at;


   public static function fromRequest(Request $request){ ... }

   public static function fromWebhook(array $params)

   {

      return new self([
        'checkout_id' => $params['id'],
        'completed_at' => $params['completed_at']
      ]);

   }

}


```
`NOTE: Above code is valid only for PHP 7.4`

We can then use this data object in other classes which are responsible for storing this information into database.

###Credits

Before PHP7.4, we had to use a [package](https://github.com/spatie/data-transfer-object) by awesome [spatie](https://spatie.be/open-source). You can read its documentation about how it works with mentioning "types" in doc blocks.

🙌🏼**All the logic that I am using is taken from this package.**


##How do we construct a DTO?

First thought would be to use `__construct` method and pass parameters for each property on DTO class. But this would get out of hand pretty quickly once we start adding more parameters.

`static constructors` to the rescue 🚑

As you can see in above example of `CheckoutData`, `fromWebhook` method returns a new instance of this class by passing an array and letting it construct itself.

In order to see what is really going on, let's have a look at the `DataTransferObject` base class.

```php

abstract class DataTransferObject
{

    public function __construct(array $parameters = [])
    {
        $class = new ReflectionClass(static::class);

        foreach ($class->getProperties(ReflectionProperty::IS_PUBLIC) as $reflectionProperty){
            $property = $reflectionProperty->getName();
            $this->{$property} = $parameters[$property];
        }
    }

}

```
By leveraging PHP's `Reflection API`, we are getting every public property on `CheckoutData` class and initializing it with value passed in parameters array.

This is how we can easily construct our Data Transfer Objects with PHP7.4.
CVE-2019-9854 libre office vulnerability 
Tags: security, vulnerability
Published: 2020-01-22 07:40:16

http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-9854

*LibreOffice has a feature where documents can specify that pre-installed macros can be executed on various script events such as mouse-over, document-open etc. Access is intended to be restricted to scripts under the share/Scripts/python, user/Scripts/python sub-directories of the LibreOffice install. Protection was added, to address CVE-2019-9852, to avoid a directory traversal attack where scripts in arbitrary locations on the file system could be executed by employing a URL encoding attack to defeat the path verification step. However this protection could be bypassed by taking advantage of a flaw in how LibreOffice assembled the final script URL location directly from components of the passed in path as opposed to solely from the sanitized output of the path verification step.*

protect your x/ubuntu desktop by running ASAP 
```
# aptitude safe-upgrade 
```
do your bug reports get ignored ? for years ?
Tags: devops, sysadmin
Published: 2020-01-22 07:32:50

for years and years and years UBUNTU have been ignoring (/dismissing) my bug report about logging into the gui as root ! 

YES I KNOW I SHOULD NEVER LOGIN AS ROOT ! but i am oldschool and i like logging in as root occasionally 

i also like to think "I KNOW WHAT I AM DOING" and i have even set my root console background to RED to remind me not to do `rm -rf`

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/6hy56rc6t5htr6b6whs9.png)
Is it practical to use blockchain to track resource distribution? #discussion
Tags: iot, blockchain
Published: 2020-01-22 07:23:08

<a href="https://www.buymeacoffee.com/peacefullatom" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" style="height: 51px !important;width: 217px !important;" ></a>

Is it practical to use blockchain to track resource distribution?
For example. The city provides the water to different consumers and tracks how much water was consumed by each consumer via IoT using the blockchain.
I'm exploring a new area of knowledge and have lots of dumb questions.
I know that the IT and financial worlds are leveraging the blockchain technology to their benefits.
But what about other areas of human activities?
It would be great to know your opinion.
is JS killing the web ?
Tags: javascript, performance, html
Published: 2020-01-22 07:19:39

why does simulateously opening 20 browser (chromium or firefox) tabs (that's not a lot is it ?) use 100% CPU and take over 1 minute ?

on a CORE i7 with 8G RAM !

if it isnt JS killing my PC ! what is ?

```
Gmail by Google 	
 
Temporary error ()	

We’re sorry, but your Gmail account is temporarily unavailable. We apologise for the inconvenience and suggest trying again in a few minutes. You can view the G Suite Status Dashboard for the current status of the service.

If the issue persists, please visit the Gmail Help Centre »

Try again Sign out

Show Detailed Technical Info
```
Reading Snippets [38 => CSS]
Tags: beginners, codenewbie, html, css
Published: 2020-01-22 07:16:27

An element that uses <code>Position:sticky;</code> is positioned based on the user's scroll position. 

A sticky element toggles between relative and fixed, depending on the scroll position. 

It maintains the position until a given offset point is met in the viewport. After the offset position is met, the element sticks in place.

<kbd><small>Source:<a href="https://www.w3schools.com/howto/howto_css_sticky_element.asp">W3 Schools</a></small></kbd>
Nullish Coalescing in JavaScript
Tags: webdev, javascript, codenewbie, refactorit
Published: 2020-01-22 07:15:03

---
title: "Nullish Coalescing in JavaScript"
date: "2020-01-22T07:15:03.284Z"
canonical_url: "https://ryanlanciaux.com/blog/2020/01/22/nullish-coalescing-in-javascript/"
published: true
tags: webdev, javascript, codenewbie, refactorit
---

{% youtube CJWFr6VJ_A4 %}

Nullish Coalescing is a language feature of JavaScript that was recently promoted to Stage 4 by TC39, the group that maintains the definition of JavaScript. This means that this language feature is valid JavaScript as of ES2020.

With any language feature, it's good to understand how it helps us. Nullish Coalescing helps us eliminate a certain class of code that primarily consists of checking if something is null or undefined.

[Lets take an example where we want to display a Star Wars character's first and last name](https://codepen.io/ryanlanciaux/pen/YzPdbLv?editors=0010). When the last name is undefined, we should show "Not Specified", but if the last name is "" we should treat it like the character doesn't have a last name. (noting that if this was not example code we would probably want to implement different logic for this)

For instance, if we had the following character definitions:

```
const hanSolo = {
  first: 'Han',
  last: "Solo"
};

const chewbacca = {
  first: "Chewbacca",
  last: ""
}

const rey = {
  first: "Rey",
  lastName: undefined
}
```

Lets assume that we had a function, `displayName` that was responsible for obtaining the character's full name for display.

We may be tempted to reach for a logical OR operator like follows.

```
function displayName(character) {
  const lastName = character.last || "Not specified"

  log(character.first, lastName)
}
```

This would work well for `hanSolo` and `rey` but would fall short for Chewbacca, since we're specifying that his last name is "" (meaning he has no last name for our simple example). The `""` is evaluated as falsy, so the logical OR operator would evaluate to "Not specified" in this case. This fails to meet our requirements because a lastname of "" should not cause the `displayName` function to append "Not specified"

Without the null coalescing operator, we'd generally have to check for lastName being null or undefined since an empty string is evaluated as falsy.

If we change our function to the following, everything works as expected, however, it's a bit more code.

```
function displayName(character) {
 const lastName = character.last === null || character.last === undefined
  ? 'Not Specified'
  : character.last;

  log(character.first, lastName)
}
```

Using the nullish coalescing operator is a lot more focused:

```
function displayName(character) {
  const lastName = character.last ?? "Not specified"

  log(character.first, lastName)
}
```

This is very similar to the function using the logical OR "||" except we're using two question marks instead "??" [View the example for this article here](https://codepen.io/ryanlanciaux/pen/YzPdbLv?editors=0010).

Please [find me on Twitter at @ryanlanciaux](https://twitter.com/ryanlanciaux)
devto followback buttons feature request
Tags: devto, featurerequest, smn, bmn
Published: 2020-01-22 07:08:12

as a devto user id like to be able to follow you back from my followers page if you have followed me with me noticing https://github.com/thepracticaldev/dev.to/issues/5640

feel free to upvote the issue if you agree

will add a DIY fix to my todo list anyway

{% link https://dev.to/osde8info/my-next-open-source-startup-ideas-1hb5 %}
Disabling Prod Mode in already Built Angular App in Chrome
Tags: angular, chrome, javascript, beginners
Published: 2020-01-22 06:07:58

In this small post i am talking about chromes "Override" tab.

Maybe this is well known and widely used  but I just found out about it today and wanted to push it for beginners or people which are not using this cool feature of the Chrome DevTools for debugging.


Since chrome version 65 - any yeah I know that this version has been released back in the beginning of 2018 -  there is a tab called "Overrides" within its DevTools Sources section which can be used to replace files which are normaly requested from the server belonging to the frontend with local files. 

For this to work you just need to open your DevTools and go to Sources, from there you click on "Overrides" and select a folder for overrides.

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

After that you can go back to sources and right mouse click on a file to save it for overrides.
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/ur6c3v3skqk0mkq57m01.png)

Chrome will then create a folder within your selected override folder named like the page you saved the file from containing all files you saving for this domain. 

From here on you can make changes using the DevTools itself or any editor you'd like to use.

I.e we can take any main Js file generated after angulars build process and search for "enableProdMod" to in the end remove that line of code and get "ng.probe" again even after reloads.
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/qofljn9h82pxilu58i03.png)

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

happy debugging.
the comments from the 👩‍💻DEV CMTY👨‍💻 in this svg list post are so cool they deserve a post of their own
Tags: svg, graphics, nocode
Published: 2020-01-22 06:55:14

the comments (ie SVG demo/example links) from the 👩‍💻DEV CMTY👨‍💻 in this svg list post are so cool they deserve a post of their own

{% link https://dev.to/liana/what-are-the-most-interesting-uses-of-svgs-youve-seen--3jek %}

BTW do SVGs fit into #nocode category ?
Finding a Remote Job as a Software Developer
Tags: remote, job, jobsearch, remotework
Published: 2020-01-22 06:27:34

---
title: Finding a Remote Job as a Software Developer
published: true
description: 
tags: remote, job, jobsearch, remotework
canonical_url: https://www.youtube.com/watch?v=PIWAMCluL9M
---

Finding a local job is not too difficult... ... but finding a remote job is way harder

I have actually found several remote jobs in the past, and here are a few tips:

* Specialize in a niche - a generalist will really struggle to stand out...
* Prefer Frontend to Backend & Devops, as employers are reluctant to give the custody of customer data to someone who live far away
* If you are too junior, it will be hard, so try to get some "easy" remote working experience by freelancing

{% youtube PIWAMCluL9M %}
WordPress in React Native: Integration using the Rest API
Tags: wordpress, react, reactnative, javascript
Published: 2020-01-22 06:25:02

WordPress data can be put into React Native by using the WordPress Rest API with JSON objects. It's simple to set up and can allow you to display the latest news, blogs, categories or even custom post types.

This video will get you up and running, show you how data can be pulled into React Native, and displaying it. It will also cover some important aspects like storing data with AsyncStorage and using MobX to hold the data in a store.

* Installing Axios
* Pulling data from WordPress
* Saving it to a store in MobX and AsyncStorage
* Displaying it in the mobile application

{% youtube bkyRHZfp3GI%}
whats the best time to post to devto ?
Tags: discuss, smn, bmn, blogging
Published: 2020-01-22 06:21:18

https://pin.it/e6vx3luynqi62s

https://i.pinimg.com/236x/2d/a6/c3/2da6c398645c47ed5739c370c5e2c30f.jpg

and what should you post about

https://pin.it/fj3gezoek3o6he

https://www.pinterest.co.uk/pin/667940188471103688/sent/

btw is there a md tag for pinterest
goormIDE - A Powerful Cloud IDE Service
Published: 2020-01-22 05:38:03

https://ide.goorm.io/

DEVELOP WITH EXCELLENCE

goormIDE is a powerful cloud IDE service to maximize the productivity for developers and teams.


EASY CONFIGURATION

One-click Workspace Environment
Don’t waste your time with complex configuration steps.
You can easily setup your own development environment.

Quick Launch Available
You can launch and check your applications right away on your own virtual container with specific URL.


COLLABORATION

Live Pair Programming
goormIDE provides the real-time collaborative edit feature. You can edit same source code on the same virtual machine with your teammates, and share project's changes in real-time.

Built-in Messenger
you can communicate and focus on collaboration via built-in messenger,
without having to switch to a separate one.


LANGUAGES

goormIDE supports almost every programming languages and platforms.
Be empowered with a wide range of development capabilities.


ENTERPRISE

For your own data center or cloud

Complete control of infrastructure and data
Active-active clustering for high availability
Annual term + license maintenance
Technical support


Create your account and get 5 free workspaces
Set up your own development environment without any complex configuration.

https://ide.goorm.io/
A JS coder's view on Blazor
Tags: csharp, webassembly, blazor
Published: 2020-01-22 05:31:39

There's certainly a hype around every new technology which promises a lot to the target users. Blazor is one of them. For C# devs who are too lazy to learn JavaScript, Blazor is certainly a saviour. 

After going through the installation and setting up my first Blazor app, I certainly have a few thoughts about Blazor.

# My thoughts on Blazor
1. Blazor may be fast when fully loaded in the browser, but by default, it takes time to load. Comparing this to the fast load times of apps built with React or Gatsby, it is certain that Blazor goes against the "fast load times" philosophy.

2. Blazor uses C#. This means for web developers who want to learn C# for whatever reason, Blazor serves as a platform for them to use the language. (I'm one of them).

3. The fact that C# is used means you don't have to face the downsides of the flexibility of JavaScript. You get to use a robust language.

4. No need for node_modules 😊. Truthfully, I hate the fact that for any modern JavaScript app, you need to download a whole directory of node modules which is usually > 60 MB. 
This may not be a problem in environments with cheap WiFi and low latency, but it's a serious pain in environments with expensive data and slow internet. Some of us end up copying old projects, cleaning them up and adding new files.

So, by far, I'm glad I jumped into Blazor at the early stages of its development and acceptance. I believe the framework will keep getting developed. I also love the bonus it offers. I get to learn C#. I can finally develop games using Unity and not feel totally lost.

If you believe you'll blend well with Blazor, I'd say you give it a try. It won't hurt much. And you get to learn C# if you don't already know C#. To get started with Blazor, check out [the docs](https://docs.microsoft.com/en-us/aspnet/core/blazor/?view=aspnetcore-3.1).
Day34:Common Path Operations - 100DayOfRust
Tags: rust
Published: 2020-01-22 04:09:55

### Common Path Operations:

```rust
use std::path::Path;

fn main() {
    let currdir = Path::new("./");

    // canonicalize return absolute path
    let absdir = currdir.canonicalize().unwrap();
    println!("Absolute path: {}", absdir.to_str().unwrap());

    // parent return parent path
    let pdir = absdir.parent().unwrap();
    println!("Parent path: {}", pdir.to_str().unwrap());

    // join to join sub path
    let toml = currdir.join("Cargo.toml");
    println!("Cargo.toml path: {:?}", toml);

    // is_file return if it is regular file; 
    // is_dir return if it is directory
    println!("Cargo.toml is file: {}", toml.is_file());

    // extension return file's extension
    println!("Cargo.toml extension: {:?}", toml.extension().unwrap());

    // is_relative return if path is relative path
    // is_absolute return if path is absolut path
    println!("Cargo.toml path is relative: {:?}", toml.is_relative());

    // starts_with return if path starts with xxx
    println!("Cargo.toml start with /home: {:?}", toml.starts_with("/home"));

    // strip_prefix remove path's prefix
    println!("Cargo.toml strip prefix: {:?}", toml.strip_prefix("./").unwrap());
}

```

Run:

```
Absolute path: /home/bo/project/rust/pathtest
Parent path: /home/bo/project/rust
Cargo.toml path: "./Cargo.toml"
Cargo.toml is file: true
Cargo.toml extension: "toml"
Cargo.toml path is relative: true
Cargo.toml start with /home: false
Cargo.toml strip prefix: "Cargo.toml"
```

### Reference
* https://doc.rust-lang.org/std/path/struct.Path.html
How to Define Global Variable in Angular 8?
Tags: angular, angular8
Published: 2020-01-22 04:08:29


Today, i will show you how to create global variable in angular 8. we can define global variable in angular 8 application. i will give you simple example of global variables in angular 8.

We always need to declare global variable file for our angular 8 application because we can set some global variable there like site title, api url etc so you can easily access any where in our application easily.

So, in this example, we will create GlobalConstants file for adding global variables in our application. in that file i added two variables as apiURL and siteTitle. I will access those variable value in my AppComponent file. you can also access all the component as you want.

Now, bellow we will create GlobalConstants as like created bellow and We will use that variables as like used in AppComponent file.

Link: https://www.itsolutionstuff.com/post/how-to-declare-global-variable-in-angular-8example.html
React Electron Boilerplate
Tags: react, electron, parcel, boilerplate
Published: 2020-01-22 03:41:27

This boilerplate is for desktop application development using web frameworks and libraries including React, Electron, Parcel. The boilerplate provides quality control with Jest, Enzyme for testing, and ESLint for linting.

### How to use the boilerplate

#### Setup new project

1. Clone the project

   ```bash
   git clone https://github.com/intocode-io/react-electron-boilerplate.git
   ```

2. Change directory name and the following properties in package.json to your new project.

   ```json
   {
     "name": "your-new-project",
     "version": "1.0.0",
     "description": "What about the project",
     "repository": {
       "type": "git",
       "url": "git+https://github.com/your-username/your-project.git"
     },
     "keywords": ["electron", "react", "what about"],
     "author": "Name Surname",
     "license": "MIT",
     "bugs": {
       "url": "https://github.com/your-username/your-project/issues"
     },
     "homepage": "https://your-home-page"
   }
   ```

   Note: **DO NOT** delete the rest of properties in the package.json.

3. Install dependencies

   ```bash
   npm i
   ```

#### Start development

```bash
npm run dev
```

#### Build production

```bash
npm run build
```
Flutter Web: Sentry
Tags: flutter, flutterweb, sentry, webdev
Published: 2020-01-22 03:34:29

{% youtube rteGnESc-p4 %}

When you have a production ready application, how are you going to catch those pesky bugs? 

Even if your users has a specific use case, it takes a lot of work to figure which exact code is giving the bug. 

No worries, [Sentry](https://sentry.io/) is here. It is a platform that helps you show the errors that you might not have thought of in your production app.

Now that Flutter Web is in beta, we gotta catch those pesky bugs when we release our Flutter Web apps out there (maybe using [Firebase hosting]()). Flutter has release some packages that can be used in the Flutter Web, and one of it is [Sentry](https://pub.dev/packages/sentry).

Once you have sign up with an account, create a project under others. 

![Screenshot of Creation of Project Other in Sentry](https://user-images.githubusercontent.com/31005114/72862763-42075c00-3d09-11ea-91e9-e36f72efc741.png)

_Sadly, Flutter is not one of the platforms._

Then go to your settings, and get your DSN keys. 

![DSN Keys](https://user-images.githubusercontent.com/31005114/72863229-cc03f480-3d0a-11ea-9654-c65b4e30725b.png)

"A DSN, or Data Source Name. It looks a lot like a standard URL, but it’s actually just a representation of the configuration required by the Sentry SDKs. It consists of a few pieces, including the protocol, public key, the server address, and the project identifier." Source: [Sentry](https://docs.sentry.io/error-reporting/quickstart/?platform=javascript#configure-the-dsn)

Then, we have to install the Sentry dependencies in our Flutter Web app.

```yaml
// In pubspec.yaml

dependencies:
  sentry: <latest version>

```

Next, we have to initialise our sentry client with our DSN (that we got earlier) in our app and send our first error! 

```dart
// In main.dart

import 'package:sentry/sentry.dart';

final SentryClient sentry = new SentryClient(dsn: YOUR_DSN);

main() async {
  try {
    throw new StateError('This is a Dart exception.');
  } catch(error, stackTrace) {
    await sentry.captureException(
      exception: error,
      stackTrace: stackTrace,
    );
  }
}
```

It will be reflected in your Sentry board as such:

![First Issue in Sentry](https://user-images.githubusercontent.com/31005114/72862722-23a16080-3d09-11ea-87e0-f66ad8afc269.png)


**What if we want to catch any uncaught error?**

Good question. You will have to use runZoned to catch all errors by flutter. 

{% github https://github.com/flutter/flutter/issues/49199 %}

Sadly, there is an error (currently) in the web client side of the Flutter's Sentry package. Thus, you have to catch your errors manually using the above code.