teleren/devto huggingface dataset:
หัด Erlang and Elixir v0.1.0
Tags: erlang, elixir
Published: 2020-01-06 16:18:59

หลังจากไปงาน Elixir meetup ครั้งที่ผ่านมา สารภาพว่าไปไม่ทัน แถมไม่รู้เรื่องอะไรกับเค้าเลย T_T) เลยอยากลองสรุปเรื่อง Erlang กับ Elixir นิดหน่อย

NOTE: ผมใช้ macOS นะ

## การติดตั้ง

ทั้งสองภาษาติดตั้งได้ผ่าน brew 

```
# Erlang
$ brew install erlang

# Elixir
$ brew install elixir
```

## REPL

ทั้งสองภาษามี repl bundle มาให้ในตัว โดย Erlang นั้นจะใช้ชื่อว่า `erl` พอเราสั่งคำสั่งนี้ก็จะเปิด repl มาให้เลย 

```
$ erl
Erlang/OTP 22 [erts-10.6.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe] [dtrace]

Eshell V10.6.1  (abort with ^G)
1>
```

ส่วนของ Elixir นั้นใช้ชื่อว่า `iex` ก็จะหน้าตาคล้ายกันหน่อย

```
Erlang/OTP 22 [erts-10.6.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe] [dtrace]

Interactive Elixir (1.9.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>
```

หากถ้าอยากออกทั้งสอง shell ทำได้เหมือนกันเลยคือกด `Ctrl-C` จากนั้นกด `a` แล้ว Enter :)

## Hello, World

เริ่มที่ Erlang ก่อนเลย 

```
% hello_module.erl
-module(hello_module).
-export([hello/0]).

hello() ->
    io:format("~s~n", ["Hello, World"]).
```

Erlang มีกฎอยู่ว่าไฟล์ 1 ไฟล์จะประกอบไปด้วย 1 module และชื่อไฟล์ต้องตรงกับชื่อ module นั้นๆ ซึ่ง module จะต้องประกาศโดยใช้ `-module(<module_name>).` เสมอ จากนั้นเราต้องบอกด้วยว่า module นี้จะ export function อะไรบ้าง สังเกตว่าจะมี `/0` ต่อหลัง `hello` นั้นหมายความว่าให้ export function hello ที่มีจำนวน arguments 0 ตัว เดี๋ยวไว้อธิบายทีหลังจากว่ามีทำไม

ตัว function นั้นจะใช้ `->` เพื่อเปิด function body และใช้ `.` เพื่อบอกว่าจบ function แล้ว

ต่อมาคือการ compile เราสามารถ compile ได้ผ่าน `erl` โดยใช้ function ชื่อ `c()`:

```
1> c(hello_module).
{ok,hello_module}
```

หาก compile ผ่าน `c` จะตอบกลับมาว่า ok กับชื่อ module ที่มัน compile ผ่านแล้ว

ทีนี้มา Elixir บ้าง

กฎการตั้งชื่อไฟล์จะคล้ายๆ กัน แต่นามสกุลไฟล์เป็น `.ex`

```
# hello_module.ex

defmodule HelloModule do
  def hello() do
    IO.puts "Hello, World"
  end
end
```

การประกาศ module ของ Elixir นั้นใช้ keyword `defmodule` ตามด้วยชื่อ module ซึ่งจะใช้ pascal case กัน 

การประกาศ function ใช้ keyword `def` ตามด้วยชื่อ function และใช้ `do` และ `end` เพื่อเปิดและปิด function body

การ compile นั้นใช้ `c()` เหมือนกันแต่ต่างกันตรง Elixir จะใส่ชื่อไฟล์แทนชื่อ module: 

```
iex(1)> c("hello_module.ex")
[HelloModule]
```

## เรียก function 

ทั้งสองภาษาจะคล้ายกันโดยใช้ชื่อ module ตามด้วย function และ arguments แต่ต่างกันนิดหน่อยตรง syntax โดย Erlang ใช้ `<module>:<function>(<args...>).`

```
2> hello_module:hello().
Hello, World
ok
```

ส่วน Elixir ใช้

```
iex(2)> HelloModule.hello()
Hello, World
:ok
```

อีกหนึ่งความแตกต่างคือ Elixir ยอมให้เรียก function โดยไม่ใส่ `()` ได้ เช่น

```
iex(2)> HelloModule.hello
Hello, World
:ok
```

พอล่ะ ง่วง zZZ
Using Python to create Hive tables with random schema
Tags: hive, database, metadata, python
Published: 2020-01-06 16:18:47

Having a large amount of test data sometimes take a lot of effort,  and to simulate a more realistic scenario, it’s good to have a large number of tables with distinct column types. This script generates random tables schema for Hive.


If you want to set up a Hive environment for dev and test purposes, take a look at: https://dev.to/mesmacosta/quickly-set-up-a-hive-environment-on-gcp-38j8

## Environment

##### Activate your virtualenv
```bash
pip install --upgrade virtualenv
python3 -m virtualenv --python python3 env
source ./env/bin/activate
```

##### Install the requirements for the metadata generator
```bash
pip install -r requirements.txt
```

## Code
{% gist https://gist.github.com/mesmacosta/a4369114ae6c676ec628d8b32647e7c7 %}

## Execution
```bash
export HIVE_SERVER=127.0.0.1
export HIVE_USERNAME=hive
export HIVE_PORT=10000
export HIVE_DATABASE=default

python metadata_generator.py \
--hive-host=$HIVE_SERVER \
--hive-user=$HIVE_USERNAME \
--hive-port=$HIVE_PORT \
--hive-database=$HIVE_DATABASE
```

And that's it!

If you have difficulties, don’t hesitate reaching out. I would love to help you!
SUKU: Using CodeStream for Code Review, Easier than Pull Requests
Tags: codereview, productivity, codequality, discuss
Published: 2020-01-06 16:18:42

---
title: SUKU: Using CodeStream for Code Review, Easier than Pull Requests
published: true
cover_image: https://assets.website-files.com/5c3c1d73652ba045d765cdb1/5e02523b6e14efbe247521bc_suku_logo.png
canonical_url: https://www.codestream.com/blog/suku-using-codestream-for-code-review-easier-than-pull-requests
description: Engineering managers for global companies like SUKU commonly face the challenge of how to efficiently review code when working with offshore development teams. Learn how the SUKU team is using CodeStream to address that challenge and shorten code review time. 
tags: codereview, productivity, codequality, discuss
---

**Overview of SUKU**
SUKU is a blockchain solution used by companies to drive efficiency, transparency, and ultimately bring an institutional level of trust to the consumer-brand relationship.  SUKU’s platform employs an on-demand, open, decentralized software distribution model which consists of applications and services that are utilized by various participants. These applications are intended to be built with technology partners in a continually evolving ecosystem.  

**The Challenge**
Engineering managers for global companies like SUKU commonly face the challenge of how to efficiently review code when working with offshore development teams.  The challenge stems from the significant time zone differences between the teams, which was 11.5 hours for the SUKU team. The offshore team primarily relies on Slack for communications, but engineering management was seeking a more contextual way to communicate during the code review. 

**How the SUKU Team Uses CodeStream**
As a project release to address a user story nears the end of the development cycle and enters QA, an engineering manager or development lead will check out the branch and review the code using CodeStream. 
CodeStream allows the manager to review the code in his or her IDE and leave comments alongside the code, much in the same way as you can use the comment function in Google Docs to mark up a shared document. 
SUKU leverages CoderStream’s Slack integration, so the developers receive the reviewers’ comments via Slack, and they can respond directly from Slack if they have questions. 
When the code review cycle is finished, comments can be archived or deleted if they are no longer relevant, or they can be kept alongside the code if they provide lasting value as a form of documentation.  
The Bottom Line
“Using CodeStream for code reviews is easier than using pull requests. It’s as simple as checking out a new branch and leaving comments alongside the code in my IDE, like you would comment on a Google Doc. CodeStream handles delivering my comments to the developers via Slack with all the related code snippet and location information they need to resolve the issue. CodeStrream has shortened our code review time by around 25%, which enables us to work more efficiently while maintaining quality.  

- Bryce Doganer, Blockchain Engineer
Tip 4: Git Commit Templates & Conventional Commits
Tags: git, dotfiles
Published: 2020-01-06 16:18:32

Git commit messages are **important**. We all know that, yet ... in the heat of the moment, we're prone to this non-sense:

```shell
git commit -m "stuff"
```

```shell
git commit -m "fix"
```

```shell
git commit -m "it'll work this time!"
```

Any of them look familiar? You bet your ass they do.

## Adding a Git Commit Template

This is nice and easy. First, create a text file for your template inside your `~/.config/git` directory (`~/.git/` on macOS I think).

```text
# ~/.config/git/commit.txt
My Commit Template
```

Then update your Git configuration. You can do this one of 2 ways:

```shell
git config --global commit.template ~/.config/git/commit.txt
```

Or you can update your configuration file:

```shell
[commit]
template=~/.config/git/commit.txt
```

## Conventional Commits

Now that you've got a simple template. What should you put there?

Let me introduce you to [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).

You can find my template [here](https://gitlab.com/rawkode/dotfiles/raw/master/nix/includes/development/git-commit-template.txt).

The following is the summary and some examples from the website linked above.

---

### Conventional Commits

The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating an explicit commit history; which makes it easier to write automated tools on top of. This convention dovetails with SemVer, by describing the features, fixes, and breaking changes made in commit messages.

The commit message should be structured as follows:

```
<type>[optional scope]: <description>

[optional body]

[optional footer(s)]
```

#### Examples

##### Commit message with description and breaking change footer
```
feat: allow provided config object to extend other configs

BREAKING CHANGE: `extends` key in config file is now used for extending other config files
```

##### Commit message with `!` to draw attention to breaking change
```
refactor!: drop support for Node 6
```

##### Commit message with both `!` and BREAKING CHANGE footer
```
refactor!: drop support for Node 6

BREAKING CHANGE: refactor to use JavaScript features not available in Node 6.
```

##### Commit message with no body
```
docs: correct spelling of CHANGELOG
```

##### Commit message with scope
```
feat(lang): add polish language
```

##### Commit message with multi-paragraph body and multiple footers
```
fix: correct minor typos in code

see the issue for details

on typos fixed.

Reviewed-by: Z
Refs #133
```
Are you ready to work remotely?
Tags: beginners, questions, remotework
Published: 2020-01-12 20:47:42

---
title: Are you ready to work remotely?
published: true
date: 2020-01-06 16:18:18 UTC
tags: beginners,questions,remote work
canonical_url: https://letterstoanewdeveloper.com/2020/01/06/are-you-ready-to-work-remotely/
---

Dear new developer,

Remote work is fantastic. You avoid a commute, have control over your work environment, and save money on lunches. However, it has downsides. You need a fast internet connection, you must be disciplined, over communicate and stay on task. You have to be OK with relative solitude.

My desire to work remotely has changed over time. Frankly, for my first job, there’s no way I would have been happy working remotely. I enjoyed the collaboration, the camaraderie, and a place to go every day where there were interesting people. Even now, with Slack, Zoom and other modern tools, I’ve seen some new developers have similar concerns.

I do think that 100% remote work is different than “work from home once a week” or “work from home when you need to”. 100% remote work requires a different workflow, communication mechanism and concept of availability than those other options. Both of the latter options are really about providing flexibility and showing trust. They are great, low cost benefits for any software company to provide to developers.

Here is a one question test for anyone considering remote work. You can ask yourself this question and if the answer is yes, a remote position will likely work well for you. If the answer is no, then I think you’d be happier with an onsite position. By the way, some people are never going to want to work remotely for a variety of reasons, and that is no big deal.

That question is: **“Are you comfortable asking a dumb question in public?”**

You must ask questions that appear dumb when you get up to speed in any new company. Developers of all levels do this. Often it’s two levels of questioning. The first is “who can help with this?” and then the second is the actual question.

In a remote company you’ll have to accept that you are “interrupting” people and/or asking questions into a Slack channel. I have observed that both of these are more difficult when I can’t see the mental state of other people (as you can in an office).

You’ll need answers. So you have to be prepared to do ask these kind of questions, in public or interrupting someone you think might have the answer, over and over for the first couple of months of your remote job. [Public questions](https://www.culturefoundry.com/cultivate/digital-agency-life/why-public-slack-chats-are-better-than-direct-messages) are better for the team but harder on my ego.

If that thought of asking basic questions in public makes you uncomfortable, congrats, you’re human. But if it makes you want to run away and hide, then perhaps you aren’t ready for remote work. If you are interested in the flexibility and freedom of 100% remote work, wait a few years, practice asking questions and internalize the fact these kind of questions may feel dumb, but actually are just part of the process at any job.

Sincerely,

Dan
Animated SVG Signature
Tags: codepen, javascript, css
Published: 2020-01-06 16:12:08

<p>A demo for animating SVG signature or autograph.</p>

{% codepen https://codepen.io/CiTA/pen/abzJqQv %}

Read the article here: https://dev.to/starbist/how-to-animate-svg-signature-16gp.
Shell commands for simple tasks of processing CSV file - Linux Tips
Tags: linux, csv, bash, ubuntu
Published: 2020-01-06 16:00:00

### Paste

Use `paste` to concat 2 csv files:

```bash
$ cat students.csv
Name,Grad Year
Alice,2024
Bob,2022
Chris,2023

$ cat score.csv
Name,GPA
Alice,B+
Bob,A
Chris,A-

# concat 2 csv files
$ paste -d "," students.csv score.csv
Name,Grad Year,Name,GPA
Alice,2024,Alice,B+
Bob,2022,Bob,A
Chris,2023,Chris,A-
```

### Cut

Use `cut` to get designated columnes:

```bash
# Use -f 1,2,4 to get only 1st, 2nd and 4th column
$ paste -d "," students.csv score.csv | cut -d , -f 1,2,4
Name,Grad Year,GPA
Alice,2024,B+
Bob,2022,A
Chris,2023,A-
```

### Sort

Use `sort` to sort specified field in CSV file:

```bash
$ cat students.csv
Alice,85,alice@example.com
Bob,92,bob@example.com
Chris,60,chris@example.com

# now sort by score in descending order
# -t: split by
# -k: field number after split
# -n: compare field as number, not string
# -r: in reverse order
$ sort -t , -k 2 -nr students.csv
Bob,92,bob@example.com
Alice,85,alice@example.com
Chris,60,chris@example.com
```

### Awk

Use `awk` to get fields in CSV file:

```bash
$ cat students.csv
Alice,85,alice@example.com
Bob,92,alice@example.com
Chris,60,alice@example.com

# use `awk` to split each line and get 2nd field
$ cat students.csv | awk -F, '{print $2}'
85
92
60

# pipe with `sort` to get the highest score
$ cat students.csv | awk -F, '{print $2}' | sort | tail -1
92
```
Verifying a Nuxt Site on Flattr
Tags: nuxt, flattr, verification
Published: 2020-01-06 17:32:20

Out of the box, Nuxt sites cannot be used to verify domains on [Flattr](https://flattr.com/).

The only way to verify a domain with the service is to include a `<meta>` tag in the `<head>` of _all_ the pages on your site. The Flattr verification service expects this tag to have 2 attributes and 2 attributes **only**:-

```html
<meta name="flattr:id" content="abc123" />
```

The reason that this doesn't play nice with Nuxt is due to `data-n-head` attributes being added to all `<meta>` and `<link>` tags. The solution is to hook into specific Nuxt events and modify the HTML appropriately:-

```js
// nuxt.config.js
import cheerio from "cheerio";

const removeDataAttributeFromFlattrMetaTag = html => {
  const $ = cheerio.load(html);

  $('meta[name="flattr:id"]').removeAttr("data-n-head");

  return $.html();
};

export default {
  head: {
    meta: [{ name: "flattr:id", content: "abc123" }]
  },

  hooks: {
    generate: {
      page(page) {
        page.html = removeDataAttributeFromFlattrMetaTag(page.html);
      }
    },

    render: {
      route(url, page) {
        page.html = removeDataAttributeFromFlattrMetaTag(page.html);
      }
    }
  }
};
```

Stripping the `data-n-head` attributes from the `<meta>` tags in this way is enough to appease the Flattr verification service. I have spoken with the support team at Flattr and brought this issue to their attention, but this workaround will suffice for now.

This attribute serves some purpose in the handover between Nuxt SSR and client-side hydration and originates from the [Vue Meta plugin](https://github.com/nuxt/vue-meta). I presume that removing the attribute in the manner outlined above doesn't cause any issues – especially since this attribute won't be updated elsewhere. But, if you're looking for an alternative, you can add the `<meta>` tag to the [app template](https://nuxtjs.org/guide/views#app-template) instead:-

```html
<!-- ~/app.html -->
<!DOCTYPE html>
<html {{ HTML_ATTRS }}>
  <head {{ HEAD_ATTRS }}>
    <meta name="flattr:id" content="abc123" />
    {{ HEAD }}
  </head>
  <body {{ BODY_ATTRS }}>
    {{ APP }}
  </body>
</html>
```

**UPDATE**: After getting to know [Vue Meta](https://vue-meta.nuxtjs.org/) a little better, I discovered the [`once`](https://vue-meta.nuxtjs.org/api/#once) special `metaInfo` attribute. This disables reactivity and, in the case of Nuxt, only outputs the tag during server-side rendering (without `data-*` attributes):-

```js
// nuxt.config.js
export default {
  head: {
    meta: [{ name: "flattr:id", content: "abc123", once: true }]
  }
};
```
How to Reset MySql Root password on MacOS 10.13
Tags: macos, mysql, password, database
Published: 2020-01-06 15:50:20

You might have had a situation where you forgot your [MySQL root password](https://anansewaa.com/reset-mysql-root-password-ubuntu-server/). How will you solve such a problem in MacOS High Sierra. Here are a few steps to solving that issue that is resetting mysql root password.

## Step 1: Stop MySQL service
You can do that by simply going to preference pane and click on MySQL then click on Stop MySQL Server or you type the command below in your Terminal to stop MySQL
```
sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop
```
## Step 2: Skip Access Tables
For MySQL5 execute the command below in your Terminal
```
/usr/local/mysql/bin/mysqld_safe --skip-grant-tables
```
And for older versions of MySQL, execute the command below in your Terminal
```
/usr/local/mysql/bin/safe_mysqld --skip-grant-tables
```
## Step 3: Reset MySQL root password
After running the above command in a Terminal, open another Terminal window and run the command below which will open up MySQL console making it easier for you to update your MySQL root user.
```
/usr/local/mysql/bin/mysql mysql
```
The query below will reset the root password
```
UPDATE user SET Password=PASSWORD(‘YOUR_PASSWORD’) WHERE Host=’localhost’ AND User=’root’;
```
If you are using MySQL5.7 the above code might not work for you. To make it work replace password with authentication_string and you are good to go
```
UPDATE user SET authentication_string=‘YOUR_PASSWORD’ WHERE Host=’localhost’ AND User=’root’;
```
Replace “YOUR_PASSWORD” with your desired password.

Conclusion
Once you are done updating your root password use the exit; command in the console to close the safe_mysqld execution.

Now, restart MySQL server using the following command
```
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
```
Once every step is successful then you can access MySQL again with no issues.
Setting up a Swift Vapor development environment on Linux
Tags: linux, swift, vapor
Published: 2020-01-06 15:38:41

... which is _not_ Ubuntu 14.04, 16.04, 16.10, 18.04 or 18.10.

As you've certainly guessed these are officially supported ones. So if you're not happened to use one of them (I use Linux Mint 19.3) official install instructions will not work (I've tried).

Luckily enough "manual" installation works pretty much automatically and out-of-the-box anyway. :)

## Install Swift

Apparently official latest [Ubuntu 18.04 toolchain](https://swift.org/builds/swift-5.1.3-release/ubuntu1804/swift-5.1.3-RELEASE/swift-5.1.3-RELEASE-ubuntu18.04.tar.gz) works on my Linux Mint 19.3 just fine. I simply downloaded the archive, extracted it and added `usr/bin` subdirectory to my `PATH` and then `swift` worked with no issues (so far :)).


## Install Vapor CLI

As we already know we can't just install Vapor CLI (aka Vapor Toolbox) simply following official instructions. Luckily building from source works as automatic as it can. :)

Step one: clone the toolbox repository into some directory and `cd` there.


```sh
$ git clone https://github.com/vapor/toolbox vapor-toolbox
$ cd vapor-toolbox
```

Step two: just build the thing with Swift! :D (Note: I copied the command from a [Dockerfile](https://github.com/vapor/toolbox/blob/master/Dockerfile) in the repo).

```sh
$ swift build -c release
```

After that we have a self-contained executable file `vapor` somewhere down the hidden `.build` dir we can copy anywhere on our `PATH` (I've copied it to my `$HOME/.local/bin`).

```sh
$ cp .build/release/vapor ~/.local/bin/
```

Now we can use it! :)

```sh
$ cd /tmp
$ vapor new Hello
$ cd Hello
```
And after answering 2 questions (I agreed to use Fluent and choose PostgreSQL) we have our first Vapor project.

Now we can build it!

```
$ vapor build
Building project..
swift build
/tmp/VaporTest/Hello: error: manifest parse error(s):
Invalid semantic version string '-beta'
error:
Failed to build.
```

OK, just not yet.

Apparently, the toolbox missed some template data for the `Package.swift`. Particularly in the line 13:
```swift
.package(url: "https://github.com/vapor/fluent--driver.git", from: "-beta")
```

That should be
```swift
.package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "1.0.0-beta")
```

At least that's what I've figured from the Github repo and that worked. :)


Run build again, wait for ages... I had no nerve and time to wait till completion, I only waited for couple hours. The process is still flawed it seems... :'D