teleren/devto huggingface dataset:
Monthly review: February
Published: 2020-03-03 21:52:26

---
title: Monthly review: February
published: true
date: 2020-03-03 00:00:00 UTC
tags: 
canonical_url: 
---

## Sponsors

I’m incredibly thankful to the following people for sponsoring my open source work this past month: [@repi](https://github.com/repi), [@oli-obk](https://github.com/oli-obk) and [@yaahc](https://github.com/yaahc).

If you like what I’m doing and want to support my work, please consider sponsoring me on [Patreon](https://www.patreon.com/philhansch) or [via othermeans](https://phansch.net/thanks) :heart:

## What I’ve worked on

February has been quite a non-productive month from the outside. Maybe it’s the winter blues finally catching up to me, but that’s for the next section of thepost.

It indeed doesn’t look like a lot in terms of merged PRs this month. The only merged PR is to the `rustc-guide` where I’ve added an [introductory section](https://github.com/rust-lang/rustc-guide/pull/590/files#diff-334e46ef0ebca8ba3936db3ac8ae0d7dR3) to the _Name Resolution_ chapter.

I’ve been learning about name resolution in rustc because I’ve been looking into making some improvements to a rustc diagnostic that is emitted exactly during name resolution. So that instead of this:

```
12 | let _ = HashNap::new();
   | ^^^^^^^
   | |
   | use of undeclared type or module `HashNap`
```

You will get an additional suggestion of the most likely alternative:

```
12 | let _ = HashNap::new();
   | ^^^^^^^
   | |
   | use of undeclared type or module `HashNap`
   | help: a struct with a similar name exists: `HashMap`
```

This PR has taken most of my time and energy in February. I want to finish it this month and continue with work around name resolution.

## Reflections

I did not get further into embedded development as I ran into issues with my tools, which I was hoping to avoid by jumping into embedded development.

Instead of doing more embedded development, I’ve started looking into `librustc_resolve`. Specifically [a PR to improve some diagnostics](https://github.com/rust-lang/rust/pull/68850) as mentioned above. This PR has apparently triggered some sort of impostor feeling in me. While working on this PR I noticed two things:

1. In the beginning I had absolutely no idea what `librustc_resolve` is about, lowering my confidence in completing this PR
2. My low confidence in completing the PR also produced feelings of guilt when asking otherwise busy contributors for help

In the future I hope this feeling will go away as I dig further into rustc. Until then, I plan to ‘just’ push through these feelings, keeping my main goal in the back of my head: Making diagnostics and lints better for rust users.

## Goals

For this March I have the following goals:

- Finishing up [the mentioned PR](https://github.com/rust-lang/rust/pull/68850)
- Further improving the name resolution chapter of the rustc-guide
- Potentially do more work around `librustc_resolve` diagnostics
Run & Debug Angular app on VS Code
Tags: vscode, angular
Published: 2020-03-02 23:56:34

## Prerequisite

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

## Step 1 launch.json

Create 'chrome task' configuration


````json
{
	"version": "0.2.0",
	"configurations": [
		{
			"name": "Run & debug my app on chrome",
			"type": "chrome",
            "request": "launch",
            "url": "http://localhost:4200/",
			"webRoot": "${workspaceFolder}",
			"preLaunchTask": "start"
		}
	]
}
```

## Step 2 tasks.json
````json
{
    "version": "2.0.0",
    "tasks": [
     {
       "label": "start",
        "type": "npm",
        "script": "start",
        "isBackground": true,
        "presentation": {
          "focus": true,
          "panel": "dedicated"
        },
        "problemMatcher": {
          "owner": "typescript",
          "source": "ts",
          "applyTo": "closedDocuments",
          "fileLocation": [
            "relative",
            "${cwd}"
          ],
          "pattern": "$tsc",
          "background": {
            "activeOnStart": true,
            "beginsPattern": {
              "regexp": "(.*?)"
            },
            "endsPattern": {
              "regexp": "Compiled |Failed to compile."
            }
          }
        }
      }
    ]
  }
```

##Step 3 Run debugger
- press F5

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/05usgbmonmjp18djkcc8.png)


## References
[[VsCode-tasks] https://code.visualstudio.com/docs/editor/tasks#_custom-tasks](https://code.visualstudio.com/docs/editor/tasks#_custom-tasks)
Connecting a Flutter Web Form to Google Cloud Firestore
Tags: webdev, flutter, firebase, googlecloudplatfor
Published: 2020-05-10 12:36:30

---
title: Connecting a Flutter Web Form to Google Cloud Firestore
published: true
date: 2020-03-02 23:49:05 UTC
tags: web-development,flutter,firebase,google-cloud-platfor
canonical_url: https://medium.com/@mat_wright/connecting-a-flutter-web-form-to-google-cloud-firestore-f6bf7aa28f99
---

[![](https://cdn-images-1.medium.com/max/1200/1*wnzJi1SjSv903JLFCF3edA.png)](https://medium.com/@mat_wright/connecting-a-flutter-web-form-to-google-cloud-firestore-f6bf7aa28f99?source=rss-8818e5bb5014------2)

Step by Step Guide

[Continue reading on Medium »](https://medium.com/@mat_wright/connecting-a-flutter-web-form-to-google-cloud-firestore-f6bf7aa28f99?source=rss-8818e5bb5014------2)
Forms and params{}
Tags: rails, ruby, codenewbie
Published: 2020-03-02 23:47:40

Recently I've been working with forms and Active Record a lot. I was struggling with associating an object with another, in a many to many relationship. I thought there was something wrong with my form syntax. Turns out I had a typo in my Model associations. Either way I decided to write a tutorial on how to assign multiple objects to another using <code>collection_check_boxes</code>.

For starter's here are my relationships. My typo was causing lots of issues, so start off by making sure your associations are correct.


```ruby 
class Person

has_many :pet_owners
has_many :pets, through: :pet_owners

end

class PetOwner

belongs_to :pet
belongs_to :owners

end

class Pets

has_many :pet_owners
has_many :persons, through: :pet_owners

end
```

Once your associations are working correctly we can move on to assigning pets to their people. We'll be using a form that allows a Person to be assigned multiple dogs.


We start by building our form in views. 

```ruby
# /app/views/_form.html.erb
<%= form_for @person do |f| %>
   <%= f.label "First Name: " %>
   <%= f.text_field :first_name %>
   <%= f.label "Pets: " %>
   <%= f.collection_check_boxes :dog_ids, Dog.all, :id, :name %>
   <%= f.submit %>
<% end %>


# /app/controllers/persons_controller.rb
def person_params
	params.require(:person).permit(:first_name, dog_ids:[])
end
```

A checkbox collection allows our user to select multiple dogs by checking a box, next to the dogs name. Our form will grab the <code>dog_id</code> assigned to that dog instance and shovel that into our array located at <code>person_params[:dog_ids]</code>. 

Once ActiveRecord see's the collection of dogs objects it will assign those dogs to the person filling out the form. 

This is a super useful method for assigning multiple objects quickly. I will be using it for a project that I'm currently working on. If you have any questions, or suggestions please leave some comments.

Happy coding!
Best .APK tests
Published: 2020-03-02 23:23:12

Hello all! I have a question for mostly the "re purposer" and security or white hat pros out there. Have any of you ran across a good way to test different apks for different breaches? I use a combo of Skit + along with my own knowledge of different types of coding and Malwarebytes. But, malware wants to mark everything as bad, and has missed things I found to be bad, like almost everything from Cheetah Mobile on the PlayStore. Is there a faster and more accurate method you have found?
Observer Pattern
Published: 2020-03-02 22:55:39

Subscribe to object changes

GitHub: https://github.com/FrancescoXX/Design-Patterns-Observer-Javascript
CodePen: https://codepen.io/francescoxx/pen/NWqvPrb


The Observer Design pattern, is a very simple yet powerful pattern.

We can use it when we want, for example, to update a UI when an object of our application changes its state.

So we have:
 - a SUBJECT: the Thing we want to observe
 - a set of OBSERVERS, which are updated when the subjects changes its state

When the subject changes its state, it notifies, to all subscribed observable, that he changed its state, and all the observers added to the subject gets updated,

That is pretty much how it works when someone updates its twitter with a new tweet! all its followers get updated with a notification

___

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



## Problem

When data changes, we want the UI to reflect the new state

___

### Intent
 - Define a one-to-many dependency between objects
 - When one object changes state, all its dependents are notified and updated automatically. 

### Applicability
 - Use : Change one object -> change others
 - No idea how many objects need to be changed
 - Object change notification, with preserving loose coupling
 - One object may notify another without knowing them directly

### Benefits
 - Loose coupling between observers and subjects
 - Supporting a broadcast model

### Drawbacks
  - One change can result in multiple unnecessary notifications
  - Clients don't know the ripple effects

### Conclusion: Observer pattern is great to
 - Preserve loose coupling
 - Observe state in other objects, then notify when state changes

___

Now lets take a look at the Structure of this pattern when we want to implement it

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/4klcdtvjdqstbrurh1gv.png)


And lets take a look at the Collaboration among them

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


That’s it!
This pattern is very simple and it could be useful when we want to observe the same thing from different points of our application!


GitHub: https://github.com/FrancescoXX/Design-Patterns-Observer-Javascript
CodePen: https://codepen.io/francescoxx/pen/NWqvPrb
Go language constants
Tags: go, beginners
Published: 2020-03-02 22:42:36


In <a href="https://golang.org/">Go programming</a>, a constant is a simple constant value of the identifier, the program runs, the amount can not be modified.

Data type constant may be only boolean, numeric (integer, floating point and complex) and <a href="https://golangr.com/strings/">string</a>.

Constant definition format:

```go
    const identifier [type] = value
```

It can omit the type specifier [type], because the compiler can infer the type based on the value of the variable.

* Explicit typing: `const b string = "abc"`

* Implicit type definition: `const b = "abc"`

More of the same type of statement can be abbreviated as:

    
```go
    const c_name1, c_name2 = value1, value2
```

The following examples demonstrate the application of constants:

```go
package main

import "fmt"

func main () {
   const LENGTH int = 10
   const WIDTH int = 5
   var area int
   const a, b, c = 1, false, "str" // multiple assignment
   area = LENGTH * WIDTH
   fmt.Printf( "area:% d", area)
   println()
   println(a, b, c)
}
```    

Examples of the above operating results are:

```
area: 50
1 false str
```

Constants can also be used to enumerate:

```go
    const (
        Unknown = 0
        Female = 1
        Male = 2
    )
```    

Numbers 0, 1 and 2, respectively, on behalf of unknown gender, women and men.

Constants can use len(), cap(), unsafe.Sizeof(). 

```go
package main

import "unsafe"
const (
    a = "abc"
    b = len(a)
    c = unsafe.Sizeof(a)
)

func main() {
    println(a, b, c)
}
```    

Examples of the above operating results are:

```
abc 3 16
```
git — Rebase vs Merge
Tags: git, rebase, merge
Published: 2020-02-26 07:43:28

Rebasing and merging are both designed to integrate changes from one branch into another branch but in different ways.

For ex. let’s say we have commits like below, the merge will result as a combination of commits, whereas rebase will add all the changes in feature branch starting from the last commit of the master branch:


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

* When you do rebase a feature branch onto master, you move the base of the feature branch to master branch’s ending point.

* Merging takes the contents of the feature branch and integrates it with the master branch. As a result, only the master branch is changed. The feature branch history remains same.

* Merging adds a new commit to your history.

Commits will look like :
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/q38tu0ww576x0bo8resn.JPG)

**When to rebase? When to Merge?**

If the feature branch you are getting changes from is shared with other developers, rebasing is not recommended, because the rebasing process will create inconsistent repositories. For individuals, rebasing makes a lot of sense.

If you want to see the history completely same as it happened, you should use merge. **Merge preserves history whereas rebase rewrites it.**

Rebasing is better to streamline a complex history, you are able to change the commit history by **interactive rebase**. You can remove undesired commits, squash two or more commits into one or edit the commit message.

Rebase will present conflicts one commit at a time whereas merge will present them all at once. It is better and much easier to handle the conflicts but you shouldn’t forget that reverting a rebase is much more difficult than reverting a merge if there are many conflicts. You can find details of a basic rebase process from [git — Basic Rebase](https://medium.com/@filissen/git-basic-rebase-1627b8296f04) .
Gatsby.js starter with light/dark themes based on CSS variables (TypeScript)
Tags: gatsby, javascript, typescript, webdev
Published: 2020-03-02 22:23:44

Hello, all my dear JAMStack'ers! If you are opened this post you might be feeling as much excited as me when working with modern static website generators. They are becoming so powerful! And Gatsby.js is definitely somewhere at the top of the list now. It works on React.js, has a large ecosystem and pretty descriptive docs. So more and more devs are trying it out. If you're one of them, I have something for you! Today I'd like to share with you my fresh Gatsby.js starter.

## What it includes:

- TypeScript support
- Light and Dark themes based on CSS variables (persisted state)
- Font Awesome
- Normalize.css
- Styling is done with CSS Modules
- SASS support (for both: global styles and CSS Modules)
- ESLint for linting TS

I made it simple and based on the default starter. Not much styling, nothing extra, all is in your hands...

## How it looks like:

![Starter Preview](https://dev-to-uploads.s3.amazonaws.com/i/aj4h1udbzwiiq2bkee4w.gif)

## Live demo is available here:

[gatsby-starter-typescript-themes.netlify.com](https://gatsby-starter-typescript-themes.netlify.com/)

## GitHub repository:

{% github room-js/gatsby-starter-typescript-themes %}

## How to create a new project:

1. Install Gatsby CLI: `npm install -g gatsby-cli`
2. Create a new project from this starter: `gatsby new my-themed-starter https://github.com/room-js/gatsby-starter-typescript-themes`

---

Thank you for reading!
If you like the starter I kindly ask you to star the GitHub repo and like the post! Also, if you got any questions about it, please let me know in the comments.

Read **JavaScript Room** blog on Instagram: [@room_js](https://instagram.com/room_js)
I have banned 'git commit -a'
Tags: git
Published: 2020-03-02 22:14:49

---
title: I have banned 'git commit -a'
published: true
description: An evil hack to improve my gitting
tags: git
---

Some time ago [I wrote](https://dev.to/drhyde/comment/cio7) that `git commit -a ...` was my least favourite git command, because it "makes it too easy to commit many unrelated changes with an unhelpful message. And of course I use it all the damned time."

Well, I finally got sufficiently annoyed at myself to do something about it.

On one of my machines this now lives in my `~/bin`, which is first in my `$PATH`. Only time will tell whether I find it more annoying than what it prevents:

```bash
#!/bin/bash

set -euo pipefail

function main {
    MYDIR="$( cd "$(dirname "$0")"; pwd -P)"
    export PATH=$(
        echo $PATH | sed -E "
            s@$MYDIR@@g
            s/::/:/g
            s/^:+//
            s/:+\$//
        "
    )

    if [ "$#" -ge 2 ] && [ "$1" == "commit" ]; then
        for i in "$@"; do
            if [ "$i" == "-a" ] || [ "$i" == "--all" ]; then
                echo NO\! SHAN\'T\! $i is BAD\!
                exit 1;
            fi
        done
    fi
    exec git "$@"
}

main "$@"
```

Update: 24 Apr 2020: I've moved this code into [a function that is `source`d into my shell](https://github.com/DrHyde/configurations/blob/master/bash/dot-bash_functions.d/git) and which also applies some default args to `git log`. I've found it sufficiently un-annoying and useful that it's now part of my config on every machine I use.

Patches welcome on Github!
Everything to know about for...in and for...of
Tags: javascript, frontend
Published: 2020-03-02 22:14:10

# for...of vs for...in

Everything you should know before using `for...in` or `for...of`

## for...of

`for...of` statement creates a loop iterating over
 iterable objects, including: build-in `String`, `Array`,array-like objects (e.g: `arguments` or `NodeList` ), `TypedArray`, `Set`, `Map`, and user-defined iterables. It invokes a custom iterable hook for the statements to be executed for the value of each distinct property of the object.

### Iterate over `Array`

```javascript
let l = [20, 30, 40];
// use let 
for (let item of l) {
    item += 1
    console.log(item)
}
// 21
// 31
// 41

// use const 
for (const item of l) {
    console.log(item)
}
// 20
// 30
// 40
```

### Iterate over `NodeList`

Iterate through `li` with class `.list` and adding .active

```javascript
let lis = document.querySelectorAll('ul > li.list');

for (let li of lis){ 
li.classList.add('active');
}
```

### Iterate over `String`

```javascript
let str = 'hello';

for (let char of str) {
    console.log(char)
}
// h
// e
// l
// l
// o
```

### Iterate over `Set` and `Map`

```javascript
// Set
let list = [1, 2, 2, 3, 4];
let set = new Set(list);

for (let i of set) {
    console.log(i);
}
// 1
// 2
// 3
// 4

// Map
let map = new Map([['milk', 10], ['potatoes', 20]]);

for (let [key, value] of map) {
    console.log(key, value) 
}
// milk 10
//  potatoes 20
```

## for...in

`for...in` can be applied on iterable, object and return the index or key of each element.

```javascript
let arr = [1, 3, 4];

let obj = { milk: 10, grappes: 23 };

// work well
for (let key in arr) {
  console.log(key);
}
// Output:
// 0
// 1
// 2

// will return keys
for (let key in obj) {
  console.log(key);
}
// Output:
// milk
// grappes

```

# Thank You
Rust 新概念
Tags: rust
Published: 2020-02-26 05:43:11

Rust 在指针安全上做了很多功夫。


### 所有权
在Rust中出现的新概念。

```rust

let str1 = String::from("H");
let str2 = str1;

// 编译是不会通过了
println!("{}", str1)

```
在这里 str1 把它指向地址的所有权给了 str2，str1不再指向任何地址。


### 可变引用

可变引用有一个很大的限制：在特定作用域中的特定数据有且只有一个可变引用。
这些代码会失败：
```rust
    let mut s = String::from("hello");
    let r1 = &mut s;
    let r2 = &mut s;
    println!("{}, {}", r1, r2);
```


这个限制允许可变性，不过是以一种受限制的方式允许。

新 Rustacean 们经常与此作斗争，因为大部分语言中变量任何时候都是可变的。这个限制的好处是 Rust 可以在编译时就避免数据竞争。

数据竞争（data race）类似于竞态条件，它可由这三个行为造成：
- 两个或更多指针同时访问同一数据。
- 至少有一个指针被用来写入数据。
- 没有同步数据访问的机制。

数据竞争会导致未定义行为，难以在运行时追踪，并且难以诊断和修复；Rust 避免了这种情况的发生，因为它甚至不会编译存在数据竞争的代码！


### 悬垂引用


让我们尝试创建一个悬垂引用，Rust 会通过一个编译时错误来避免：

```rust
fn main() { 
    let reference_to_nothing = dangle(); 
} 

fn dangle() -> &String { 
    let s = String::from("hello"); 
    &s 
}
```

dangle Function 尝试返回其内部变量 s 的引用，然而返回之后s 的所被分配的内存因为出栈就会被回收，得到引用的Main Function 引用的也是个未知的内存地址。这非常的危险。

```rust
fn no_dangle() -> String {
    let s = String::from("hello");
    s
}
```
这样就没问题了，所有权被转移。
How to Write a good Dev.to post?
Tags: watercooler, meta
Published: 2020-03-02 22:02:10

I really like the Dev.to community. Only been here a few days but people are super nice and it's a great place to brain dump my thoughts.

So for both networking and personal satisfaction reasons, I'm thinking about making posts and sharing them to the general public rather than haunting people like a poltergeist.

Any thoughts from the community, especially those that actually have some community street cred, on the kinds of things you make posts about, the ones that stick, the ones that get engaged and the ones that stink or are just magnets for trolling?

I'm specifically interested in starting friendly debates over slightly controversial things. IE, the advantages of certain frameworks over others, good vs. bad practices, the state of the industry, etc. I want to sort of trial run my thinking on a lot of things and get friendly and helpful push-back so I can refine my ideas. 

I'm also interested in maybe writing a few tutorials. I'm self-taught and being able to give a hand-up to the new generation coming up behind me appeals to me greatly. 

I can see a few patterns on what works and what doesn't already, but I'm interested in any nuggets of insight that might not be obvious.
Xamarin.Android - Using SwipeRefreshLayout
Tags: android, xamarin, mobile
Published: 2020-03-02 21:53:50

<h2> Layout: </h2>

```javascript
    <android.support.v4.widget.SwipeRefreshLayout
                    android:id="@+id/swipeRefreshLayoutMain"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
     
                    <ListView
                        android:id="@+id/listMain"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"/>
     
                </android.support.v4.widget.SwipeRefreshLayout>
```

<h2>Activity:</h2>

```javascript

    using Android.App;
    using Android.OS;
    using Android.Support.V7.App;
    using Android.Runtime;
    using Android.Widget;
    using Android.Support.V4.Widget;
     
    namespace SwipeRefreshExample
    {
        [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
        public class MainActivity : AppCompatActivity
        {
            ListView listMain;
            SwipeRefreshLayout swipeRefreshLayoutMain;
     
            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);
                Xamarin.Essentials.Platform.Init(this, savedInstanceState);
                // Set our view from the "main" layout resource
                SetContentView(Resource.Layout.activity_main);
     
                listMain = FindViewById<ListView>(Resource.Id.listMain);
                swipeRefreshLayoutMain = FindViewById<SwipeRefreshLayout>(Resource.Id.swipeRefreshLayoutMain);
     
                swipeRefreshLayoutMain.Refresh += SwipeRefreshLayoutMain_Refresh;
            }
     
            private void SwipeRefreshLayoutMain_Refresh(object sender, System.EventArgs e)
            {
                showData();
                swipeRefreshLayoutMain.Refreshing = false;
            }
     
            public void showData()
            {
                string[] data = new string[] { "Data 1", "Data 2", "Data 3", "Data 4", "Data 5" };
     
                ArrayAdapter arrayAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, data);
     
                listMain.Adapter = arrayAdapter;
            }
     
            public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
            {
                Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
     
                base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
            }
        }
    }
```

Finish and Output:

<img src="http://semihcelikol.com/wp-content/uploads/2020/02/SwipeRefreshLayoutExample.gif" >