teleren/devto huggingface dataset:
Day15:Load and Dump JSON - 100DayOfRust
Tags: rust
Published: 2019-12-01 18:01:19

We will use `serde` and `serde_json` crate to parse string to object and dump object to json string.

This code contains:
* Read json string from file and parse string to object
* Use `json!` macro to create Value object and use `.to_string()` function to dump object to string
* Use `Serialize` and `Deserialize` trait for self-defined struct so we can dump it to string
* Use `serde_json::to_string` and `serde_json::to_string_pretty` to dump object to string

First let's create a `config.json` file for test reading, put it in the same level as the `Cargo.toml`, like this:

proj
|-- Cargo.toml
|-- config.json
|-- src

In `config.json`, put some sample json string:
```json
{
    "debug": true,
    "name": "serdetest"
}
```

And in `Cargo.toml` file:
```
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.42"
```

Make sure `features = ["derive"]` exists <sup>[1]</sup>, otherwise later in our code, `#[derive(Serialize)]` won't work.

Code in `main.rs`:
```rust
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};

use std::fs;

#[derive(Serialize, Deserialize)]
struct Person {
    name: String,
    score: i32,
}


fn main() {
    // parse config file
    let path = concat!(env!("CARGO_MANIFEST_DIR"), "/config.json");
    let s = fs::read_to_string(path).unwrap();
    let cfg: Value = serde_json::from_str(&s).unwrap();
    println!("Config: debug {}", cfg["debug"]);

    // json! macro
    let bonus = 10;
    let result = json!({
        "name": "Bo",
        "score": 92 + bonus,
    });
    println!("JSON!: {}", result.to_string());
    println!("JSON! Pretty: {}", serde_json::to_string_pretty(&result).unwrap());

    // serde_json to_string and to_string_pertty
    let p = Person {name: "Bo".to_owned(), score: 92};
    let serialized = serde_json::to_string(&p).unwrap();
    println!("Person serialized: {}", serialized);

    let serialized_pretty = serde_json::to_string_pretty(&p).unwrap();
    println!("Person serialized pretty: {}", serialized_pretty);

}
```

Result:
```
Config: debug true
JSON!: {"name":"Bo","score":102}
JSON! Pretty: {
  "name": "Bo",
  "score": 102
}
Person serialized: {"name":"Bo","score":92}
Person serialized pretty: {
  "name": "Bo",
  "score": 92
}
```


### Reference
[1] https://serde.rs/derive.html
The Perils of Java's Object.clone() method
Tags: java, codequality
Published: 2019-12-01 17:56:17

As a Java programmer, it is sometimes noticed early on that Object.clone() exists, so you start relying on it to copy objects. It isn't an ideal solution to this problem, though: it is fragile, relying on both overriding Object.clone() AND implementing Cloneable; it can fail in weird ways, usually in the form of CloneNotSupportedExceptions being thrown; and finally, it is very easy to implement incorrectly - to copy an object properly, you need to call clone() on the superclass and cast it first. If not, things will break.

In my own code, I am generally only trying to copy objects I control, which means I give my objects copy constructors for this purpose. Creating one is simple enough, is a lot safer than cloning, and can be illustrated with a small example:


```
public class MyObject {
    // Fields
    private int counter;
    private boolean counterUsed;
    private final String name;
    private String description;

    // Constructor
    public MyObject() {
        this.counter = 0;
        this.counterUsed = false;
        this.name = "No name";
        this.description = "Please describe me!";
    }

    // Copy constructor
    public MyObject(final MyObject other) {
        this.counter = other.counter;
        this.counterUsed = other.counterUsed;
        this.name = other.name;
        this.description = other.description;
    }
    // ... rest of class goes here ...
}
```

If I need a copy of a MyObject instance, I can explicitly request one with the copy constructor, then change anything I need changed. Most importantly, copy constructors can't fail in the same ways cloning can, and the C++ way to make them happens to also be the recommended way in Java - if you're familiar with C++, this will not take long to learn!
Why arduino is the perfect mixture of electronics and programming 
Tags: opensource
Published: 2019-12-01 17:46:57

Arduino has become a very popular, useful code and tool to make awsome electronic projects.
The opensource plataforme is totaly free and you can learn amazing things about LEDs, servos and more electronic gadgets. This mixure of electronics and programming  give us the opportunity of develop awsome automatisims and wonderful projects.
Managing your time as a junior software developer who wants to make a progress. 
Tags: discuss, help, career
Published: 2019-12-01 17:32:08

---
title: Managing your time as a junior software developer who wants to make a progress. 
published: true
description: 
tags: discuss, help, career 
---

Lately I have been struggling to make a good balance between my coding gools and my work as a software developer freelancer, so I have started to question my self? What am I doing wrong? 
Is it a bad time management, gools are not realistic? Lack of motivation? 
I can't find an answer till now...

Another factor is that I have to use number of technologies because the team am working with are using it, it's good for me to find this environment, and I have been learning a lot by coding projects with team, however sometimes I feel like am not doing enough, or am not able to be as good as them, I know they have much more experience than I do have but the feeling I get can not be ignored. 
At the same time I want to learn the newest technologies, am taking two course to do so. 

Sometimes I feel like am distracting my self instead of focusing on a couple of things at a time. 

Now I have completed one year as a software developer. But I need some advice on how to balance between my personal coding gools and my work.
A new admin template project for Vue.js with Inkline
Tags: vue, css, template
Published: 2019-12-01 17:02:08

Hi. I started a new admin template project for Vue.js.

Repo url: [https://github.com/aligoren/carbon-panel](https://github.com/aligoren/carbon-panel)

My project uses [Inkline](https://inkline.io).

You can see a demo from [here](https://aligoren.github.io/carbon-panel/index.html).

Currently, I've completed the theme section. So, I'm looking for open source contributors :)

Thanks!
Switching between PHP versions with Homebrew
Tags: php, homebrew
Published: 2019-12-01 16:21:44

---
title: Switching between PHP versions with Homebrew
published: true
description: 
tags: [php, homebrew]
canonical_url: https://daveismyname.blog/switching-between-php-versions-with-homebrew
cover_image: https://thepracticaldev.s3.amazonaws.com/i/16bkxpkqyzxnprrh2y9l.png

---

With Homebrew it's possible to have multiple versions of PHP installed at once, to switch which version is active unlink the current version and link the desired version. 

Switch from 7.4 to 7.3

```
brew unlink php@7.4 && brew link --force --overwrite php@7.3
```

Switch from 7.3 to 7.4

```
brew unlink php@7.3 && brew link --force --overwrite php@7.4
```

Since you may want to do this frequently it's more convenient to create a function to do this.

Create a function to your bash/zshrc profile

```
switchphp() {
    brew unlink php && brew link --force --overwrite php@$1
}
```

This will unlink PHP and relink to the specified version.

**Usage**:

switch to PHP 7.4 

```
switchphp 7.4
```

switch to PHP 7.3

```
switchphp 7.3
```
Social skills for tech folks (?)
Tags: discuss, career
Published: 2019-12-01 16:16:31

---
title: Social skills for tech folks (?)
published: true
description: 
tags: discuss, career
---

Hi all!

I'm trying to write down something about one of the most terrifying things to deal with for tech folks: **social skills**.

It is known that almost all of the *people that work in IT prefer to interact with a machine rather than a human*.

Am I wrong? What do you think about it?

Tell me a story about that time you struggled with talking/interacting with another human and why.

Which social skill is the most important to you? Why? Is it empathy? Maybe sincerity?

I look forward to hearing your answers!
Upgrade PHP 7.4 with Homebrew
Tags: php, homebrew
Published: 2019-12-01 16:13:28

---
title: Upgrade PHP 7.4 with Homebrew
published: true
description: 
tags: [PHP, Homebrew]
canonical_url: https://daveismyname.blog/upgrade-php-74-with-homebrew
cover_image: https://thepracticaldev.s3.amazonaws.com/i/tpj3anmuvxw0w4106y7d.png
---

PHP 7.4 came out this week, so it's time to upgrade! 

On Mac, Homebrew makes the whole process painless.

First, run an update on Homebrew:

```
brew update
```

You will see any tabs available if you've updated recently then its likely you'll only see:

```
Updated 1 tap (homebrew/core).
==> New Formulae
php@7.3
```

Next upgrade PHP:

```
brew upgrade php
```

This will upgrade PHP to the latest version, which at this moment is PHP 7.4

To verify your PHP version run:

```
php -v
```

Then you should see:

```
PHP 7.4.0 (cli) (built: Nov 29 2019 16:18:44) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.0, Copyright (c), by Zend Technologies
```

That's all there is to it!
Apache Spark Basics
Tags: beginners, productivity, bitesize
Published: 2019-12-01 16:01:58



This is a basic cheat sheet, glossary and the very beginning of getting started with Apache Spark, every time we will share a new post with terms or code snippets, they will appear here as well at a generic form.

If you work with Apache Spark and look for a cheat sheet, this is for you as well!

![](https://media.giphy.com/media/xUOwG5IshvzNMdzR72/giphy.gif)

First thing first:
## -1- the workspace:
First, we need to create the workspace, we are using Databricks workspace and here is a [tutorial](https://docs.microsoft.com/en-us/azure/azure-databricks/quickstart-create-databricks-workspace-portal?WT.mc_id=apachespark-bitesize-adpolak) for creating it.


## -2- Basic Apache Spark Vocabulary :

#### Dataframe 

This is a _distributed_ collection of data organized into named columns that provide operations to filter, group, or compute aggregates. Dataframe data is often distributed across multiple machines. It can be in-memory data or on disk.

#### Dataset
Strongly typed collection of objects that can be transformed in parallel using functional or relational operations. Each Dataset is a typed view of **Dataframe**.
Dataset is defined as "lazy", meaning the computations are only triggered when an action is invoked.

#### RelationalGroupedDataset

A set of methods for aggregations on a `DataFrame`, created by [groupBy](https://medium.com/r/?url=http%3A%2F%2Fmaxpumperla.com%2Fjava-book%2Fapi%2Fscala%2Forg%2Fapache%2Fspark%2Fsql%2FDataset.html%23groupBy%28col1%3AString%2Ccols%3AString*%29%3Aorg.apache.spark.sql.RelationalGroupedDataset), [cube](https://medium.com/r/?url=http%3A%2F%2Fmaxpumperla.com%2Fjava-book%2Fapi%2Fscala%2Forg%2Fapache%2Fspark%2Fsql%2FDataset.html%23cube%28col1%3AString%2Ccols%3AString*%29%3Aorg.apache.spark.sql.RelationalGroupedDataset) or [rollup](https://medium.com/r/?url=http%3A%2F%2Fmaxpumperla.com%2Fjava-book%2Fapi%2Fscala%2Forg%2Fapache%2Fspark%2Fsql%2FDataset.html%23rollup%28col1%3AString%2Ccols%3AString*%29%3Aorg.apache.spark.sql.RelationalGroupedDataset).



>This is an evolving page and more terms, code snippets and architecture design will be added.
Future Growth of Programming languages.
Published: 2019-12-01 16:01:43

Hi! I hope you are all doing good. I'm a student of software Engineering . I'm doing a research that in future which programming languages will be on top. Currently I'm doing front end web development. But I want to learn back end development. In back end which programming languages should I learn that is growing and there will be scop in future. People are saying to me that popularity of react.js and node.js is increasing. Can anybody refer me any link where I can find that which programming languages are going to be popular and which languages are decreasing its community. Thanks
Day14:Call Web API - 100DayOfRust
Tags: rust, webdev
Published: 2019-12-01 15:53:40

In this example, we will call a bitcoin web api with `reqwest` crate to get the json format data, then use `serde_json` crate to parse json to get price.

First, we add those 2 dependencies:

```
[dependencies]
reqwest = "0.9.22"
serde_json = "1.0.42"
```

Then in `main.rs`:

```rust
use serde_json::{Value};
use reqwest;

fn main() {
    let url = "https://blockchain.info/ticker";
    println!("Send request to: {}", url);
    // 1st way, use .json()
    let val: Value = reqwest::get(url).unwrap().json().unwrap();
    println!("Bitcoin price: ${}", val["USD"]["last"]);

    // 2nd way, use .text() then serde_json::from_str
    let text = reqwest::get(url).unwrap().text().unwrap();
    let val2: Value = serde_json::from_str(&text).unwrap();
    println!("Bitcoin price: ${}", val2["USD"]["last"]);
}

```

Run it with `cargo run`:

```
Send request to: https://blockchain.info/ticker
Bitcoin price: $7293.05
Bitcoin price: $7293.05
```
Daily Challenge #129 - Clay Pigeon Shooting
Tags: challenge
Published: 2019-12-01 15:42:16

---
title: Daily Challenge #129 - Clay Pigeon Shooting
published: true
series: Daily Challenge
description: Write a function to score a shooting competition.
tags: challenge
---

Pete and his mate Phil are out in the countryside shooting clay pigeons with a shotgun - amazing fun. Some of the targets have something attached to create lots of smoke when hit, guaranteed by the packaging to generate 'real excitement!' 

They decide to have a competition. 3 rounds, 2 shots each. Winner is the one with the most hits.

For each round you will receive the following format:

`[{P1:'XX', P2:'XO'}, true]`

That is an array containing an object and a boolean. Pl represents Pete, P2 represents Phil. X represents a hit and O represents a miss. If the boolean is true, any hit is worth 2. If it is false, any hit is worth 1.

Find out who won. If it's Pete, return 'Pete Wins!'. If it is Phil, return 'Phil Wins!'. If the scores are equal, return 'Draw!'.

Note that as there are three rounds, the actual input (x) will look something like this:

`[[{P1:'XX', P2:'XO'}, true], [{P1:'OX', P2:'OO'}, false], [{P1:'XX', P2:'OX'}, true]]`

**Test Cases:**
<pre>
shoot([[{P1:'XX', P2:'XO'}, false], [{P1:'OX', P2:'XX'}, false], [{P1:'OO', P2:'XX'}, true]])

shoot([[{P1:'XX', P2:'XO'}, true], [{P1:'OX', P2:'OO'}, false], [{P1:'XX', P2:'OX'}, true]])
</pre>

Good luck!

***
_This [challenge](https://www.codewars.com/kata/57fa9bc99610ce206f000330) comes from A.Partridge on CodeWars. Thank you to [CodeWars](<https://codewars.com/>), who has licensed redistribution of this challenge under the [2-Clause BSD License](<https://opensource.org/licenses/BSD-2-Clause>)!_

_Want to propose a challenge idea for a future post?  Email **yo+challenge@dev.to** with your suggestions!_
Open source at companies
Published: 2019-12-01 15:04:07

---
title: Open source at companies
published: true
description:
tags: opensource
---

Are you actively looking for an awesome opensource project which is maintained by a company like Microsoft, Google, Apple, Facebook, and co and is at the beginning of an engineering phase or just looking for newly published open-source projects by companies to keep up to date with new frameworks, tools, etc?

I'm a software engineer and I had a few months ago a very important problem... I wanted to start watching at the engineering processes of big companies like Facebook while an early stage-phase of an opensource project to learn new things about software engineering but unfortunately, I couldn't find anywhere a platform which is providing me feed for such projects. This was the reason why I created "www.goopensource.dev" to solve this problem and I was totally surprised and amazed by how frequently all kinds of companies publishing new things like this [orm](https://github.com/facebookincubator/ent) every week.

My app has reached alpha status.

I'm would be very glad if you could provide some feedback about this project.

Thank you for your support! :)
Ionic 4 Form Validation Tutorial with Reactive Forms
Tags: ionic4, ionic, ionic4formvalidation, react
Published: 2020-02-01 19:23:20

---
title: Ionic 4 Form Validation Tutorial with Reactive Forms
published: true
date: 2019-12-01 14:31:53 UTC
tags: Ionic 4, Ionic,  Ionic 4 Form Validation, React
canonical_url: https://www.positronx.io/ionic-form-validation-tutorial/
---

The post [Ionic 4 Form Validation Tutorial with Reactive Forms](https://www.positronx.io/ionic-form-validation-tutorial/) appeared first on [positronX.io](https://www.positronx.io).

**In this step by step Ionic 4 Forms validation tutorial, we will learn to create and validate a form with Angular’s Reactive Forms method.**

Setting up forms in an Ionic application is easy, Angular offers Template-driven and Reactive Forms methods to deal with the forms data. Template-driven approach is used for working with simple forms. In contrast, It is used for handling more complex data. Especially when you need to work with nested values.

[Click here to read more](https://www.positronx.io/ionic-form-validation-tutorial/)
@supports (CSS) 
Published: 2019-12-01 14:27:28

{% tag css %} {% tag todayilearned %} {% tag webdesign %} {% tag beginners %}
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/cob2wlcodzi0jhixm4hi.png)

If you are notified when using CSS features that are not supported by your browser, you have a support feature that lets you see if your browser supports this or not.


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



The not Keyword
---------------
Although this feature shows you that the browser supports this feature there is not to show you that the browser does not support the property or supported and this property is not useful from my personal opinion
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/t27kivf27spz33xsnhzj.png)
_____

And, Or 
-------
And
---
Add another property with the first property
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/tfo04xq69jfbs44ltoom.png)


Or
--
Is to activate the property on one without the other

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/04trkhhk6fr2yziwv2dq.png)
What was your "aha moment" for OOP?
Published: 2019-12-01 14:00:43

I remember when I was new to React and I tried Redux. I didn't get it at first as it was overkill for the simple apps I was building. When my React skills improved there came a point I was managing complex enough state that I saw how Redux was useful and I had my "aha moment".

Im traditionally a JavaScript developer but Im learning Object Oriented Programming and PHP. I get the general idea but I've yet to have the "aha moment" where I see what problem I would choose to solve with it if I had other options. 

When was your "aha moment"? I think it would help me to understand why you would put up with the verbosity.
Help With LucidWorks Fusion Search 
Tags: webdev, discuss, javascript
Published: 2019-12-01 13:51:04

Can anyone guide me through the process of how you can integrate a lucidworks Fusion Search in a nodejs or anyother website of my choice? 

Or  any link which can guide me through the entire process as I've read the documentation of lucidworks fusion but i really am confused with how you can integrate with an external web app or maybe any website made using react , or any frondend library .

Thankyou
Simple take-away Angular input toggle using Font Awesome
Tags: angular, fontawesome, inputtag, html
Published: 2019-12-01 13:30:20

---
title: Simple take-away Angular input toggle using Font Awesome
published: true
description: We are going to create a simple reusable input select toggle. This is a simple take away HTML input check using Angular and fontAwesome that can be handy to use in any application
tags: angular, font awesome, inputTag, HTML
cover_image: https://thepracticaldev.s3.amazonaws.com/i/nek9wcpcj2s40ij6ckpo.jpg
---

## What we are going to do:
We are going to create a simple reusable input select toggle. This is a simple take away HTML input check using Angular and fontAwesome that can be handy to use in any application:


## fontawesome icons:
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/qnxodmfa9b48ajndeuwx.png)
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/y21s9ep23960jaek91m3.png)

https://fontawesome.com/icons/square
https://fontawesome.com/icons/check-square


## Demo:
<a href="https://stackblitz.com/edit/angular-simple-input-toggle?embed=1&file=src/app/app.component.ts">stackblitz Angular input toggle</a>


## Setup:
We need to install the next few dependencies under an Angular project.

<sub>setup package.json</sub>
```javascript
...
    "@fortawesome/angular-fontawesome": "^0.3.0",
    "@fortawesome/fontawesome-svg-core": "^1.2.25",
    "@fortawesome/free-solid-svg-icons": "^5.5.0",
...

```

## Module declaration:
We need to import the @fortawesome dependencies in the app.module, and use the constructor to add the faSquare andfaCheckSquare from 'free-solid-svg-icons' to the library.

<sub>setup app.module.ts</sub>
```javascript
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { library } from '@fortawesome/fontawesome-svg-core';
import { faSquare, faCheckSquare } from '@fortawesome/free-solid-svg-icons';


 imports: [
...
    FontAwesomeModule
...
]

export class AppModule {
  constructor() {
    library.add(faSquare, faCheckSquare);
  }
}

```

## Component Implementation:


<sub> Component </sub>
```javascript
import { Component } from '@angular/core';

import { faCoffee } from '@fortawesome/free-solid-svg-icons';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  isActive = true;

  faUser = ['fas', 'square'];
  faUserDefault = ['fas', 'square'];
  faUserCheck = ['fas', 'check-square'];

  toggle(): boolean {
    return this.isActive = !this.isActive;
  }

  onClickBtn(e) {
    this.toggle() ? this.faUserDefault = this.faUser : this.faUserDefault = this.faUserCheck;
  }
}
```

## Template implementation


<sub>Template</sub>
```javascript
<fa-icon
  [icon]="faUserDefault"
  (click)="onClickBtn($event)"
></fa-icon>
```

## GitHub

GitHub code example:
https://github.com/leolanese/simple-input-toggle
FlutterVN newsletter series
Tags: fluttervnnewsletter, flutter, androiddev, iosdev
Published: 2019-12-01 13:30:07

FlutterVN newsletter is a series to show you new information in Flutter development world. It is aggregated by **FlutterVN — Flutter Vietnam Development** team and released every Wednesday.

In addition to [Medium](https://medium.com/fluttervn), we also share these newsletters on [Facebook](https://www.facebook.com/fluttervndev/), [Twitter](https://twitter.com/fluttervn), [Reddit](https://twitter.com/fluttervn), [Youtube](https://www.youtube.com/channel/UCrPorwpQ0ldHyAtgKTRpzyw/), [Github](https://github.com/fluttervn) and [Dev.to](https://dev.to/fluttervn). Let’s follow our social pages to have the latest news. Or you can contact us directly via fluttervndev@gmail.com.

For the completed list of **FlutterVN newsletter**, let's continue reading this article on Medium: https://medium.com/fluttervn/fluttervn-newsletter-series-f50ebd1d89ca
JSONs VS Native : A Discussion
Tags: java, javascript, webdev, discuss
Published: 2019-12-01 13:01:18

Have been using JSONObjects and JSONArrays along with POJOs and ArraysLists and Hashmaps. 

When one can get data from database directly in JSON formats, are Lists and Maps or even POJOs of any use now? 

Talking in context of Web and Mobile Apps where JSON is used predominantly.


Please post your comments.