teleren/devto huggingface dataset:
ทำความเข้าใจ sync.Mutex กับ sync.RWMutex ของ Go
Tags: go, programming
Published: 2021-01-11 00:25:47

ทำความเข้าใจสอง type ที่ช่วยในการ lock การแย่งกันใช้ resources

จริงๆ Mutex นี่มันเป็นการผสมมาจากคำว่า Mutual Exclusion พอมาอยู่ในบริบทของการ Lock ก็คือกันไม่ให้เกิดการแย่งกันทำงาน ในบริบทของสอง type นี้ของ Go นั่นก็คือ กันไม่ให้หลายๆ goroutines แย่งการทำงานหรือแย่งกันใช้ resources ที่เราต้องการจำกัดการเข้าถึงของหลายๆ goroutine นั่นเอง

## type sync.Mutex
เริ่มที่ `type sync.Mutex` นั้นช่วยให้เรา lock แบบ ณ ขณะเวลาใดนั้นจะมีแค่ 1 goroutine ที่ใช้งานได้จนกว่ามันจะ unlock ส่วน goroutine อื่นๆที่ขอ lock การใช้งานเมื่อมี goroutine อื่น lock ไว้ก็จะต้องหยุดรออยู่อย่างนั้น

ตัวอย่างเช่นโค้ดต่อไปนี้

```go
package main

import (
	"fmt"
	"sync"
	"time"
)

var m sync.Mutex

var n = 10

func p() {
	m.Lock()
	fmt.Println(n)
	time.Sleep(1 * time.Second)
	m.Unlock()
}

func main() {
	go p()
	p()
	time.Sleep(3 * time.Second)
	fmt.Println("DONE")
}
```

จากการทำงาน function `p` เราจะใช้ m ที่เป็น `sync.Mutex` โดยเรียก method `Lock` เพื่อกัน goroutine อื่นรันโค้ดต่อไปจากนี้จนกว่าจะเรียก method `Unlock`

ทำให้ถ้าเราเรียกแบบใน main ที่แยกรันอีก goroutine ทั้งสอง goroutine นี้จะ block กัน มันจะรัน `go p()` จนกว่าจะเรียก `m.Unlock()` การทำงานของ `p()` ถึงจะไปต่อจากบรรทัดที่เรียก `m.Lock()` ได้

## type sync.RWMutex
ส่วน `type sync.RWMutex` นั้นมี `Lock()` กับ `Unlock()` เหมือนกัน แต่จะเพิ่มกลไก `RLock()` กับ `RUnlock()` เข้ามา เพื่อขอ lock สำหรับอ่านอย่างเดียว ซึ่งจะทำให้ทำให้คนที่ขอ `RLock()` เหมือนกันทำงานพร้อมกันได้ แต่จะ lock คนที่ขอ `Lock()` เพื่อแก้ไขข้อมูล

ตัวอย่างโค้ดเช่น

```go
package main

import (
	"fmt"
	"sync"
	"time"
)

var rw sync.RWMutex

var n = 10

func p() {
	rw.RLock()
	fmt.Println(n)
	time.Sleep(1 * time.Second)
	rw.RUnlock()
}

func q(v int) {
	rw.Lock()
	n = v
	time.Sleep(1 * time.Second)
	rw.Unlock()
}

func main() {
	go p()
	p()
	q(20)
	time.Sleep(3 * time.Second)
	fmt.Println("DONE")
}

```

เราเพิ่ม `q` เข้ามาเพื่อเป็นฟังก์ชันที่เขียนข้อมูลโดยเรียก `Lock()` ถ้าเกิด `q` สามารถ lock ได้ goroutine อื่นๆที่เรียก `rw.Lock()` หรือ `rw.RLock()` ต้องรอ goroutine ที่ได้การทำงานไป `Unlock()` ก่อน

ถ้ามี goroutine ทีทำงาน `p` ที่เรียก `RLock()` เอาไว้ก่อน แล้วมี goroutine อื่นที่รัน `p` เหมือนกันด้วยจะไม่ block กันเพราะถ้ามี `RLock()` ทำงานอยู่มันจะ block เฉพาะ `Lock()` เท่านั้น

การ block จะเป็นตามตารางนี้

|       | RLock     | Lock  |
|-------|-----------|-------|
| RLock | NOT BLOCK | BLOCK |
| Lock  | BLOCK     | BLOCK | 

<a href="https://www.buymeacoffee.com/weerasak" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
Async JavaScript
Tags: javascript, computerscience, webdev, programming
Published: 2021-01-11 00:21:16

JavaScript is a single threaded language.

That means that JS only does one thing at a time. This is key to understanding how it works. 

JS has what's called an event loop. It is a one dimensional array of jobs to be done. When you execute a JS program it pops in an event to the queue, and executes it in First In First Out order. It does so sequentially and goes from the top of the program to the bottom. It will pop in whatever is at line 1 to the queue, then line 2, then line 3 and so on. It will execute those instructions in that order.

So writing this:
```javascript
let a = 0;
let b = a + 10;

a = b; //a == 10 as expected.
```
It will (and has to in order for the program to work) execute  from top to bottom. It will not declare the variable `b` until variable `a` is declared, and will not reassign variable `a` until `b` has been declared. This makes sense to us because we also think sequentially. 

This is nice, but sometimes we want JavaScript to do something while we wait for something else. For example, if you set a timeout with the setTimeout function.

```javascript
let a = 0;
let b

setTimeout(() => {
    b = a + 10
}, 0) //Setting a timeout of 0?

a = b; //here a == undefined??...
```

Now look at that example and think about it. Why does setting a timeout of 0 not do the thing that we expect it to do? If we set a timeout with no wait, we expect it to happen right away, why doesn't it??

There is a simple answer to this and it is in the event loop. Javascript does thing in the order of first in first out, remember? 

When it comes time for actually executing the calls in the order this happens:
```
    declare "a" equal to 0
    declare "b" equal to undefined

    set a timeout of 0

    declare "a" equal to the value of "b" (which is undefined)

    check if timeout is done

    now that the timeout is done, add the anonymous function that was passed inside setTimeout to the queue.
    assign to "b" the value of "a" + 10
```

So if we look at the above, we see that setTimeout is not blocking the rest of the program to be added to the queue. Doing things asynchronously allow for larger timeouts to happen in the background without holding up the rest of the code from executing. If the timeout would have been longer, the output would have been no different. The timeout is waiting for the timer to be done to add the item to the bottom of the queue, but not before it adds the rest of the program to the queue. 

Understanding the interworkings of JS like these allows you to write more deliberate code, and makes it so the way that you make programs are more readable and take advantage of the way that the language was designed to your favor. Without it, programming JavaScript is more like the tail wagging the dog.

Hope this helps you if you are having trouble understanding async code, stay tuned for more.
How to start PgSQL (Postgres) server
Published: 2021-01-11 00:19:26

Try directly using: 

`sudo /etc/init.d/postgresql start`

otherwise try:

`pgrep -u postgres -fa -- -D`

More info: 
**How to start Postgres**
There again are several ways to start Postgres. If you’re running a Debian-based distribution, you should find the perl wrappers pretty handy.

For Debian or Debian-based (including Ubuntu) Linux distributions
First, issue pg_lsclusters to find out your cluster name:

`pg_lsclusters`

`Ver Cluster Port Status Owner    Data directory              Log file
12  main    5432 online postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log`

To start that particular cluster, you just need to issue:

`pg_ctlcluster <Version> <Name> start`

So, in our example, it will be:

`pg_ctlcluster 12 main start`

if that gives an error, use:

`sudo /etc/init.d/postgresql start`

You may need to then run:
`
  584  rake db:drop
  586  rake db:create
  587  rake db:migrate
  588  rake db:seed`
Definition of Done
Tags: agile, dod, definitionofdone
Published: 2021-01-11 00:16:47

---
title: Definition of Done
published: true
description: Along with the Definition of Ready, the Definition of Done is one of the fundamental states defined within the Agile software development life cycle. The definition explicitly identifies a User Story “done state”.
tags: agile, dod, definitionofdone
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/306le6wb491opa8ububi.jpg
---


Along with the [Definition of Ready](https://dev.to/dev3l/definition-of-ready--1jfb), the **Definition of Done** is one of the fundamental states defined within the Agile software development life cycle. The **Definition of Done** is the soul of the entire Scrum process. The definition explicitly identifies a User Story "done state”.


The **Definition of Done** defines a common terminology to be used between all members (internal and external) of the team. Once defined, no one ever has to ask if something is "DONE-done" ever again!

# Definition

The team agrees on, and displays prominently somewhere in the team room, a list of criteria that must be met before a product increment "often a user story" is considered "done". Failure to meet these criteria at the end of a sprint normally implies that the work should not be counted toward that sprint's velocity.

# Benefits

- **Provides Explicit Accountability**
  - Every user story moved into the "Done" category meets a minimum agreed-upon standard of completion
- **Creates an Overwhelming Sense of Clarity and Power**
- **Prevents User Story Thrashing**
- **Limits the Risk of Misunderstanding and Conflict**
  - Between the development team, quality assurance, and the product owner
- **Guides Pre-Implementation Activities**
  - Discussion, estimation, design

# Reference

Here is a solid article that has a great formal definition from the Agile Alliance on the [Definition of Done](https://www.agilealliance.org/glossary/definition-of-done/)

# Example Checklist:

- **Code Updated** to satisfy all requirements and acceptance criteria
- **Code Properly Formatted** and follows applicable standards
  - Code self-documented
- **Code Review Performed**
- **Exit Three Amigos Completed**
- **Unit, Integration, and Acceptance Tests Added/Updated**
  - Pass successfully
  - Provide adequate code coverage
- **Documentation Created** (Architectural / Design ) and made available as appropriate
- **Performance** concerns have been identified, analyzed, and addressed
- **Security** concerns have been identified, analyzed, and addressed
- **Metrics** have been identified and addressed
- **Code Accepted** by QA
- **User Story Status Updated**
  - Set to "Done"
LHD: Build Day 1
Tags: mlh, majorleaguehacking, localhackday
Published: 2021-01-11 00:10:38

So far, I've introduced myself to #introduce yourself and my guild, followed MLH on twitter, checked in, and attended a live session. I made my own person portfolio website using Github. See: [https://brookthebook.github.io/](brookthebook.github.io)

If you want to join a guild you can join Developer Student Community. They're a great guild. If I have any questions I know I can ask them and get answers.

Local Hack Day: Build is a great way to meet new people, learn to hack, or just have fun!
Seed Generator
Tags: dohackathon
Published: 2021-01-10 22:43:49

---
title: Seed Generator
published: true
description: My submission to the DigitalOcean App Platform Hackathon!
tags: dohackathon
---

## What I built

This is a program that will generate (random) csv data that can be used to populate databases!

### Category Submission: 

Program for the People

### App Link

https://seed-gen-ubod9.ondigitalocean.app/

### Screenshots

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


### Description

This program allows you to generate randomized data, customized to your preference (to a certain extend). 

### Link to Source Code

https://github.com/lucidkodo/seed-gen

### Permissive License

MIT

## Background

Whenever i build something, the database is always empty and it can be time-consuming to come up with random bits of data just to populate and run tests!

### How I built it 

DO's app platform is very well documented and by following thru the documents, i managed to get things working as expected! However, i did hit a bug when i was in the inital state of tinkering, when pushing to main branch did not trigger any app builds. I tried manual deployment, it did not work. I ended up creating a fresh repo and fresh app, and all is good.


### Additional Resources/Info 

The pre-generated pools of data are as listed in the repo README file.
How to undo or abort a Git rebase process?
Tags: git
Published: 2021-01-11 00:00:00

---
  title: How to undo or abort a Git rebase process?
  published: true
  tags: Git
  date: Mon Jan 11 2021 05:30:00 GMT+0530 (India Standard Time)
  canonical_url: https://melvingeorge.me/blog/abort-undo-rebase-process-in-git
  cover_image: https://melvingeorge.me/_next/static/images/main-d2f0ddb2c97cb87b634accfb1269ca7f.jpg
  ---
  [Originally posted here!](https://melvingeorge.me/blog/abort-undo-rebase-process-in-git)
  
Sometimes during a Git rebase process, you may encounter some merge conflicts and Git asks you to resolve the conflicts to move forward with the rebasing.

There is also an option to completely abort or undo this rebase process, which doesn't mean it will remove the conflicts but will help you to undo a fully rebased branch to its original state before the rebase or abort the rebase process so that you can continue with it later onwards.

You can do this by passing an `--abort` flag to the `git rebase` command during the rebase process like this,

```bash
git rebase --abort
```

This aborts the whole rebase process.

### Feel free to share if you found this useful 😃.

---
Portfolio Site
Tags: dohackathon
Published: 2021-01-10 23:47:02

## What I built
A personal dev portfolio site.

### Category Submission: 
Portfolio Site

### App Link
https://portfolio-site-3-yaxja.ondigitalocean.app/
https://tawil.dev/

### Screenshots
![Screen Shot 2021-01-10 at 6.44.59 PM](https://dev-to-uploads.s3.amazonaws.com/i/eoqdh0yoi062s5xu33q1.png)
 

### Description
React based and utilized React-PDF.

### Link to Source Code
https://github.com/Jackmt9/portfolio_site

### Permissive License
MIT License

## Background
(What made you decide to build this particular app? What inspired you?)
I needed a portfolio site to apply to jobs and this hackathon pushed me to get it done in a timely fashion.

### How I built it 
(How did you utilize DigitalOcean’s App Platform? Did you learn something new along the way? Pick up a new skill?)
I deployed via DigitalOcean and learned how to purchase a domain and upload.

### Additional Resources/Info
Array: Swiss-army-knife of Python sequences
Tags: showdev, python, functional, github
Published: 2021-01-10 23:07:31

[github](https://github.com/lauriat/funct) & [pypi](https://pypi.org/project/Funct) & [docs](https://lauriat.github.io/funct/Array.html) & [HN](https://news.ycombinator.com/item?id=25713915)

I released a package that extends the functionality of the Python built-in list - maybe others will find it useful. I often found myself writing the same code snippets for manipulating lists (e.g. flattening, grouping, and element-wise operations) and figured I might as well make a library that contains all the essentials. Many of the methods are wrappers for built-ins, but I find the syntax of Arrays cleaner than the weirdness of the builtins and you won't be needing to google for the 100th time whether reduce is in the itertools or functools module.
Array provides
- basic mathematical operations (add, mul, eq, etc.)
- chainable functional methods (map, filter, reduce, etc.)
- basic “numpy” methods (clip, argsort, split, linspace, etc.)
- parallel execution (parmap, asyncmap, etc.)
- multidimensional indexing
- list built-ins
- & more

Cheers!
Road to Genius - Python Series level 1
Tags: beginners, python, codenewbie, computerscience
Published: 2021-01-10 23:02:43

In this post I will solve and explain several Python code challenges from Codr's Ranked mode. The goal is to reach the Genius level, so join me at [Codr](https://nevolin.be/codr/)!

Instead of posting one challenge per day, I will instead post several in one.

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

The first code asks us to fix a bug, which should be a number such that the answer `R = 30`. The answer is pretty simple, the `people` variable is a list of objects with name and age. The bug is Ana's age, with the if-condition below requires Ana's age, since R should be 30, we know that 30 is her age.

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

---

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

Here we have two bugs, the first one is R's value, and if you look at the code you see that R is being used as a boolean. Since R should eventually be False, then R should be initialized as False, unless the if-condition is true, which it shouldn't as long as the rocket isn't equal to 3.

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

---

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

The same algorithm as before, this time the first bug should be the arr variable. The second bug's value doesn't matter because the if-condition won't execute anyway.

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

---

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

A very simple one right here. We need to fix the operator on the second line, which is highly like to be an assignment `=`.

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

---

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

A slightly more complicated algorithm here. We need to fix a bug in the function nonzero as well as one of its inputs. The first bug is a variable name which should be `j`, since it is used below and should be declared.

To fix the red apple, we need to figure out what the algo does. So given an input list of 4 numbers and `i=3`, it should return 4. Here's some pseudo code of that function:
```
j = i+1 = 3+1 = 4
while(j < 4 and ...)  --> j is not less than 4, so we can skip the while loop
return j (=4)
```
The values inside the input array are irrelevant because the while-loop isn't executed, so the red apple can by anything.

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

---

As easy as that, we made it to the 2nd "Smart" level. If you enjoyed this post, make sure to join [Codr](https://nevolin.be/codr/), like and follow <3!
dev.to をどのように使えば良いか
Published: 2021-01-10 23:01:13

YouTube に上がっている [dev.to(gether) - The State of the Web](https://www.youtube.com/watch?v=ptJAlOSewW8) を視聴すると、少しアイディアが広がるかもしれない。

dev.to をどのように使えばよいか、という話と、私がそもそも何をしたいかという話を切り分けて考える必要がある。
Midas Pizza - DigitalOcean App Platform Hackathon
Tags: dohackathon, buildforbusiness, hackathon, digitalocean
Published: 2021-01-10 22:57:45

## 🍕 What I built
I built a pizza delivery application called Midas pizza. It's a simple application that allows users to sign up and order pizza... mhnnnnn🤤

### 👨🏾‍💼 Category Submission: 
This application was built for business....get it...because it's under the **built for business** category....no?...ok.

### 🔗 App Link
https://midas-pizza-y9r6m.ondigitalocean.app/

### 📸 Screenshots
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/v2g47k38yluxnj30po38.png)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/g193pzyemfd2qcapbq23.png)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/23ktx6dukc977bvb9j3b.png)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1tgt2d8ehtlqz6vx3oci.png)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mt5soy53r2tmml36z1zs.png)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/asyre2r8vaxtqbkq4pwn.png)

### 📖 Description
A JAMstack pizza delivery application. Made with React which consumes a node API (also made by me) to give you ~~fake~~ digitally appetizing food.

### 👩🏾‍💻 Link to Source Code
https://github.com/OlaoluwaM/midas-pizza

### 📜 Permissive License
MIT

## Background
Well, if you haven't already guessed, I love pizza. That's it that's the story....😂. I built this app because it was a creative spin on an e-commerce application. Building Midas taught me a lot about the kinds of things that really need to be considered before putting out these kinds of applications, such as, making sure the prices are always correctly displayed, preferring to use totals from the server rather than the client when making any form of payment to avoid certain bad actors, and reconfirming the user's action through helpful prompts and micro-interactions. Also, wouldn't it be nice if dominos had UI and UX like this, just saying👀

### How I built it 
I connected my GitHub account to Digital Ocean. That way it was a smooth transition to building the application using Digital Ocean's App platform. The frontend was written in React, animations with framer-motion and global state management with recoil. The backend was done in Nodejs. Code was written in VSCode and hosted on Github
Lets Read | Digital Ocean Hackathon Submission
Tags: dohackathon
Published: 2021-01-10 22:36:40

## What I built
I decided to build a web app for parents to help their small children learn how to read. Since being in quarantine I have decided to teach my own children to read and I thought this would be helpful for other parents. 

{% youtube YyxeaeXLHww %}

### Category Submission: 
Program for the people

### App Link
https://lets-read-2sufe.ondigitalocean.app/lessons.html

The app is mostly designed for mobile therefore I suggest to use it on your phone but it is also desktop friendly. 

### Screenshots

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

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

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

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


### Description
Lets Read is a webapp that helps parents or guardians interact with their small children and help them learn how to read. It includes letters, letter blends, cvc (consonant vowl consonant) words, and sight words. 

With the parents help to pronounce the letters, blends and words the child can learn by imitating. Children learn by imitating what their parents and people around them do therefore this webapp can be very helpful in teaching small children the basics of reading. 

### Link to Source Code
https://github.com/BrendaMichellle/letsRead/tree/main

### Permissive License
MIT

## Background
Since being in quarantine due to covid I have found it is very difficult to entertain my small children especially when we can't really go outside. During these difficult times I decided to start teaching my children to read. I looked for books, lessons and online resources and a lot of them were not very accessible or very expensive. 

I built this web app based on the information I encountered. I still have more plans and features I want to add. I am still learning therefore I hope to add more as I learn more. 

### How I built it 
I used HTML, css and javascript as well as the Digital Ocean App Platform. 

I really liked how it is extremely easy to deploy with Digital Ocean. All you have to do is click a button, choose the github repo and you're live in a few minutes. 

I also really like the fact that any changes made to the main branch get instantly updated on the live version. 


### Additional Resources/Info
If anyone has any recommendations or suggestions for the web app I would be very glad to hear them. Thank you in advance.