teleren/devto huggingface dataset:
Side Project Sunday! Share your progress.
Tags: discuss, showdev, sideprojects, watercooler
Published: 2022-06-05 15:25:04

Give a quick description of what you're up to and what some recent challenges have been.

Anyone who posted [last week](https://dev.to/ben/side-project-sunday-hacking-on-anything-3f04) is more than welcome to share an update.
Python Concept learning point 1: Difference between methods and functions
Tags: beginners, python, concept
Published: 2022-06-05 15:22:10

Since I am always confused with methods and function, I did some reading about them and here is what I understand.
## What confused me 
- methods and functions look the same
- they both have parenthesis() 
- they can both take argument
- When defining, they both have `def` before the name

## The difference between methods and functions
1. Methods cannot call on its own, it need an object to call with, functions can call on it own.
2. Methods need and dot.operator, functions do not
3. Methods must be defined within a class, function can define on its own
4. When defining, methods require at least one parameter, and the first must be `self`, function can have any number of parameter(including 0)

The follow two program will have an output of "Bloom", but whats the difference?
## Example 1: method
```python
class Car:
    def make_sound(self):
        print "Bloom!"

ferrari = Car()
ferrari.make_sound()
```
Take make_sound as example, `make_sound` is define within a class, it takes self as its first parameter, it has a dot before it, so it is a method.

## Example 2: function
```python
def car_make_sound():
    print("Bloom!")

car_make_sound()
```
This time `car_make_sound()` is a function, although it also has an output of Bloom!. But it does not have `class` on top, it does not have any parameter and it have not object and . operator before it.
The weight of Experience
Published: 2022-06-05 15:09:08

---
title: The weight of Experience
published: true
description: 
tags: 
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nau6ksmjhtk7q2rlpn33.png
# Use a ratio of 100:42 for best results.
canonical_url: 'https://kevwe.com/weekly/202223'
---
Sometimes it looks like Testing has already become a new religion, but still apparently, the industry does not learn enough from the experiences.


Out of the systems that we build, it should be possible to see clearly what works, what could be done better, and what is clearly unsustainable.


A lot of technologies are borderline:

https://kevwe.com/weekly/202223
Calculate Digit Sum of a String
Tags: leetcode, dsa, theabbie
Published: 2022-06-05 15:00:46

You are given a string `s` consisting of digits and an integer `k`.

A **round** can be completed if the length of `s` is greater than `k`. In one round, do the following:

1.  **Divide** `s` into **consecutive groups** of size `k` such that the first `k` characters are in the first group, the next `k` characters are in the second group, and so on. **Note** that the size of the last group can be smaller than `k`.
2.  **Replace** each group of `s` with a string representing the sum of all its digits. For example, `"346"` is replaced with `"13"` because `3 + 4 + 6 = 13`.
3.  **Merge** consecutive groups together to form a new string. If the length of the string is greater than `k`, repeat from step `1`.

Return `s` _after all rounds have been completed_.

**Example 1:**

**Input:** s = "11111222223", k = 3
**Output:** "135"
**Explanation:** 
- For the first round, we divide s into groups of size 3: "111", "112", "222", and "23".
  ​​​​​Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5. 
  So, s becomes "3" + "4" + "6" + "5" = "3465" after the first round.
- For the second round, we divide s into "346" and "5".
  Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5. 
  So, s becomes "13" + "5" = "135" after second round. 
Now, s.length <= k, so we return "135" as the answer.

**Example 2:**

**Input:** s = "00000000", k = 3
**Output:** "000"
**Explanation:** 
We divide s into "000", "000", and "00".
Then we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0. 
s becomes "0" + "0" + "0" = "000", whose length is equal to k, so we return "000".

**Constraints:**

*   `1 <= s.length <= 100`
*   `2 <= k <= 100`
*   `s` consists of digits only.

**SOLUTION:**

    class Solution:
        def digitSum(self, s: str, k: int) -> str:
            while len(s) > k:
                nexts = ""
                for i in range(0, len(s), k):
                    nexts += str(sum(int(d) for d in s[i:i+k]))
                s = nexts
            return s
Recursive Algorithm
Tags: java, algorithms
Published: 2022-06-05 14:49:48

**Recursion** is where a function invokes itself. Various algorithms utilize recursion, hence it's important to know this concept.

Always remember when creating a recursive function that you need 2 parts: the **base case**, and the **recursive case**. The recursive case is when the function calls itself. The base case is when the function doesn’t call itself again (this prevents the function go into an infinite loop)


## Sample Code
_In this example, we try to find the factorial of 5_
```
public class Main {
    public static void main(String[] args) {
        // test the recursion method
        Factorial f = new Factorial();
        System.out.println(f.recursion(5));
    }
}

class Factorial {
    public long recursion(long n) {
        // this is our base case
        // always have a base case or else your recursion will never end
        if (n <= 1) {
            // here we are returning a value of 1
            // in programming, this means the output is met or valid
            return 1;
        } else {
            //recrusive case or also known as the method calling itself
            return n * recursion(n - 1);
        }
    }
}
```

## Note:
- Be careful with recursion as it can consume a lot of memory, and can create a program that never terminates. However, when used correctly recursion can be a very efficient and mathematically-elegant approach to programming.
- There’s no performance benefit to using recursion; in fact, loops are sometimes better for performance. Simply choose which is more important in your situation!
SwiftUI Text
Published: 2022-06-05 14:46:02

---
title: SwiftUI Text
published: true
description: 
tags: 
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
---

A view that displays one or more lines of read only text

SwiftUI draws the text with a **body** font by default, you can apply a different font like **title** using the **font()** modifier.

```swift
Text("F1 Hamilton")
    .font(.caption)
```

### Use a system font or a custom font

You can use the **font()** modifier to set a system or custom font.

```swift
Text("A man liveth")
    .font(.system(size: 14, weight: .light, design: .serif))
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tvisj0mshm1yfrrrstxw.png)

### Line limit

Sets the maximum number of lines that the text can occupy on the view.

```swift
Text("Sweet are the uses of adversity which, like the toad, ugly and venomous, wears yet a precious jewel in his head")
    .lineLimit(1)
```

### Multiline Text Allignment(alignment:)

Sets the alignment of multiple text in this view.

```swift
Text("William Shakespeare was an English playwright, poet and actor. He is widely regarded as the greatest writer in the English language and the world's greatest dramatist. He is often called England's national poet and the \"Bard of Avon\" ")
    .multilineTextAlignment(.center)
```

![Multiline Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pr34j5ae12huhq3z6u8l.png)

### Line Spacing

Sets the amount of space between lines of text in this view.

```swift
func lineSpacing(_ lineSpacing: CGFloat) -> some View 
```
**lineSpacing** is the distance between the top of one line of text and the bottom of another.

```swift 
Text("FROM off a hill whose concave womb reworded
A plaintful story from a sistering vale,
My spirits to attend this double voice accorded,
And down I laid to list the sad-tuned tale;
Ere long espied a fickle maid full pale,
Tearing of papers, breaking rings a-twain,
Storming her world with sorrow's wind and rain.

Upon her head a platted hive of straw,
Which fortified her visage from the sun,
Whereon the thought might think sometime it saw
The carcass of beauty spent and done:
Time had not scythed all that youth begun,
Nor youth all quit; but, spite of heaven's fell rage,
Some beauty peep'd through lattice of sear'd age.")
    .lineSpacing(20)
```

![10 Line Spaces](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1c188izrkspjh2ihlx7i.png)

![20 Line Spaces](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mbtdqg3y6iebktwcl7zi.png)
Azure Resource Manager Templates
Tags: azure, beginners, cloudskills, microsoft
Published: 2022-06-05 14:42:42

##Examine the Azure Resource Manager template hierarchy.

You'll learn how to use Azure Resource Manager templates (ARM templates) to implement infrastructure as code in this article. We'll go over the sections of an ARM template, learn how to deploy your ARM template to Azure, and go over the resources portion in depth.

##What is infrastructure as code, and how does it work?

Infrastructure as code allows you to express the infrastructure that your application requires in code.
You can maintain both your application code and everything you need to deploy your application in a common code repository with infrastructure as code. The following are some of the benefits of infrastructure as code:

- Configurations that are consistent
- Scalability has been improved.
- More rapid deployments
- Improved traceability

##What is an ARM template, and how does it function?

ARM templates, which are JavaScript Object Notation (JSON) files, establish the architecture and parameters for your deployment. The template employs declarative syntax. Declarative syntax is a way of defining the structure and elements that describe how resources will appear without having to specify the control flow. Declarative syntax is different from the imperative syntax, which uses commands to do computer activities. The goal of imperative scripting is to define each step of the resource deployment process.

You can declare what you want to deploy using ARM templates rather than having to write the programming commands to make it happen. An ARM template specifies the resources and characteristics for those resources.

We will discuss the:

##Advantages of ARM Templates
You can utilize ARM templates to automate deployments and use infrastructure as code (IaC). Your infrastructure and development initiatives will benefit from the template code. IaC files, like application code, can be stored in a source repository and versioned.

Idempotent means that you can use the same ARM template multiple times and get the same resource types in the same state.

Resource Manager coordinates the deployment of resources to ensure that they are created in the proper order. Resources will be produced in parallel whenever possible, making ARM template deployments faster than scripted deployments.

Validation is also included into Resource Manager. Before initiating the deployment, it examines the template to ensure that it will succeed.

You can break down your ARM templates into smaller, reusable components as your deployments become more complicated. At deployment time, you can join these smaller templates together. Templates can also be nestled inside other templates.

You can review your deployment history and get information about the status of your deployment via the Azure site. All parameters and results are displayed in the portal.
Loud and Rich
Tags: leetcode, dsa, theabbie
Published: 2022-06-05 14:30:42

There is a group of `n` people labeled from `0` to `n - 1` where each person has a different amount of money and a different level of quietness.

You are given an array `richer` where `richer[i] = [ai, bi]` indicates that `ai` has more money than `bi` and an integer array `quiet` where `quiet[i]` is the quietness of the `ith` person. All the given data in richer are **logically correct** (i.e., the data will not lead you to a situation where `x` is richer than `y` and `y` is richer than `x` at the same time).

Return _an integer array_ `answer` _where_ `answer[x] = y` _if_ `y` _is the least quiet person (that is, the person_ `y` _with the smallest value of_ `quiet[y]`_) among all people who definitely have equal to or more money than the person_ `x`.

**Example 1:**

**Input:** richer = \[\[1,0\],\[2,1\],\[3,1\],\[3,7\],\[4,3\],\[5,3\],\[6,3\]\], quiet = \[3,2,5,4,6,1,7,0\]
**Output:** \[5,5,2,5,4,5,6,7\]
**Explanation:** 
answer\[0\] = 5.
Person 5 has more money than 3, which has more money than 1, which has more money than 0.
The only person who is quieter (has lower quiet\[x\]) is person 7, but it is not clear if they have more money than person 0.
answer\[7\] = 7.
Among all people that definitely have equal to or more money than person 7 (which could be persons 3, 4, 5, 6, or 7), the person who is the quietest (has lower quiet\[x\]) is person 7.
The other answers can be filled out with similar reasoning.

**Example 2:**

**Input:** richer = \[\], quiet = \[0\]
**Output:** \[0\]

**Constraints:**

*   `n == quiet.length`
*   `1 <= n <= 500`
*   `0 <= quiet[i] < n`
*   All the values of `quiet` are **unique**.
*   `0 <= richer.length <= n * (n - 1) / 2`
*   `0 <= ai, bi < n`
*   `ai != bi`
*   All the pairs of `richer` are **unique**.
*   The observations in `richer` are all logically consistent.

**SOLUTION:**

    class Solution:
        def loudAndRich(self, richer: List[List[int]], quiet: List[int]) -> List[int]:
            n = len(quiet)
            graph = {}
            for a, b in richer:
                graph[b] = graph.get(b, []) + [a]
            answer = [0] * n
            for beg in range(n):
                paths = [beg]
                visited = {beg}
                while len(paths) > 0:
                    curr = paths.pop()
                    for j in graph.get(curr, []):
                        if j not in visited:
                            visited.add(j)
                            paths.append(j)
                answer[beg] = min(visited, key = lambda p: quiet[p])
            return answer
Working with JavaScript Arrays Pt. 3
Tags: webdev, javascript, beginners, programming
Published: 2022-06-05 14:28:47

Often in JavaScript you'll come across big long strings, that you'll more than likely want to separate certain items out into a more useful form, so then you can display them differently. Like a table for instance.

To do such an action, we can use the method, ***split()***.
Split takes a single parameter, which is the character you want to separate the string at, puts these substrings into an array, then returns the array.
Let's play around with it. 


## **1. First we create a string. **
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1650719701338/EqYwkf1hH.png)


## **2. Next, we'll split it at every comma. **
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1650719845192/9dIgLtUlG.png)


## **3. Lastly, we can find the length of the new array, and receive some items from it.**
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1650720055915/VkfFrNpuq.png)

## **4. You can do the opposite of .split(), by using the .join() method. **
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1650739090417/OoQlBUjaA.png)

## **5. One of the other ways of converting an array to a string, is using the ***.toString()*** method.
The .toString() method is more simple than the ***.join()*** method. It doesn't take a parameter. But, it is more limiting to use.
With the ***.join()*** method, you can specify different separators, whereas with ***.toString()*** method, it always uses a comma. 

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1650742064358/021KjTW3F.png)
Working with JavaScript Arrays Pt.1
Tags: webdev, javascript, beginners, programming
Published: 2022-06-05 14:21:04

Knowing about Arrays are one of the most important skills you can have in a programming language, especially for one learning JavaScript.  

We'll look at how with arrays, we can retrieve, add, and remove items stored in an array. 

Arrays are used to store a list of data items under a single variable name.
Usually described as list-like objects, they are objects that contain multiple values stored in a list.
Array objects are stored in variables and then be used in the same way as any other type of value. However, we can access each value inside the list individually. 

Arrays can be useful in such examples as if you had a dresser, and each drawer had different clothing items, and you wanted to access which drawer had what certain items.
Another example would be if you wanted to find the many different prices of items, and wanted to send an invoice while adding up the prices together and print out the total together.  



### Creating Arrays 
Suppose we wanted to store an array that had items that made up a skateboard:
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1648339323165/ETOhDjcfw.png)

Which would show you each of the items inside of the variable of skateboard.


Not only can we store strings, such as what we did above, but we can also store other data types such as numbers, objects, and even other arrays.
We can even mix other data types in a single array. 
Such an example:
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1648339886288/iuwgAdLfC.png)


## Finding the Arrays Length
By using the ***length*** property, we can find the length of the array.
If wanted to find the length of the array called food, it would look something like this:
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1648347648204/iR2WLEx9P.png)
As you see, there are 5 items inside the array of food, so 5 would be logged to the console.


## Accessing Array Items
You would think by looking at an array, that the items index would start with 1, but in fact, all arrays start with the item index of 0, with the second item being 1, and so on.
Using bracket notation we can access the item index of a particular item in the array.
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1648340825875/W2kUM5aSi.png)

Say if we wanted to change the item inside of the array ***pop***, we can do something like this.
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1648341012898/z3Ky0EOg3.png)
Here we change the first item, which is at the index of 0, to rock n rye.


In the next post, I'll talk about how to find items in an array, adding items, removing items, and accessing every item.
40 projects ideas for web developer
Tags: webdev, javascript, react, programming
Published: 2022-06-05 14:01:33

Are you looking ideas for web development to increase your skills?

Here is 40 projects ideas for web developer that you can build using all technologies stacks.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w1fmcim4yj8gs79ym4id.jpg)
Smallest String With A Given Numeric Value
Tags: leetcode, dsa, theabbie
Published: 2022-06-05 14:00:44

The **numeric value** of a **lowercase character** is defined as its position `(1-indexed)` in the alphabet, so the numeric value of `a` is `1`, the numeric value of `b` is `2`, the numeric value of `c` is `3`, and so on.

The **numeric value** of a **string** consisting of lowercase characters is defined as the sum of its characters' numeric values. For example, the numeric value of the string `"abe"` is equal to `1 + 2 + 5 = 8`.

You are given two integers `n` and `k`. Return _the **lexicographically smallest string** with **length** equal to `n` and **numeric value** equal to `k`._

Note that a string `x` is lexicographically smaller than string `y` if `x` comes before `y` in dictionary order, that is, either `x` is a prefix of `y`, or if `i` is the first position such that `x[i] != y[i]`, then `x[i]` comes before `y[i]` in alphabetic order.

**Example 1:**

**Input:** n = 3, k = 27
**Output:** "aay"
**Explanation:** The numeric value of the string is 1 + 1 + 25 = 27, and it is the smallest string with such a value and length equal to 3.

**Example 2:**

**Input:** n = 5, k = 73
**Output:** "aaszz"

**Constraints:**

*   `1 <= n <= 105`
*   `n <= k <= 26 * n`

**SOLUTION:**

    class Solution:
        def getSmallestString(self, n: int, k: int) -> str:
            a,b = divmod(k-n, 25)
            c = max(n-a-1, 0)
            d = n-a-c
            return "a" * c + chr(ord('a') + b) * d + "z" * a
Clojure Tutorial Part 6 -- サーバーファイルのメソッドからサーバーの起動、停止、再起動をできるようになる
Tags: clojure
Published: 2022-06-05 13:51:20


## 参考

https://scrapbox.io/ayato-p/Part1_Web%E3%82%A2%E3%83%97%E3%83%AA%E3%82%B1%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%AF%E3%81%98%E3%82%81%E3%81%AE%E4%B8%80%E6%AD%A9

引き続き、ayato-p さんの記事の

新しいネームスペースを作って保存する

の章を参考にする。

```clj
 (ns cljblog.server
   (:require [ring.adapter.jetty :as jetty]))
 
 (defonce server (atom nil))
 
 (defn handler [req]
   {:status 200
    :headers {"Content-Type" "text/plain"}
    :body "Hello, world!"})
    
 (defn start []
   (when-not @server
     (let [options {:port 3000 :join? false}]
       (reset! server (jetty/run-jetty handler options)))))
      
 (defn stop []
   (when @server
     (.stop @server)
     (reset! server nil)))
 
 (defn restart []
   (stop)
   (start))
```

main として読み込まれる src/cljblog/core.clj に並列して
src/cljblog/ に server.clj を作成する。

詳しくみていくと

```clj
 (ns cljblog.server
   (:require [ring.adapter.jetty :as jetty]))
 
 (defonce server (atom nil))
```

ns でファイル名を明記

defonce と atom はサーバー変数を起動、停止、再起動で使うためにあるらしい。

```clj
 (defn handler [req]
   {:status 200
    :headers {"Content-Type" "text/plain"}
    :body "Hello, world!"})
```

最初に共通処理として handler 関数を作る。
全てのリクエストで

- status 200
- contentType プレーンテキスト
- body "Hello, World!"

これらを渡すようにする。

```clj
 (defn start []
   (when-not @server
     (let [options {:port 3000 :join? false}]
       (reset! server (jetty/run-jetty handler options)))))
```

start では server 変数が無い時にのみ動いて
options に port と join を追加して

server に jetty を handler と options の値を渡す。
するとサーバーが起動される。

https://clojuredocs.org/clojure.core/reset!

reset! は引数の値を書き換えるためのメソッド。

```clj
 (defn stop []
   (when @server
     (.stop @server)
     (reset! server nil)))
```

stop では server 変数の中身がある時に .stop を与えて
reset! で　server 変数を空にする。

```clj
 (defn restart []
   (stop)
   (start))
```

restart は単に stop の後に start を実行している。

## 実際に動かす

```clj
lein repl
cljblog.core=> 
```

lein repl で起動して

```clj
(require '[cljblog.server :as server])

2022-06-05 22:40:17.170:INFO::nREPL-session-1dd10f13-948c-4f56-ba35-317335f370eb: Logging initialized @42123ms to org.eclipse.jetty.util.log.StdErrLog
nil
```

さっき作った server ファイルを import

```clj
(server/start)
Started @77584ms
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/chjdims1fggz3484pi4u.png)
 
その start を呼ぶとサーバーが動く

```clj
Stopped ServerConnector@5a2fa9ff{HTTP/1.1,[http/1.1]}{0.0.0.0:3000}
```

stop も

```clj
 (server/restart)
Started ServerConnector@6e0dc191{HTTP/1.1,[http/1.1]}{0.0.0.0:3000}

(server/restart)
Stopped ServerConnector@6e0dc191{HTTP/1.1,[http/1.1]}{0.0.0.0:3000}
Started ServerConnector@9da958b{HTTP/1.1,[http/1.1]}{0.0.0.0:3000}
```

restart も起動した。

---

## まとめ

Clojure でサーバーの操作コマンドを作るためには

server ファイルを作成し、

共通の handler 関数を作り
status, headers, body,
これらを渡すようにする

start 関数では
server 変数の中身がない場合のみ動いて
options の port, join を渡して
server 変数に run-jetty と
さっき作った options と共通関数の handler 
これらを渡す。

stop 関数は逆で
server 変数がある時のみ動いて
.stop を server にぶち込んで
server 変数に nil (null 相当)をぶち込みます

restart は stop と start

そして、repl を起動して import してこれらを呼ぶ。
以上。
Dear dev.to community
Published: 2022-06-05 13:37:46

Hello everybody, first post here so I'll start small.
First of all I'd really like to thank everybody for being such a friendly (and of course interesting)environment, light years from many other so called 'communities' where the most important thing is asserting that "my ideas are much better than anybody's", or "my frame works better than yours"😁
That's it, cheers!