teleren/devto huggingface dataset:
Day 5: Inconsistent days
Published: 2021-07-18 16:15:37

### Disclaimer:
> I am a beginner in competitive programming, and this is me documenting my learnings. So, anything I say is just what I think at the moment and should not be taken as hard truths.

## Two problems a day, keeps doctor away!

### Problem 1: [Brain's Photos](https://codeforces.com/problemset/problem/707/A)

Simple problem of taking input and comparing it with different values.

```cpp
main() {
  int n, m; cin >> n >> m;
  bool bw = true;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      char c;
      cin >> c;
      if(c == 'C' || c == 'M' || c == 'Y') bw = false;
    }
  }
  if(bw) cout << "#Black&White";
  else cout << "#Color";
}
```

This is better style of writing for the given problem. No need to write two for loops. Cleaner code.
```cpp
main() {
  int n, m; cin >> n >> m;
  bool bw = true;
  char c;
  while(cin >> c) {
    if(c == 'C' || c == 'M' || c == 'Y') bw = false;
  }
  if(bw) cout << "#Black&White";
  else cout << "#Color";
}
```


### Problem 2: [Sereja and Dima](https://codeforces.com/problemset/problem/381/A)

Implementing the greedy take and find score of each player.

```cpp
main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for(auto& e: v) cin >> e;
  int i = 0, j = n-1;
  int s = 0, d = 0;
  bool ser = true;
  while(i <= j) {
    if(v[i] > v[j]) {
      if(ser) s += v[i];
      else d += v[i];
      i++;
    } else {
      if(ser) s += v[j];
      else d += v[j];
      j--;
    }
    ser = !ser;
  }
  cout << s << ' ' << d;
}
```

More cleaner code and easy to understand.
```cpp
main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for(auto& e: v) cin >> e;
  int i = 0, j = n-1;
  int s = 0, d = 0;
  bool ser = true;
  while(i <= j) {
    int val = max(v[i], v[j]);
    if(ser) s += val;
    else d += val;
    ser = !ser;
    if(val == v[i]) i++;
    else j--;
  }
  cout << s << ' ' << d;
}
``` 

## Algorithm

We didn't learn any new algorithm today :-(

Dated: 17th July 2021
Developing Quality API with Laravel - Tip #1
Tags: laravel, api
Published: 2021-07-18 15:39:29

Developing quality API is one of the most important factors in an application's success. In this series I try to bring easy but helpful tips to help you develop quality APIs.

So let us begin...

###Tip #1 - Do not hardcode response messages into your codebase.

What is mean by this is that you don't have to hardcode every message into the codebase. You can simply store them in a file so in case of any change so you can handle the situation with ease.

#### Don't do this.
```php
return response()->json([
    'message' => 'Yo, everything is cool!'
], Response::HTTP_OK);
```

What if you use this piece of code in, say, 100 functions and now you want to change the `message` because your boss is not ok with it? 

The easiest way is to `ctrl + shift + f` that string in `vscode` and replace all of it in a matter of seconds; and let's not even think about the idea of manually replacing each string ourselves.

But why do this when there's an easier and more professional way?

####Let's do this instead.
Create a `response.php` file in `/resources/lang/en` folder of your Laravel project and create an array of whatever keys and values you want. But for the purpose of this article we can do this: 

```php
return [
    'successful_action' => 'Yo, everything is cool!',
];
```
And modify that `return` statement with this:
```php
return response()->json([
    'message' => __('response.successful_action')
], Response::HTTP_OK);
```
Now even if there are a million of these `return` statements in your codebase and you want to change that `message` to something more appropriate you can easily change the value of `successful_action` key inside you `response.php` file and you're good to go.

**Note**
Please remember to return proper HTTP status code with each response you send back to front-end guys. They'll greatly appreciate it.

**Last Words**
If you know a better way or any tips at all, please feel free to share it with me, I'd be more than happy to learn something from you.

---

[Link to cover image](https://unsplash.com/photos/AiORnUT6sC0)
Ruby gem for finding weekday of a date
Tags: ruby, rubygem, programming
Published: 2021-07-18 15:24:49

I have created my first ruby gem named **DayFinder**

This gem is useful if you want to find the weekday of given date

`Example:-`
```ruby
require 'DayFinder'
day=DayFinder.find 15,8,1947
puts day
#output
# Friday

```
You have to provide the date as `d-m-Y` format.
So do you want to give it a try ?
Install and try now

## Installation
```ruby
gem 'DayFinder'
```

And then execute:

    $ bundle install

Or install it yourself as:

    $ gem install DayFinder
The Github Repo:https://github.com/freakflames29/DayFinder
Rubgems.org:- https://rubygems.org/gems/DayFinder
What's new in Android 12
Tags: android, java, kotlin
Published: 2021-07-18 15:08:52

Android 12 Developer preview is out since February. There are couple of interesting features and capabilities added to the release that developers can leverage. Regarding the new Material You UI, it's too early to take a call, but the AppSearch API is worth taking a look. The NoSQL LocalStorage and PlatformStorage will enable apps that can do high data processing.

Here is a high level analysis by @donpeter06 about the new features in Android 12.
https://www.blog.finotes.com/post/what-is-new-for-developers-in-android-12
tmux prefix
Tags: techtalks, tmux, linux
Published: 2021-07-18 15:05:40

---
title: tmux prefix
published: true
description: 
tags: techtalks, tmux, linux
canonical_url: https://waylonwalker.com/tmux-prefix/
series: tmux
---


The prefix key is an essential part of tmux, by default all of tmux's
key-bindings sit behind a prefix.  This prefix is very similar to vim's leader
key. It is common for folks to change the default `C-b` (control b) to `C-a` or
if they are a vim user something to match their vim leader key.

``` bash
set -g prefix C-Space
bind Space send-prefix
```

A few of the essential default key-bindings.

```
%      vertical split
"      horizontal split
d      detach

up     select up one pane
down   select down one pane
right  select right one pane
left   select left one pane

t      clock
o      swap panes
c      create window
n      next window
p      previous window
```

A more complete list of key-bindings can be found in this gist https://gist.github.com/mzmonsour/8791835.


---

Be sure to check out the full youtube playlist and subscribe if you like it.

https://www.youtube.com/playlist?list=PLTRNG6WIHETB4reAxbWza3CZeP9KL6Bkr


{% post https://dev.to/waylonwalker/how-i-navigate-tmux-in-2021-2ina %}

> Also check out this long form post for more about how I use tmux.
Understanding Kubernetes in a visual way (in 🎥 video): part 20 – Useful tools part 2
Tags: kubernetes, devops, docker, beginners
Published: 2021-07-18 15:00:51

---
title: Understanding Kubernetes in a visual way (in 🎥 video): part 20 – Useful tools part 2
published: true
description: Serie of videos about Kubernetes. Explaining in a visual way Kubernetes principles.
tags: Kubernetes, DevOps, Docker, beginners
series: Understanding Kubernetes in a visual way - (in video) in video
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w5broy22vxw3z50k2ozb.jpg
---

Understanding Kubernetes can be difficult or time-consuming. In order to spread knowledges about Cloud technologies I started to create sketchnotes about Kubernetes, then I've auto-published a book and since now I've started a new serie of video! :-)

I imagined a serie of short videos with a mix of sketchnotes and speech.

I think it could be a good way, more visual, with audio & video to explain Kubernetes (and others technologies).

In this second special episode, let's discover other several useful tools in the Kubernetes ecosystem.

{% youtube M9CN-VEBcME %}

The video is in French BUT I done the subtitles in english (and french too).

If you liked the video and are interested to watch another ones, please give me some feedbacks (and you can also subscribe to [my Youtube channel](https://www.youtube.com/channel/UCrRk0kOP58lBMl9B8ZS8Vlg), if you want to ❤️).

If you are interested, I published all the sketchnotes on Kubernetes (and new ones!) to make a "book" of 165 pages: ["Understanding Kubernetes in a visual way"](https://gumroad.com/aurelievache#uCxcr).

If you like theses sketchnotes, you can follow me, I will publish others sketchs shortly :-).
Do we learn from mistakes/bugs? 💻
Tags: discuss, programming, productivity, career
Published: 2021-07-18 14:58:17


# Introduction

Hi guys, how are you doing? 
The main idea of this post is to talk a little bit about our experiences fighting with some bugs or mistakes we know and need to fix but at the end of the problem we learn something. Some of them are invalidating and we can't continue developing and others are just warnings but sometimes we really need them fixed.

*I don't wanna motivate you to "learn from bugs/mistakes" because I think the best way to do it is from documentation, but due to my experience I guess we can learn from them.*

# To the point...
I have learnt a lot from some struggling situations, from coding to setting up an environment. I will give a simple example that could help you to understand what I mean.

I remember facing with Apache Cordova setting up issues a few years ago and with React Native some time after that. In both cases I had to read, to study and to find out a lot of info about that, not just a light search. That time I was using Ubuntu and it was too interesting for me find out how `~/.bashrc` or `~/.bash_profile` works, and `$PATH` as well. 

Simple things maybe for someone with some years of developing experience, but I found it so awesome to learn from that situation.

# Conclusion
This is just a simple sample, but **do you think the same? do you learn from bugs/mistakes?**

---

### Thanks for reading 🙌 👋
How to use Bootstrap Icons in Elixir Phoenix 1.5 app
Tags: phoenix, elixir, bootstrap, icons
Published: 2021-07-18 14:51:20

Here is how I set up [Bootstrap Icons](https://icons.getbootstrap.com) in one of my Elixir Phonenix apps. To me it was more difficult than I expected so I want to write this post for future reference.

## Get started

### Install necessary libraries from NPM

I do not know much about Webpack but icons would not get loaded without file-loader set up. This post ["Loading Fonts with webpack" by Chris Lis](https://chriscourses.com/blog/loading-fonts-webpack) was helpful.

```
npm --prefix=assets install bootstrap-icons file-loader --save-dev
```

### Import CSS and webfonts in the stylesheet

`assets/css/app.scss`

```diff
+ @import '../node_modules/bootstrap-icons/font/bootstrap-icons.css';
+
+ @font-face {
+   font-family: 'bootstrap-icons';
+   src: font-url('../node_modules/bootstrap-icons/font/fonts/bootstrap-icons.woff2') format('woff2'),
+     font-url('../node_modules/bootstrap-icons/font/fonts/bootstrap-icons.woff') format('woff');
+ }
```

### Set up the file-loader for web fonts

`assets/webpack.config.js`

```diff
           test: /\.[s]?css$/,
           use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
         },
+        {
+          test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
+          use: [
+            {
+              loader: 'file-loader',
+              options: {
+                name: '[name].[ext]',
+                outputPath: 'fonts/',
+              },
+            },
+          ],
+        },
       ],
     },
     plugins: [
```

## Usage

Pick an icon from [Bootstrap Icons website](https://icons.getbootstrap.com/) and copy and paste an "Icon font" HTML tag like:

```html
<i class="bi bi-plus-circle"></i>
```

## Alternative methods

Alternatively, `PhoenixInlineSvg.Helpers.svg_image/2` from [phoenix_inline_svg](https://hexdocs.pm/phoenix_inline_svg/readme.html) is straight-forward and useful when we want to render SVG files in our view templates. All we need is make `assets/static/svg/generic/` folder and copy necessary SVG files into it.
Oh-my-zsh no Windows
Tags: linux, windows, ohmyzsh
Published: 2021-07-18 13:49:22

Se você teve alguma experiência com linux, provavel que tenha usado ou ouviu falar sobre zsh ou oh-my-zsh, com o advento do home-office muitas empresas usam o Windows como sistema padrão, mas como esse sistema não tem suporte ao zsh, como você poderia estar utilizando essa ferramenta que ajuda tanto com o plus de ter um terminal decente no sistema operacional do Bill Gates? vou ensinar nesse mesmo artigo :)

Primeiro precisamos ter um emulador de bash, o que eu recomendo é o git-bash pela simplicadade de baixar, instalar e já sair usando.
Podemos baixar nesse link
```
https://gitforwindows.org/
```

Ok, baixei, instalei e agora?

Entre nesse link e baixe o pacote do zsh
```
https://packages.msys2.org/package/zsh?repo=msys&variant=x86_64
```
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nmcpb3aq0e7yy8bzhnsw.png)
esse pacote é compactado usando zstd, então vamos precisar baixar um descompactador de dados especial, eu recomendo o peazip 
```
https://peazip.github.io/zst-compressed-file-format.html
```
Extraia na sua pasta do git, normalmente ela fica nesse caminho
```
C:\Program Files\Git 
```

Abra o Git Bash e rode o comando
```
zsh
```

Então, esse passo é importante, o zsh vai pedir algumas configurações quando você rodar ele pela primeira vez, como histórico, etc. Leia as opções e defina isso de acordo com o seu uso e gosto, mas você pode deixar como default e depois alterar caso você não tenha ideia do que esteja alterando.

Seguindo, execute o comando abaixo no git bash para instalar o Oh-my-zsh
```
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
```
Agora você vai defini-lo como padrão, então você vai precisar editar o arquivo ~/.bashrc ou crie caso ele não exista, recomendo que faça esse processo na basta Git/etc/zsh mas acredito que funcione se você salva-lo em qualquer lugar, nesse arquivo você vai colocar o seguinte código.

```
# Roda o Zsh como default
if [ -t 1 ]; then
exec zsh
fi
```
Feche e abra novamente o git que já vai funcionar! :)

Recomendação
* Baixar e usar o Windows terminal com o tema Batman configurando para usar o git bash como padrão
* Instalar o tema Hokunay no zsh
* Ler e usar os alias default do oh-my-zsh
```
https://ohmycheatsheet.com/oh-my-zsh-commands-cheat-sheet/
```
* Adicionar os diversos plugins que existem ao seu zsh, recomendo esses
```
fast-syntax-highlighting
zsh-completions
```

Resultado:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/912bbieizlrfl6b3z4ui.png)

Espero que tenha ajudado, qualquer dúvida é só mandar um comentário que responderei assim que possível! see ya :)
Elasticsearch: Get Started
Tags: elasticsearch, kibana, opensearch
Published: 2021-07-18 13:48:04

####Agenda
- Elasticsearch
- OpenSearch
- Kibana
- Dev Tools
- ​curl
- Docker Container
- CRUD
- Analyze
- Basic Query

Code: https://github.com/codebangkok/elastic

####ติดตามผลงานได้ที่
* **Page:** [https://fb.com/CodeBangkok​](https://fb.com/CodeBangkok​)
* **Group:** [https://fb.com/groups/msdevth​](https://fb.com/groups/msdevth​)
* **Blog:** [https://dev.to/codebangkok](https://dev.to/codebangkok)
* **YouTube:** [https://youtube.com/CodeBangkok](https://youtube.com/CodeBangkok)
Array | Rust
Tags: rust, array
Published: 2021-07-18 12:52:54

#การประกาศอาร์เรย์
ใน rust สามารถทำได้ดังนี้ การประกาศตัวแปร์ ages เก็บค่าอายุในรูปแบบของอาร์เรย์ขนาด 4 ช่อง
```rust
let ages:[i32;4] = [12, 16, 19, 20];
```
เนื่องจากอาร์เรย์มีขนาดชัดเจน หากเราทำการกำหนดค่าในแต่ละช่องตั้งแต่แระแล้ว
เราสามารถที่จะละtype ไปได้เลย
```rust
let ages = [12, 16, 19, 20];
```

เรายังสามารถกำหนดค่าเริ่มต้นให้กับอาร์เรย์ทุกช่องโดยใช้ `[v;n]` 
หมายความว่า กำหนดค่าในอาร์เรย์ทุกช่องเป็นค่า `v` และอาร์เรย์มีขนาดเท่ากับ `n` ตัวอย่างด้านล่างหมายความว่า ค่าในอาร์เรย์ทุกช่องจะเป็น `0` และอาร์เรย์มีขนาดเท่ากับ `4`
```rust
let ages = [0;4];
```

จะละ type หรือระบุ type ก็ได้เช่นกัน
```rust
let ages:[i32;4] = [0;4];
```

ขนาดของอาร์เรย์เป็นคุณสมบัติหนึ่งของ type ด้วย
ตัวอย่างเช่น ฟังก์ชั้น show รับอาร์เรย์ขนาด 3 แต่เราส่ง ages ซึ่งเป็นอาร์เรย์ขนาด 4 ไปตอนเรียกฟังก์ชั่น เราจะเจอคอมไพล์ error ถึงแม้อาร์เรย์จะเป็นชนิด `i32` เหมือนกัน
```rust
fn show(xs: [i32;3]) {
    println!("{:?}", xs); 
}

fn main(){
   let ages = [0;4];
   show(ages);
}
```

ผลลัพธ์
`show(ages);
        ^^ expected an array with a fixed size of 3 elements, found one with 4 elements`


#อ่านค่าจากอาร์เรย์
เราสามารถอ่านค่าจากอาร์เรย์ได้โดย `[index]` โดย index เริ่มต้นที่ 0 
เช่น ถ้าอยากอ่านค่าตำแหน่งแรกของอาร์เรย์ ทำได้โดย `ages[0]` ถ้าอยากอ่านค่าตำแหน่งที่สามของอาร์เรย์ ทำได้โดย `ages[2]`  เพราะ index เริ่มนับที่ `0` ตำแหน่งที่สาม index ก็เลยเป็น `2`  

```rust
fn main(){
    let ages = [12, 16, 19, 20];
    println!("first element: {}", ages[0]);
}
```

#เปลี่ยนค่าในอาร์เรย์
หากเราอยากให้อาร์เรย์สามารถเปลี่ยนค่าได้ต้องเพ่ิมคำว่า `mut` (mutable) เข้าไปตอนประกาศอาร์เรย์เพื่อระบุให้ชัดเจนว่านี่คือตัวแปรอาร์เรย์ที่สามารถเปลี่ยนค่าได้ 

```rust
fn main(){
    let mut ages = [12, 16, 19, 20];
    println!("first element: {}", ages[0]);
    
    ages[0] = 55;  //เปลี่ยนค่าตำแหน่งแรกจาก 12 ให้เป็น 55
    println!("first element: {}", ages[0]);
}
```

#ขนาดของอาร์เรย์
สามารถหาได้โดยใช้ คำสั่ง `len()` 

```rust
fn main(){
   let ages = [0;4];
   println!("length of ages {}", xs.len()); 
}
```

นั่นก็คือการใช้งานตัวแปรอาร์เรย์ใน rust เบื้องต้นครับ
GITHUB REPOS THAT EVERY DEVELOPER MUST KNOW ✨
Tags: javascript, github, webdev, beginners
Published: 2021-07-18 12:32:40

Here are the **7 GitHub Repos** arranged in _increasing order of the number of stars🌟 they got_ and the amount of people found it useful is quite amazing. Hope you will also get benefitted from these and yes, at the end, don't forget to checkout the video :))

#### 1. Public APIS - 139K 🌟
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n5gi1w6irxcx4otwihu5.png)
 
{% github public-apis/public-apis %}
#### 2. You don't know JS - 142K 🌟
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vqoub0do77wo94kf5fv0.png)
 
{% github getify/You-Dont-Know-JS %}
#### 3. Developer Roadmap - 164K 🌟
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8s1yk4y29r2dbfqlidyk.png)
 
{% github kamranahmedse/developer-roadmap %}
#### 4. Awesome - 166K 🌟
![Awesome](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ujzxtlu2cejnb92hpqar.png)
 
{% github sindresorhus/awesome %}
#### 5. Coding Interview University - 184K 🌟
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dtefwax92pb25fcvuxuk.png)
 
{% github jwasham/coding-interview-university %}
#### 6. Free Programming Books - 194K 🌟
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ltzqfpcy9cflppe3qxsq.png)
{% github EbookFoundation/free-programming-books %}


#### 7. FreeCodeCamp - 326K 🌟
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ie65ezknunxmr8shdfjk.png)
 
{% github freeCodeCamp/freeCodeCamp %}

----
#### Video Link :
{% youtube VSfYwYJr_Dc %}
----
a good example why tech companies test leetcode style questions.
Tags: javascript, career, programming
Published: 2021-07-18 12:12:32

Today I came across a question that is simple enough for most developers to solve fast, but just slightly complex enough to worth a little bit of discussion. I believe this questions, and my answer to it, is a pretty good demonstration why leetcode style interview exists. Let's look at the problem first: 
https://leetcode.com/problems/isomorphic-strings/

The real problem at hand is how do you confirm whether two strings are representationally the same. Representationally, sorry for the unclear diction, because you can transform the strings into a representations of the order of appearance and how many of different kinds in each word. 

so essentially, a good way to show an isomorphic representation of a string would be like:
egg = 122
add = 122
therefore egg and add are isomorphic 

isomorphic = 1234356718;

Please see code below:
```
var isIsomorphic = function(s, t) {
    if (!s || !t) return false;
    if(s.length !== t.length) return false;
    
    let sMap = {};
    let tMap = {};
    let sNumString = '';
    let tNumString = '';
    let currentS = '';
    let currentT = ''
    for (let i=0; i<s.length; i++) {
        currentS = s[i];
        currentT = t[i];
        
        if(!sMap[currentS]) {
            sMap[currentS] = Object.keys(sMap).length + 1
        } 
        else {    
            sNumString += sMap[currentS]
        }
        
        
        if(!tMap[currentT]) {
            tMap[currentT] = Object.keys(tMap).length + 1
        }
        else {    
            tNumString += tMap[currentT]
        }
    }
    
    return sNumString === tNumString
};

```

I think questions like one this really digs deep into whether a developer really knows and is skillful at general problem solving and would be an indicator whether the employee will be good for the company. 

(Although I don't know if my solution to this would be well-received at interviews when it is usually not possible to test the validity of code.)

I really dislike problems that are very esoteric and dependent on contextual knowledge. For example, you'd need to know a specific formula for solving how many prime numbers are in [0 ... n]. This type of problem is just terrible and not worthwhile to learn. 

Another reason why I like the isomorphic string problem so much, because not only it is knowledge independent, but also does not require a huge mental aerobatic like https://leetcode.com/problems/maximum-subarray/
I would say, however, questions like maximum-subarray do show whether a candidate has reach a higher level of computational, emphasis here, solving skill. Except that in interviews, it's hugely frustrating if you haven't seen a problem remotely similar beforehand.

Do you have a similar question in mind that is like this one ? Please comment and let me know!