teleren/devto huggingface dataset:
สร้าง TCP Client และ Server ง่าย ๆ ด้วย Ruby
Tags: ruby, networking
Published: 2020-01-08 15:40:34

[TCP](https://en.wikipedia.org/wiki/Transmission_Control_Protocol) เป็น protocol ที่ช่วยให้เราเขียนโปรแกรมให้ติดต่อสื่อสารกันผ่านระบบ network ได้ และวันนี้จะพามาดูวิธีเขียน Ruby เพื่อสร้างโปรแกรมเป็น TCP Server และ TCP Client ซึ่ง Ruby มี library socket ที่เตรียม class ไว้ให้แล้ว ทำให้สร้างได้ง่ายมาก ๆ

## สร้าง TCP Server

เราจะใช้ class [TCPServer](https://ruby-doc.org/stdlib-2.7.0/libdoc/socket/rdoc/TCPServer.html) ซึ่งตัวอย่างโค้ดจะเป็นโค้ดที่เอาไว้เปิด TCP socket ไว้รับการ connect จาก client

```ruby
require 'socket'

server = TCPServer.new 2000
loop do
  Thread.start(server.accept) do |client|
    client.puts "Hello !"
    client.puts "Time is #{Time.now}"
    client.close
  end
end
```

จะเห็นว่าเราต้อง `require 'socket'` เข้ามาก่อน จากนั้นจะสร้าง TCPServer object โดยระบุ port ที่ต้องการเปิดไว้ว่าเป็น port 2000

เมื่อได้ server object แล้วเราก็จัดการเรียก method `server.accept` เพื่อรอรับการ connect จาก client เราจะได้ client object กลับมา และเราใช้ Thread.start ครอบเอาไว้เพื่อว่าเมื่อ client connect มาแล้วเราจะแยกไปทำงานอีก thread ทำให้เราสามารถ connect หลาย ๆ client ได้พร้อมกัน

ส่วนโค้ดที่ทำงานให้แต่ละ thread นั้นเมื่อเรามี client object เราก็สามารถใช้ method puts เพื่อส่งข้อมูลไปหา client ได้ และเรียก close เพื่อปิด connection ของ client นี้

## สร้าง TCP Client

เราจะใช้ class [TCPSocket](https://ruby-doc.org/stdlib-2.7.0/libdoc/socket/rdoc/TCPSocket.html) ซึ่งตัวอย่างโค้ดจะเป็นการ connect ไปหา server แล้วใช้ method gets เพื่ออ่านข้อมูลจาก server ที่ส่งมา

```ruby
require 'socket'

s = TCPSocket.new 'localhost', 2000

while line = s.gets # Read lines from socket
  puts line         # and print them
end

s.close             # close socket when done
```

เมื่อรัน server ก่อน แล้วทดลองรัน client ก็จะได้ผลลัพธ์ประมาณนี้

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/2y9r9l6bxofe95dub802.png)
What is TypeScript Part one?
Tags: beginners, typescript, javascript
Published: 2020-01-08 15:27:27

If you have been learning JavaScript, chances are that you have heard of TypeScript. 

TypeScript is a superset of JavaScript that is open-sourced and developed by Microsoft. It has to be compiled into vanilla JavaScript and it is less error prone. 

It is intended to be scaled and used on large projects. 

TypeScript is statically typed but that is an option. However, it is 
recommended that you specify the type. JavaScript is dynamically 
typed.


Here is an example of JavaScript's dynamic typing and TypeScripts optional Static typing. Below is an example of JavaScript

```javascript
let goat = "Michael Jordan"
let retired = true
let championships = 6
```

The same variables would look like this in TypeScript

```typescript 
let goat: string = "Michael Jordan"
let retired: boolean = true
let championships: number = 6
```

In JavaScript, I could do this.

```javascript
championships = "six"

```

However, this would not work in Typescript because we already assigned a data type to championship. The championship variable will only accept numbers.

This also can be used to set the return type for a function

```typescript
const add = (num1: number, num2: number): number => {
  return num1 + num2;
}
```

By statically setting the type, we can reduce the potential for bugs in the future and this is a huge advantage over Javascript. 

I have included a link from my github account for the TypeScript project from this course <a href="https://www.udemy.com/share/1013yQAkAScF1XQHw=/">Learn TypeScript - 2020 Edition</a> taught by Maximilian Schwarzmüller. 
{% github AweysAhmed/typescript-project %}

I highly recommend the course if you are looking to learn TypeScript. 

In part two of the blog post, I will cover the topic of Interfaces.
What are your thoughts on 'Silent Installations'?
Tags: discuss
Published: 2020-01-08 15:26:04

---
title: What are your thoughts on 'Silent Installations'?
published: true
description: Are "Silent Installations" still a thing?
tags: discuss
---

Recently a coworker asked me about my thoughts on "silent installations" and all I could think about was keyloggers, spyware, and other things that could show up installed on my computer unannounced. Hard pass.

His idea was service providers may want silent installations so users just get the software they need without being bothered.

Even installing at scale across multiple server nodes, I could see two paths: easy scriptable installs with a config file, something I could work with in a terminal or provide the software in a package manager (like Brew, for instance) that I can still script my way to the install. I'd want to be able to configure the install for my given setup, whether I'm installing this on my personal machine or on a server.

Am I missing something? Is the definition for "silent installations" broader than I've described it? What are your thoughts? Are you packaging your software this way?
tbas, a tiny cross-platform basic interpreter
Tags: basic, legacy, learning
Published: 2020-01-08 15:17:43

I started programming in 1977, back then processor speeds and memory sizes were considerably less than what we have now. I learned how to achieve much with little, and from time to time I deliberately return to that time by using resource-limited tools.

For example, there's a family of programming languages called [BASIC](https://en.wikipedia.org/wiki/BASIC) and I've been helping out on a project called [tbas](https://digilander.libero.it/tonibinhome/tbas/index.html) developed by an Italian programmer, [Antonio Maschio](https://digilander.libero.it/tonibinhome/). 

tbas is based on Antonio's earlier [decb](https://digilander.libero.it/tonibinhome/vibes_project) which is an implementation of [DEC BASIC](https://en.wikipedia.org/wiki/HP_BASIC_for_OpenVMS#VAX_BASIC_and_DEC_BASIC). 

Antonio is actively developing tbas, and we're currently up to Beta7 in-house. We've got it running under Linux, the Windows Subsystem for Linux (WSL), Cygwin (32bit) and Cygwin64. It should compile for MacOS. Source is available along with comprehensive documentation.

tbas has a number of quirky limitations which provide interesting opportunities to think outside the box. Strings, for example, are a maximum of 255 characters long! There are some intriguing ideas too, like CHANGE.

I enjoy stepping back in time with tbas. It helps maintain a sense of perspective, especially when C# and JavaScript are being for some reason recalcitrant. Want a NUnit or xUnit tool? Roll your own. Want command line parsing tools? Roll your own. Want database tools? You get the idea.
Reading Snippets [27 => Git]
Tags: git, beginners
Published: 2020-01-08 15:02:13

Git has three main states that files can reside in:


 💻 Modified- You have changed the file but have not committed it to your database yet. 

 💻 Staged- You have marked a modified file in its current version to go into your next commit snapshot. 

 💻 Committed- Data is stored in your local database


<hr>

The three main sections of a Git project include:

 🌲 Working Tree- A single checkout of one version of the project, pulled out of the database in Git directory for use. 

 🎭 Staging Area- Located in Git directory. It stores information about what will go into your next commit. 

 🎥 Git directory- Where metadata and object database of the project are stored. 

<kbd>Source:<a href="https://git-scm.com/book/en/v2/Getting-Started-What-is-Git%3F"><i>Git</i></a></kbd>
A letter to my future anxious self
Tags: career, anxiety, health, life
Published: 2020-01-08 14:59:55

## Dear future me,

You could be doing and learning much more.
You could be earning more money and progressing in your career.
You could impact the world a bit further.
Yes, you could do A, B, ... XYZ.

The only thing I ask of you is to breathe deeply and think critically if whether these goals are set consciously by you or if they're imposed by society's expectations.

Remember that comparing yourself to others is a sure way to get the wrong idea and brew anxiety. These high achievers you're so keen on using as inspiration don't have the same trajectory as you, making it impossible to follow their exact path, which is actually a blessing, not a curse.

**You have the privilege of being able to define your own path according to your values and beliefs, so please use it for good!**

Yours truly, post-anxiety crisis you.

------

## **For context:**

I almost didn't sleep last night, ruminating on how much I've been lacking as a professional lately. As of late, my body and mind have been lazy and tired, and focusing enough to learn a new topic or solving hard problems has been impossible. Then, after a day-long failed attempt of creating a cache strategy for my CI pipelines, I had the brilliant idea of scroll through a Twitter feed full of "2019 in review" posts, in which people were sharing their amazing year of crazy growth.

This text is just a way of reassuring myself that my path is valid and that respecting the body and mind's state is important. Else we fall victim to the demands of our capitalist society that wants to **squeeze every little drop of our energy in favor of production**, which in our software world means learning everything and regularly building tons of projects and products.

In the end, pushing your boundaries might not be so sustainable and end up hurting your productivity. I'll leave you with [Justin Jackson's](https://twitter.com/mijustin) quote, which can easily be applied to any career:

<blockquote class="twitter-tweet" data-dnt="true"><p lang="en" dir="ltr">Good businesses have margin.<br><br>Profit margin, yes.<br><br>But also margin for your time, your emotional and physical health, your relationships, your sanity, and your integrity.<br><br>Low-margin work eventually leads to ruin. The margins rarely get better; the sunk costs get worse.</p>&mdash; Justin Jackson (@mijustin) <a href="https://twitter.com/mijustin/status/1214391547925450752?ref_src=twsrc%5Etfw">January 7, 2020</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

I know many of you suffer from this dilemma, what's your take on this?
Reading Snippets [26 => Git]
Tags: git, beginners
Published: 2020-01-08 14:27:34

The major difference between Git and other version control systems is in the way Git thinks about its data. 


Other systems think of information that they store as a set of files and changes made to each file over time (delta-based version control). Git thinks about its data as a stream of snapshots.

<kbd>Source: <a href="https://git-scm.com/book/en/v2/Getting-Started-What-is-Git%3F"><i>Git</i></a></kbd>
หัด Erlang and Elixir v0.3.0 - atom
Tags: erlang, elixir
Published: 2020-01-08 14:26:17

atom ใน Erlang ขึ้นด้วยด้วยอักษรตัวเล็ก หรือใช้ `'` ครอบ text เอา

```erlang
6> centimeter.
centimeter
7> 'Centimeter'.
'Centimeter'
8> 'Centi meter'.
'Centi meter'
```

ส่วนของ Elixir ใช้ `:` นำหน้าหรือขึ้นต้นด้วยตัวอักษรตัวใหญ่ ถ้าอยากจะใช้ `'` แบบ Erlang ให้เติม `:` เข้าไป

```elixir
iex(1)> :centimeter
:centimeter
iex(2)> :'Centimeter'
:Centimeter
iex(3)> :'Centi meter'
:"Centi meter"
iex(13)> This_is_greeting
This_is_greeting
```

ทั้งสองภาษามี function `is_atom` เพื่อเอาไว้ตรวจสอบว่า value นั้นเป็น atom หรือไม่ 

```erlang
9> is_atom(centimeter).
true
10> is_atom('Centimeter').
true
11> is_atom('Centi meter').
true
```

```elixir
iex(4)> is_atom(:centimeter)
true
iex(5)> is_atom(:'Centimeter')
true
iex(6)> is_atom(:'Centi meter')
true
iex(15)> is_atom(This_is_greeting)
true
```

boolean ของทั้งสองภาษาก็เป็น atom เช่นเดียวกัน

```erlang
12> is_atom(true).
true
13> is_atom(false).
true
```

```elixir
iex(7)> is_atom(true)
true
iex(8)> is_atom(false)
true
```

NOTE: ที่เราเห็น true/false ใน Elixir ใน atom นั้นสาเหตุเพราะ compiler จะแปลง true/false ให้กลายเป็น `:true` กับ `:false` ที่เราใช้ตัวอักษรตัวใหญ่เคสนั้นก็น่าจะทำนองเดียวกัน

Module ใน Elixir และ Erlang เองก็เป็น atom เหมือนกันนะ

```erlang
14> is_atom(lists). %% module lists
true
```

```elixir
iex(1)> is_atom(List) ## module List
true
```

NOTE: ในเคสของ Elixir จะแปลงไปเป็น `:'Elixir.List` ให้เองโดย compiler
Best practice for syncing todo list with server

Tags: devops
Published: 2020-01-08 14:17:40

Hello everyone,,
I am building a sample todo list using flutter. Currently when a check box is checked, I am making a backend call to the server to update the state and then upon successful response, I am updating the local state. The issue here is, when the server response is slow, from the UI perspective, when a checkbox is checked, nothing happens for few seconds and then gets checked. Ideally, I would like to update the UI first and then make a call to backend. But then with this approach, I have to deal with unchecking the box again if the call to server is unsuccessful or retry again after sometime. I am actually looking for patterns for variant of a second approach. i.e. When a checkbox is checked, the UI state updates and is stored locally. Then in an asynchronous manner, update the server. Are there some patterns in flutter community to achieve this? https://showbox.bio/  https://tutuapp.uno/  https://vidmate.vet/

PS: I am using Redux & Redux thunk to talk with my backend..
Day 3: From string to math
Tags: challenge, kotlin, learning
Published: 2020-01-08 14:13:30

## Details

- Difficulty: Hard
- Programming language: Kotlin

## Problem

Giving a string consisting of parentheses, single digits, positive and negative signs,
convert the string into a mathematical expression to obtain the answer.

Don't use ``eval`` or a similar built-in parser.

For example:
   - Given `-1+(2+3)`, you should return `4`

## Solution

Before looking at my solution, which is probably not the best, why don't you give it a try? :grin:


I decide to simply use a simple switch case (when in Kotlin) 


```kotlin
/**
 * Parse and calculate the string passed in param
 *
 * @param calculation
 * @return result of the calculation
 */
fun parseAndCalculation(calculation: String): Int {
    var result = 0

    var multiplier = 1
    var subProblem = -1

    for ((index, c) in calculation.withIndex()) {
        if(subProblem == -1 || c != ')')
            when(c) {
                '+' -> multiplier = 1
                '-' -> multiplier = -1
                '(' -> subProblem = index
                ')' -> {
                    result += multiplier * parseAndCalcul(calculation.substring(subProblem + 1, index))
                    subProblem = -1
                }
                else -> result += multiplier * c.toString().toInt()
            }
    }

    return result
}
```
BlurBG - playing with blurry images in CSS and HTML
Tags: codepen, html, css, javascript
Published: 2020-01-08 14:13:06

<p>A little play with the css filter property and some positioning to display a blurry background image.</p>

<p>We're also grabbing the image URL with Javascript and applying it to the article header so that our template would only have to include the featured image one time - this could then be set through your CMS of choice.</p>

{% codepen https://codepen.io/abeeken/pen/MWYQZwV %}
หัด Erlang and Elixir v0.2.0 - variable
Tags: erlang, elixir
Published: 2020-01-08 14:03:23

การสร้างตัวแปรใน Erlang นั้นจะใช้ชื่อตัวแปรขึ้นต้นด้วยตัวอักษรตัวใหญ่

```erlang
1> Greeting = "hello".
"hello"
2> Greeting.
"hello"
```

ใน Erlang นั้นจำเป็นต้องใช้ `.` เป็นตัว end statement เสมอ และ assign ให้ตัวแปรเดิมทับไม่ได้

```erlang
3> Greeting = "new hello".
** exception error: no match of right hand side value "new hello"
```

NOTE: ใน Erlang shell เราสามารถทำยกเลิก variable binding ได้ด้วยการใช้ function f(<Var>) เช่น

```erlang
4> f(Greeting).
ok
5> Greeting = "new hello".
"new hello"
```

ส่วนของ Elixir นั้นใช้ขึ้นด้วยตัวเล็ก

```elixir
iex(1)> greeting = "hello"
"hello"
iex(2)> greeting
"hello"
```

แถมต่างกับ Erlang ตรง assign ทับได้

```elixir
iex(3)> greeting = "new hello"
"new hello"
iex(4)> greeting
"new hello"
```

แต่ถ้าอยากไม่ให้ re-assign ค่าใหม่ที่ไม่ใช่ค่าเดิมได้ จะต้องใช้ `^` นำหน้าตัวแปร Elixir จะทำการ match value ระหว่างสองข้างให้ 

```elixir
iex(5)> ^greeting = "hello"
** (MatchError) no match of right hand side value: "hello"
    (stdlib) erl_eval.erl:453: :erl_eval.expr/5
    (iex) lib/iex/evaluator.ex:257: IEx.Evaluator.handle_eval/5
    (iex) lib/iex/evaluator.ex:237: IEx.Evaluator.do_eval/3
    (iex) lib/iex/evaluator.ex:215: IEx.Evaluator.eval/3
    (iex) lib/iex/evaluator.ex:103: IEx.Evaluator.loop/1
    (iex) lib/iex/evaluator.ex:27: IEx.Evaluator.init/4
iex(5)> ^greeting = "new hello" # สามารถ assign ได้เพราะค่าทางด้านขวาเป็นค่าเดียวกับด้านซ้าย
"new hello"
```
Big O Notation BIG ITS BIG
Tags: 100daysofcode
Published: 2020-01-08 14:01:08

# Algorithms and Data Structures

When I've started to learn this stuff, the weather was sunny and schools didn't start.
I still can't know If I know anything at all.

![Chart](https://cooervo.github.io/Algorithms-DataStructures-BigONotation/images/graphs/comparison.svg)

[![View on vgy.me](https://i.vgy.me/XM9SMf.png "View XM9SMf.png on vgy.me")](https://vgy.me/u/XM9SMf)

Some Sources
* [hackr](https://hackr.io/tutorials/learn-data-structures-algorithms?sort=upvotes&type_tags%5B%5D=1&languages%5B%5D=en)
* [learnxinyminutes](https://learnxinyminutes.com/docs/asymptotic-notation/)
* [khanacademy] (https://www.khanacademy.org/computing/computer-science/algorithms/asymptotic-notation/a/asymptotic-notation)

day15
Things to do in 2020
Tags: javascriptbootcamp, barcelonacodeschool, fullstackbootcamp, wourdpresscourseinbarcelona
Published: 2020-01-08 13:36:15

---
title: 'Things to do in 2020'
published: true
description: "Start strong in 2020 with our new courses in Barcelona Code School"
tags: "javascript bootcamp, barcelonacodeschool, full-stack bootcamp, wourdpress course in barcelona"
---

Hi from 2020!
 
New dates on the block:

<img src="https://gallery.mailchimp.com/1ea2b8f22493f512dc7644468/images/11f77c62-4043-4475-83eb-169c451dd70e.png" class='fullwidth banners' alt='JavaScript Bootcamp at Barcelona Code School'>

JavaScript Full-Stack Bootcamp 

Upcoming starting dates: January 07, February 10, March 09, April 13.

<a href='https://barcelonacodeschool.com/barcelona-code-school/javascript-full-stack-bootcamp/'>Go this way</a>.

Or do <a href='https://barcelonacodeschool.com/barcelona-code-school/javascript-full-stack-online-bootcamp/'>the online version</a> with the same curriculum and outcomes from any location you are in 🤷‍♀️

+++

<img src="https://barcelonacodeschool.com/static/online_bootcamp_vr-292b7798069a95c16c6ea848d961cba7.jpg" class='fullwidth banners' alt='JavaScript Full-Stack Online Mentored Bootcamp at Barcelona Code School'>

JavaScript Full-Stack _Mentored_Online_ Bootcamp 

Upcoming starting dates: January 06, January 20, February 03, February 17, March 02, Mark 16, March 30.

<a href ='https://barcelonacodeschool.com/barcelona-code-school/javascript-full-stack-online-bootcamp/'>Go this way</a>.

+++

<img src="https://barcelonacodeschool.com/static/be_a_devstar-6ed7dbc9e3aa4efad436d0e0ef045686.jpg" class='fullwidth banners' alt='Programming with JavaScript course at Barcelona Code School'>

Programming with JavaScript

Starts on <a href='https://barcelonacodeschool.com/programming-with-javascript/'>January 13, March 16, April 20</a>.

+++

<img src="https://barcelonacodeschool.com/static/responsive_web_design_with_css3_barcelona_code_school-28958f08c2a6c0bab1cae57755add173.png" class='fullwidth banners' alt='Responsive Web Design with CSS3 course at Barcelona Code School'>

Responsive Web Design with CSS3

<a href='https://barcelonacodeschool.com/responsive-web-design-with-css3/'>January 06, February 10, March 09, April 13</a>.

+++

<img src="https://barcelonacodeschool.com/static/wordpress-bicycle-69b89dfb967812ee9339c30fbc4f04c2.jpg" class='fullwidth banners' alt='Ultimate WordPress 3-day workshop at Barcelona Code School'>

Ultimate WordPress 3-day workshop

<a href='https://barcelonacodeschool.com/barcelona-code-school/wordpress-courses-in-barcelona-code-school/'>January 21</a>.

+++

See you soon!

<p>All the best, George</p>
Form validation with ControlValueAccessor
Published: 2020-01-08 13:29:55

If we have UI components, that are using inputs, we normally want to hook it into the form handling so we can do form validation and show error messages. This post will show you how to use ControlValueAccessor to integrate your UI components into the form validation and how to control the error state in an Angular material input using ErrorStateMatcher.

Read more [here](https://christianlydemann.com/form-validation-with-controlvalueaccessor/)
Does your app need a privacy policy?
Tags: privacy, swift, ios, productivity
Published: 2020-01-08 12:57:10

Generate it directly from your app’s code and earn a $5 Amazon gift card.

We are computer science researchers at Wesleyan University. We developed PrivacyFlash Pro, an automatic generator that produces a privacy policy for your iOS app written in Swift. PrivacyFlash Pro is [available on GitHub](https://github.com/privacy-tech-lab/privacyflash-pro). We are excited to hear what you think!

If you are an iOS developer, you may also be eligible to participate in our usability study and earn a $5 Amazon gift card. Learn more at our [study site](https://forms.gle/r8SHNYQJRqX5rSR47).

{% github privacy-tech-lab/privacyflash-pro %}
I am looking for drag and drop page builder resources for react application 
Tags: react, javascript, node
Published: 2020-01-08 12:38:33

---
title:I am looking for drag and drop page builder resources for react application 
published: true
description: I am looking for drag and drop page builder resources for react application that will be implemented invoice, email and so on . can anyone recommend resources?Thanks in advance.

tags: reactjs,javascript,nodejs
---
Teaching myself Julia
Tags: julia, learning, youtube
Published: 2020-01-07 07:04:40

---
title: Teaching myself Julia
published: true
description: An account of my 4.5 hour blitz session to teach myself the Julia language while trying to teach others how to learn a new language.
tags: Julia, learning, YouTube
---

I recently took it upon myself to record myself learning Julia for the first time (an edited down version of that can be found [here](https://youtu.be/TNoShNPoEak)) to demonstrate to others how to learn a new language. It was a really cool experience and I got to satisfy my curiosity about this new contender for the Python throne.

The game plan was:
- Learn Basic Syntax
- Lists, dicts, tuples
- Control flow, functions, structs
- Notebooks and visualization
- Package management
- Reimplement a simulation from my Numba video and compare performance

The first half of this I could meet by going over the "Learn X in Y" page for Julia. The rest came from the official docs which are really nicely put together.

Overall I came away mostly impressed by Julia. There's some rough edges in the tooling still and some syntax and design choices are hard to stomach (1 based indexing guys? Really?) but these are mostly minor. I've gotten a number of very insightful comments on the video too about ways the language allows you to overcome these issues if you wanted to. I was particularly delighted by the package management. It seems to take in the best parts of pip, npm, and cargo and I loved using it. 

Overall it's nice to see a modern language that's simple but has a focus on performance. I look forward to seeing where it goes next and if I can ever professionally jump into it.

Have you used Julia? What are your impressions (especially if you're from a Python background)?