teleren/devto huggingface dataset:
Update json file with Environment Variable - Compiling ENV without Webpack on Electron
Tags: electron, cicd, json, env
Published: 2021-07-30 15:54:21

In the Electron App that we develop at our company, there is no Webpack configured for bundling the App, since the App is just a shell to render a Web App. Moreover, the Electron code base isn't that big to deserve a sophisticated bundler, the Web App within is already CRA with typescript.

However, we are losing the benefit of having the default support of dotEnv supported by Webpack bundler, as well as hot reload and other cool features. Since CRA already hot reload the web contents, is not that big of a deal for Electron to have hot reload since it is just a frame. Then, ENV compilation becomes a major problem when we don't bundle the codes with the respective `env` for `electron-builder` to build.

Electron-builder is a packager that package the code, it does not compile your env file for you. Thus, your env inside the codes will become `undefined` in the packaged build if we skip the bundling process. not cool :(

While not using Webpack or other bundling tool, we created a json file to host the env that we need and update them during CI/CD process. That way, we can just inject ENV that are set in the CI/CD tool into the json dynamically according to build pipeline.

First, create a `config.json` file that stores the list of env that you want to update during build. It should default to dev environment variable so that you do not need to update them every-time during development. For example,

```json
{
  "env": "development",
  "appUrl": "http://localhost:8080/",
  "bugsnagAppId": ""
}

```

In your code,

```javascript
// main.js
const fs = require('fs');
const config = JSON.parse(fs.readFileSync(path.join(__dirname, './build/config.json'), 'utf8'));
const isDevelopment = config.env === 'development';

if (isDevelopment) window.loadUrl(config.appUrl);
```

Then, set up your ENV in your CI/CD tool, you may have staging build pipeline and production build pipeline that has its own set of ENV. Once all is set, we use `json` library to do the key-value update accordingly. Below is the script that we execute during CI/CD.
```bash
# build-script.sh
yarn install

json -I -f build/config.json -e "this.env='$(echo $NODE_ENV)'"
json -I -f build/config.json -e "this.appUrl='$(echo $APP_URL)'"
json -I -f build/config.json -e "this.bugsnagAppId='$(echo $BUGSNAG_APPID)'"

yarn build:mac

```

* Remember to add the library https://github.com/trentm/json to your package.json for it to work :)

Now, you have a dynamic config.json in different build of your Electron App.
An Article I Just Stole But Actually Not
Published: 2021-07-30 15:50:46

{% youtube rW16dg8boUo %}

Article rewriting, paraphrasing, spinning, synonymizing, I'm not sure if that last one's even a word but, it all refers to the same thing and that's to make someone else's article your own by replacing keywords with their synonyms which gives you the ability to have unlimited, plagiarism-free, instant articles of your own. 

>###*Why Would Anyone Need a Rewriter/Paraphraser?*

We're not talking about the traditional paraphrasing where content from other author's books is used. At the time of writing this script there are 160 billion websites and at least 600 million of these are blogs and I don't even wanna count how many articles these blogs would contribute, since I suck at maths, and making unique, Search-Engine-Friendly articles at this rate is quite impossible for an average human being. That's where article rewriting, paraphrasing, and blah blah blah comes into play and there are a ton of different tools that automate this process that's not so easy otherwise and all it takes is a few clicks.

I personally use the tool of this website called [SEO Helpify](https://www.seohelpify.com/article-rewriter), yeah, what the hell is that name, cuz of a couple of reasons.
* Its straight forward.
* It's not pumped with ads.
* It has a dark mode.

![SEO Helpify's Article Rewriter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/72hfhhenimnk0j79bfg1.png)
 
All you gotta do is copy that article your mouth watered about and paste it in the text box and then click the big red `submit` button and it'll generate a plagiarism-free, unique, SEO-friendly article with a shit ton of grammar mistakes. Arguably that's how Artificial Intelligence works these days, hope that changes soon and we get rid of our ugly jobs, if you know what I mean.

##Utilizing Grammarly For Maximized Efficiency.

Now to fix this you'll need an extension called grammarly, visit your browser's add-ons store and add the grammarly extension to your browser, also visit their website and `activate` the extension and let the games begin. 
![grammarly](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fyjl0g1wy5eezz5h4xey.png)
 
Now if it all worked nice and clean you can click on the rewritten article in SEO Helpify and grammarly will start doing its thing and mark all the problems whether they're grammatical errors or spelling mistakes. Copy this article once you're finished and use it anywhere you want, easy as that. If you liked this article and want to see more relevant content then please like and follow and don't forget to subscribe to our [youtube channel](https://www.youtube.com/channel/UCYCAUsfy9JybOT-DvdTV_sA) cuz we, at Devshot, are gonna take you to the moon!
形式手法の話
Published: 2021-07-30 15:46:14

# 背景
社内で形式手法の勉強会が行われた。この[リンク](https://www.marulabo.net/docs/aws-formal/)の内容。全3回のうちの第1回らしい。
形式手法は知ってはいたけど、非常にコストが高く実務的ではないという認識だった。この勉強会は、クラウドなど産業界で実際に使われている事例を紹介して、興味を持つことを目指しているようだった。

勉強会のスライドを読み進めると、上記リンク中の参考資料1「[Amazon Web Services はどのように形式手法を利用したか](https://drive.google.com/file/d/1OY7GmEZLTDnIgS3D0JlsLFOz7qmWGeRv/view)」を読むよう記載されており、読んでみると非常に興味深いものだった。
勉強会第一回の内容と合わせて、面白いと思ったところをまとめてみる。

# AWSでの形式手法の利用
報道されるような重要なシステムでの大規模障害の原因は様々で、対処方法も複数ある。
仕様の誤りに形式手法で対応できれば、正確な仕様を元にした実装とテストができ、障害を防ぐことができる。
障害発生後の原因は調査しやすいが、障害発生前に防ぐことは難しい。形式手法ならそれができる。
クラウドのような大規模かつ複雑な並列・分散システムでは、ハードウェアや人間のエラーも想定しなければならない。このような複雑な仕様を、検証可能で表現力のある形式手法で取り扱うことが必要となっている。

形式手法で検証可能な仕様が記載されれば、そこから実装を生成することもできるかもしれない。その場合、実装する人間は仕事が少なくなるかもしれない。
しかし、仕様を作成する仕事は創造性が求められ、これは人間にしかできない。

# Amazon Web Services はどのように形式手法を利用したか
形式手法ではない、業界で一般的な方法では、大規模分散システムのレアケースを未然に発見することはできなかった。
この問題を解決することを目標として、代替手段を探し始めた。

複雑な仕様を厳密に記述しつつ、記述量を抑制するソリューションとして、[TLA+](https://lamport.azurewebsites.net/tla/tla.html)を見出した。
TLA+は離散数学に基づいた形式的仕様記述言語で、モデルチェッカーはもちろん、疑似コードを置き換える表現力を持つPlusCal言語を備えている。

設計にTLA+を使うことの副次的な利点として、人間の設計手法を向上させることがある。
TLAによらない既存の手法では、まずビジネス要求に応える最短のハッピーケースを設計し、その後でエンジニア個人の知識と経験に基づき問題点の検討を行う。この場合、能力を超える複雑な問題を見つけることはできない。
TLA+の場合はまず「正しく進むには何が必要か」というシステム特性を、安全性と生存性の観点から記述することから始まる。次に、ハードウェアの異常や人間のミスなど、起こりうる動的イベントを特定する。その後、モデルチェッカーで仕様の正しさを確認する。
前者は「うまくいかないもの」をアドホックに見つけ、後者は「正しく進むために必要なもの」を厳密に特定する。

形式手法はまた、仕様が安全であること、または安全ではないことを、事前に知ることができる。
さらに、優れたドキュメントとして機能する。

> さらに、設計の正確でテスト可能な、十分にコメントされた記述は、優れた形式のドキュメントである。というのも、AWS システムのライフタイムには期限がないため、このことは、重要である。
時間が経過し、ビジネスの成⻑とともにチームも成⻑する。そのため、我々は定期的に新しい人々をシステムに慣れさせる必要がある。この教育は効果的でなければならない。微妙なバグを作らないようにするには、すべてのエンジニアがシステムの同じメンタルモデルを持つことが必要なのだが、その共有モデルは、精密で正確で完全である必要がある。
エンジニアはさまざまな方法でメンタルモデルを形成する。互いに話し合ったり、設計ドキュメントを読んだり、コードを読んだり、バグ修正や小さな機能を実装したりする。 しかし、会話や設計のドキュメントはあいまいであったり不完全であったりする。実行可能コードが大きすぎてすぐに理解できなかったり、あるいはそのコードは意図したデザインを正確に反映していない場合があるのだ。 対照的に、形式仕様は、正確で短く、ツールを使用して調査や実験ができる。

TLA+に向いていないこともある。AWSのインフラはハード・リアルタイムスケジューリングをサポートしておらず、サービスに対しては一定以上の遅延をエラーとみなすソフト・リアルタイムスケジューリングが要求されている。
TLA+では安全上の特性として応答時間の上限を設定できるが、このギャップを埋めるには至っていない。

## AWSでの形式手法の導入経緯
バグを防ぐ手法を模索する上で、形式手法はROIが低いという偏見があり、当初は検討されていなかった。
ある時、形式手法言語[Alloy](http://alloytools.org/)によって分散システムのメンバーシップ・プロトコル[Chord](https://ja.wikipedia.org/wiki/Chord)の不具合を見つけたことで、有用性を認識した。
Allowの表現力不足を解決する方法を模索していた際、LamportのFast Paxos論文のAppendixにTLA+仕様が記載されていることを見つけた。
Paxosアルゴリズム作成者がTLA+を作ったという事実は、TLA+の実用性を確信させるものだった。

[Lamport, L. Fast Paxos. Distrib. Comput. 19, 79–103 (2006). https://doi.org/10.1007/s00446-006-0005-x](https://link.springer.com/article/10.1007%2Fs00446-006-0005-x)
※自分は論文へのアクセス権を持っていないので未確認

発見者はAmazonの同僚にTLA+を薦めたが、必要性がなく導入はされなかった。
しかしDynamoDBで採用され、TLA＋の学習と仕様記述を2週間で行い、8Coreと23GBのEC2インスタンス10台でモデルチェッカーの分散バージョンを実行して、データが失われるバグを発見した。
このDynamoDBでの成功と、社内へのプレゼンテーションの工夫によって、TLA+を伝える試みを改善させた。

> エンジニアは「検証」ではなくデバッグの観点から考えるため、プレゼンテーションでは「設計のデバッグ」と呼んだ[18]。こうしたメタファーを続けながら、エンジニアは、「徹底的にテスト可能な疑似コード」と呼ぶと、TLA+の概念と実用的な価値をより簡単に把握できることに気づいた。 形式手法は実践的ではないと広く見られていたため、最初は「形式」、「検証」、「証明」という言葉を使うのを避けた。また、我々は、最初に TLA が何を表すのかについて言及することは避けた。

このような活動によって、S3のチームから導入サポートの依頼があった。

結果として、2011年から現在に至るまで、AWSでは形式手法が用いられている。
Introducing the social image generator
Tags: showdev, webdev, writing
Published: 2021-07-30 15:42:49

Creating social images are a pain. I barely add any (just look through my posts and you'll know). But now, you can easily generate social sharing images using my [generator](https://github.com/SiddharthShyniben/social-image-generator). It's not a generator yet, more like a HTML generator where you screenshot the page.

Wanna know how it looks? Check the social image of this post up ^ there. It supports tags, text, images, captions, and more to come soon!
The Engineering Executive Operating System — Part 2
Tags: management, leadership, devops, agile
Published: 2021-07-30 15:39:56


## The Engineering Executive Operating System — Part 2 

Today on the [Dev Interrupted Podcast](https://devinterrupted.com/podcast/the-engineering-executive-operating-system-part-2), we premiere the second and final episode in our two-part series with Tech Executive Consultant and author, Aviv Ben-Yosef.

If you haven’t listened to the first episode, we highly recommend checking it out. Aviv is an expert at onboarding new employees, particularly those joining leadership positions.

In episode 2 we discuss how leadership can provide a workplace culture where employees are encouraged to speak up and question leadership decisions as well as how to create high impact R&D organizations.

[Get a sample chapter of Aviv’s book here.](https://avivbenyosef.com/tech-executive-operating-system/)

#**Listen to the full episode**
{% spotify spotify:episode:6MrAOnueZ07n4KdjnXDx8M %}

## Part 2 Highlights Include:

* Each member of a team becoming a force multiplier

* “Chutzpah driven development”

* How to have candid discussions between leadership and employees

* Providing a culture where employees can tell leadership they are wrong

* Creating high-impact R&D organizations and teams

{% youtube H_oyLCAX2qw %}
## Join the Dev Interrupted Server

With over 1400 members, the Dev Interrupted Discord Community is the best place for Engineering Leaders to engage in daily conversation. No sales people allowed. [Join the community >>](https://discord.com/invite/devinterrupted)

![](https://cdn-images-1.medium.com/max/2878/1*BAy13fLk6AB3z5sJNtmP4g.png)



*Originally published at [https://devinterrupted.com](https://devinterrupted.com/podcast/the-engineering-executive-operating-system-part-2).*
Laravel 8 Notes Part 1 - Factory
Tags: php, laravel
Published: 2021-07-30 15:38:14

Factory berguna untuk mengetest dengan cara populate database kita dengan data dummy atau data palsu.
Laravel menggunakan bantuan dari library [FakerPHP/Faker](https://github.com/FakerPHP/Faker/).

## Step 1 - Generate Factory File

```
php artisan make:factory NamaFactory
```

## Step 2 - Masukkan Faker Sesuai Atribut Model

```
<?php

namespace Database\Factories;

use App\Models\Model;
use Illuminate\Database\Eloquent\Factories\Factory;

class CompanyFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Model::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        $name = $this->faker->company;

        return [
            'user_id' => User::inRandomOrder()->first()->id,
            'name' => $name,
            'slug' => Str::slug($name, '-'),
            'phone_number' => $this->faker->phonenumber,
            'building_name' => $this->faker->buildingnumber,
            'street_address1' => $this->faker->StreetAddress,
            'city' => $this->faker->city,
            'country' => $this->faker->country,
            'postcode' => $this->faker->postcode,
        ];
    }
}
```

## Step 3 - Generate Data with Tinker

```
> php artisan tinker
App\Models\NamaModel::factory()->count(3)->make();
```
Run a TypeScript type check in your pre-commit hook using lint-staged + husky
Tags: typescript, webdev, git
Published: 2021-07-30 15:34:51

A great way to prevent TypeScript compilation errors from bringing down your CI pipelines is to introduce a type check _before_ you commit your `.ts` file changes. 

If you've worked with Git Hooks before, you'll probably know that one of the best combinations for running pre-commit checks is [husky](https://typicode.github.io/husky/#/) and [lint-staged](https://github.com/okonet/lint-staged). 

Together, these two packages allow you to tap into the relevant Git hook and run commands such as linting on _staged files only_. It saves a bunch of debugging time by fixing preventable errors sooner in the development process.

As a separate step, if you want to check for TypeScript type errors (note: this is different to syntax errors which ESLint picks up and fixes for you), you would typically run a command in the CLI such as `npx tsc --noEmit` to compile the TypeScript and highlight any type errors to address.

Now, the best case scenario here is that you simply pop the above TypeScript command into your lint-staged config along with anything else e.g. ESLint, and you're good to go! 

Oh no, it doesn't quite work as expected. The error message that you may come across looks something like this: 

```
Option 'project' cannot be mixed with source files on a command line.
```

The issue I found - and at the time of writing, [it is still being discussed](https://github.com/microsoft/TypeScript/issues/27379#issuecomment-425245572) - is that lint-staged would pass each staged file to the `npx tsc` command like `npx tsc --noEmit file1.ts file2.ts` and that causes TypeScript to simply ignore your `tsconfig.json`.

Super frustrating!

Fear not however, as there is an extremely helpful tool that runs `tsc` on specific files _without_ ignoring tsconfig.json and it's called [tsc-files](https://www.npmjs.com/package/tsc-files). As the tool's author points out:

> I wanted to type-check only the staged files with lint-staged.

Perfect for my use case. So, after a quick look at the docs, it was as simple as updating the lint-staged config in my `package.json` file to use the `tsc-files` package:

```
{
  "husky": {
    "pre-commit": "lint-staged"
  },
  "lint-staged": {
    "**/*.ts": "tsc-files --noEmit"
  }
}
```

### Conclusion

Now I am able to run a TypeScript type check on all my staged files using a pre-commit hook.

Tip: use the `--pretty` flag in the `tsc` command to add some formatting and colour to your type errors.

If you have any questions on this setup or have tried different approaches, feel free to comment below or start up a convo over on [Twitter](https://twitter.com/samueldjones).

Thanks for reading 👋
What are the key fundamental skills to learn to become a Backend Engineer? Check out this Youtube Channel 
Tags: beginners, codenewbie, webdev, computerscience
Published: 2021-07-30 15:29:00

I have decided to start a blog series on the skills to learn to become a backend engineer. I have started out as a front-end engineer but looking to expand my skills to learn more about backend engineering

I found this awesome YouTube channel called Hussein Nasser and he talks about different topics regarding backend engineering. In the video that I have watched (https://www.youtube.com/watch?v=V3ZPPPKEipA&list=PLQnljOFTspQUNnO4p00ua_C5mKTfldiYT&index=1) he mentions some skills to learn for backend engineering. Here are some things he mentioned:


1. Communication Protocols: Learning the basics of the communication protocols (low level) ex. TCP and UDP to higher level (HTTP), Web Sockets

2. Web Servers: Have the ability to serve content (Static, Caching, Dynamic). Learn the types of web servers

3. Database Engineering: Relational & Non-Relational Databases

4. Proxies: Reverse Proxies, Load balances (Huge Potential)

5. Caching: Caching Layers, Statefull vs Stateless Caching

6. Messaging Systems: Message queue, Pub/Sub 
   
7. Web API Frameworks: (Node.JS, Django, Express)

8. Message Formats: JSON & protobuf 

9. Security: TLS, Encryption, Firewalls 

Most important thing to take away is that you aren't going to be an expert at everything. Pick a few topics and dive deep into it.
Querying the Most Granular Demographics Dataset
Published: 2021-07-19 14:59:20

There are a plethora of use cases that require detailed population data. For example, having a detailed breakdown of the demographic structure is a significant factor in predicting real estate prices. Also, humanitarian projects such as vaccination campaigns or rural electrification plans highly depend on good population data.
It is very challenging to find high-quality and up-to-date data on a global scale for these use cases. Usually, census data is published every four years, which makes those datasets outdated quickly. Arguably the best datasets out there for population densities and demographics are published by Facebook under their Data for Good initiative. They combine official census data with their internal data and leverage machine learning algorithms for image recognition to determine buildings’ location and type.

Facebook Data for Good and Kuwala (2021)
Using those different sources can give a detailed statistical breakdown of demographic groups in 1-arcsecond blocks, a resolution of approximately 30 meters. Each square contains statistical values for the following demographic groups:
Total
Female
Male
Children under 5
Youth 15–24
Elderly 60 plus
Women of reproductive age 15–49
Facebook delivers for each country a file per demographic group, either as a GeoTIFF or CSV. The CSV contains the latitude and longitude of the cell and the respective population value.

Just working with a static CSV file can be cumbersome. That is why we created an open-source wrapper that exposes the data over an API. You can directly download the data for entire countries over a CLI. We preprocess the data to make it easily queryable. For that, we are leveraging the power of Uber’s H3 spatial indexing.
Thanks to the H3 indexing, it is easy to build queries on top of the database. Using either H3 cells or coordinate pairs, you can retrieve the population based on a point, a given radius, or polygon. That way, it is straightforward to aggregate the population on a zip code level, for example.

Uber H3 and Kuwala (2021)
We aggregate the squares into H3 cells at resolution 11 and store them in a MongoDB with the aggregated values for each demographic group. Using JS streams and MongoDB’s aggregation pipelines, the memory usage stays low, and you can process millions of rows on your local machine.

For quick data exploration and visualization, you can directly create datasets compatible with Kepler.gl or Unfolded.ai to make beautiful maps. We published an example map for Malta. It is directly visible where the highly populated regions are and where the heart of the city is.

By having Facebook’s population data now directly queryable, it is much faster to create predictive models or visualizations so data teams can spend time on the value-adding tasks. That is also the main reason why we are building an open-source community for third-party data integration with Kuwala. So if you want to get your hands on more connectors like these, star us on Github and join our Slack community.
How to change CPanel account root directory.
Published: 2021-07-30 15:28:21

## Step 1
Update variable `documentroot` in following two file:

```sh
sudo nano /var/cpanel/userdata/<cpanel-username>/<example.com>
sudo nano /var/cpanel/userdata/<cpanel-username>/<example.com>_SSL
```

Replace `<example.com>` to your actual domain.

You need update following line in both files:

```
documentroot: /home/<cpanel-username>/public_html
```

to your target folder.

Eg:

```
documentroot: /home/<cpanel-username>/public_html/public
```

## Step 2
Then edit:

```
sudo nano /var/cpanel/userdata/<cpanel-username>/<example.com>.php-fpm.yaml
```

and add following line

```
php_admin_value_doc_root: { name: 'php_admin_value[doc_root]', value: /home/<cpanel-username>/public_html/public }
```

Final file will look like:
```
---
_is_present: 1
php_admin_value_doc_root: { name: 'php_admin_value[doc_root]', value: /home/<cpanel-username>/public_html/public }
```


## Step 3
Then to rebuild the Apache conf and restart Apache:

```sh
/scripts/php_fpm_config --rebuild
/scripts/rebuildhttpdconf

/scripts/restartsrv_apache_php_fpm
/scripts/restartsrv_httpd
service httpd restart
```

When you visit your url and getting following message:
```
No input file specified
```

Simply restart the server, it should be fixed.
How to solve error NG8002: Can't bind to 'routerLink' since it isn't a known property of 'a'.?
Tags: angular, typescript, javascript
Published: 2021-07-30 15:17:22

I work on angular 11 I face error when build angular app

    ERROR in src/app/Employee-list/employee-list.component.html:22:45 - error NG8002: Can't bind to 
'routerLink' since it isn't a known property of 'a'.
<a class="nav-link text-dark" [routerLink]="['/employee-list']">Staff List</a>
and below is package json file

    "@angular/animations": "^11.2.14",
    "@angular/cdk": "^12.1.3",
    "@angular/common": "^11.0.0",
    "@angular/compiler": "^11.0.0",
    "@angular/core": "^11.0.0",
    "@angular/forms": "^11.0.0",
    "@angular/material": "^11.2.13",
    "@angular/router": "^11.2.14",
    "@angular/cli": "^11.0.0",
    "@angular/compiler-cli": "^11.0.0"
on application module I do as below :

import { RouterModule } from '@angular/router';


@NgModule({
 
  imports: [
    RouterModule
so How to solve issue ?

sample of app modules and component employee list exist as blow

https://stackblitz.com/edit/angular-uffug5?file=src%2Fapp%2FEmployee-list%2Femployee-list.component.ts
image for issue
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sn64gjoqxso8gqo75mf1.png)