teleren/devto huggingface dataset:
Typical folder structure for a Ruby application using Sinatra and ActiveRecord
Tags: ruby, sinatra
Published: 2022-08-14 17:49:36

When writing a software application, _separation of concerns_ is very important, especially with object oriented programming. It is key that we use a folder structure that is easy to work with and clearly let us know where to put each file.

---

This is a suggestion on how to make this folder structure when you are coding in **Ruby** using **Sinatra** and **Active Record**. Each folder in this structure has a clearly defined responsibility as well as each file inside of them.

Files in the root folder:
**Gemfile**: Lists all the gems that need to be installed for our application to run.
**Rakefile**: Contains code we create and use for common tasks we can run from the command line and also by requiring **sinatra/activerecord/rake** we can have access to other useful tasks like **db:migrate** or **db:seed**.

Folders:
**app/models**: Here we put all our Active Record models, the core of our application because here we access and update the database responding to the user actions.
**app/controllers**: Following the software pattern known as [Model-View-Controller](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller), this folder contains the code for creating our API end points that are responsible for feeding the client app.
**config**: Code responsible for our environment setup. Here we define how to connect to the database and require files or gems needed by our application.
**db**: Has the different databases we are using for each environment (development/test).
**db/migrate**: Files to create/alter the database structure.
**db/seed.rb**: File that contains code to add sample data to our database. Here is a useful [gem for generating sample data](https://github.com/faker-ruby/faker). We can use the rake task _db:seed_ to add that sample data to the database.
**spec**: Contains all the test files.

Following a well designed folder structure will make it easy to know where to put code depending of its responsibility, will help our application to grow under control and will help other developers to easily maintain the application in the future.
📢 Junior developers, this Twitter space is for you 📢
Tags: codenewbie, webdev, beginners, career
Published: 2022-08-14 17:33:21

Join me and the legendary [Anna J McDougall](https://twitter.com/AnnaJMcDougall) on Monday, **August 15th**, at **6pm BST** / **7pm CEST** as we share our top tips for junior devs who want to get promoted to mid level.

Bring your questions!

Set a reminder here 👇👇👇
https://twitter.com/i/spaces/1OwxWzXyvmqJQ?s=20
Laravel FormRequest With Opis Validator
Published: 2022-08-14 17:25:16

I published a package for using [Opis JSON Schema](https://github.com/opis/json-schema) to FormRequest on laravel

https://github.com/mesak/laravel-opis-validator

# installation

```bash
composer require mesak/laravel-opis-validator
```

## Example

### Requests
```php
<?php

namespace App\Http\Requests;

use Mesak\LaravelOpisValidator\JsonSchemaRequest;

class JsonSchema extends JsonSchemaRequest
{
    protected $extendValidatorMessage = true;

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            '$schema' => "http://json-schema.org/draft-07/schema#",
            "type" => "object",
            "title" => "Base Preference",
            "description" => "Base Preference Setting",
            "properties" => [
                "limit" => [
                    "type" => "integer",
                    "minimum" => 5,
                    "maximum" => 15,
                    "title" => "limit",
                    "attrs" => [
                        "placeholder" => "limit (limit)"
                    ]
                ],
                "page" => [
                    "type" => "object",
                    "title" => "Page",
                    "attrs" => [
                        "placeholder" => "Page ( Page )"
                    ],
                    "properties" => [
                        "limit" => [
                            "type" => "integer"
                        ]
                    ]
                ]
            ],
            "additionalProperties" => false,
            "required" => [
                "limit",
                "page"
            ]
        ];
    }
```


### Controller
```php

use App\Http\Requests\JsonSchema as JsonSchemaRequest;

    public function update(JsonSchemaRequest $request)
    {
        dd($request->validated());
    }
```
Difference between business idea, business model and business concept
Tags: beginners, management, community, writing
Published: 2022-08-14 17:15:51

For a budding or developing infopreneur, it is interesting to know what makes the difference between these three terms:

<>Business idea<>

The business idea is the starting point for developing new or different business solutions for important tasks, problems or wishes of customers. The essential points that should be included are the customer benefit as well as at least one essential USP (unique selling point), in order to give the customer a value proposition (which benefit a company promises its customers with a certain product or service) to be able to.

<>Business model<>

After the successful evaluation of this idea, a suitable business model is set up. It describes in concrete terms how this idea should be implemented and implemented and how sales can be generated with it. Basically, the model should help to understand, analyze and communicate the most important success points. Several models can be developed under one idea and then tested. In the end, the one with the highest economic benefit should be identified and combined with the business idea.

<>Business concept<>

The last and most concrete step now follows the creation of a business concept / business plan. This describes the entrepreneur’s project, strategy, goals and planned measures so precisely that investors can also be convinced of them.
Java executor framework
Tags: programming, java, tutorial, community
Published: 2022-08-14 17:09:31

ExecutorService is a JDK API that simplifies running tasks in asynchronous mode. It provides a pool of threads and an API for assigning tasks to it. The executor framework is an implementation of the Producer-Consumer pattern. The **java.util.concurrent.Executors** class provides a set of methods for creating ThreadPools of worker threads. In this article, we will be looking at types of executors.

##Types of executor

- **Single thread Executor**

The SingleThreadExecutor is a special type of executor that has only a single thread. It is used when we need to execute tasks in sequential order.

`ExecutorService executor = Executors.newSingleThreadExecutor()  `

- **Fixed thread pool**

FixedThreadPool is another special type of executor that is a thread pool having a fixed number of threads. By this executor, the submitted task is executed by the n thread.
The tasks are then stored in **LinkedBlockingQueue** until previous tasks are not completed.

`ExecutorService executor = Executors.newFixedThreadPool(4);  `

- **Cached thread pool**

The CachedThreadPool is a special type of thread pool that is used to execute short-lived parallel tasks. The cached thread pool doesn't have a fixed number of threads. When a new task comes at a time and all the threads are busy executing some other tasks, a new thread is created by the pool and added to the executor.

`ExecutorService executor = Executors.newCachedThreadPool();  `

- **Scheduled executor service**

The ScheduledExecutorService interface runs tasks after some predefined delay and/or periodically. 

`ScheduledExecutorService scheduledExecService = Executors.newScheduledThreadPool(1);  
`
The **scheduleAtFixedRate** and **scheduleWithFixedDelay** are the two methods that are used to schedule the task in ScheduledExecutor. 
The **scheduleAtFixedRate** method executes the task with a fixed interval when the previous task ended. 
The **scheduleWithFixedDelay** method starts the delay count after the current task is complete. 
The main difference between these two methods is their interpretation of the delay between successive executions of a scheduled job.

`scheduledExecService.scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)  
`

`scheduledExecService.scheduleWithFixedDelay(Runnable command, long initialDelay, long period, TimeUnit unit) 
` 

The best use case for ExecutorService is the processing of independent tasks, such as transactions or requests according to the scheme “one thread for one task” in Oracle’s documentation, fork/join was designed to speed up work that can be broken into smaller pieces recursively.

That's all for today, Happy Coding!..
Algorithm Code Complexity
Published: 2022-08-14 17:07:21

<div class="r21Kzd" data-hveid="CBAQAQ" data-ved="2ahUKEwjnnNirw8b5AhUC-TgGHe8lBs0Quk56BAgQEAE"><a href="https://howtostartprogramming.in/algorithm-code-complexity/"><strong>Code Complexity</strong> </a>compute it by using the control flow graph of the program. Cyclomatic complexity <b>measures the number of nested conditions within the code, such as those created by for, if/else, switch, while, and until</b>. The greater the number of conditions (as in example b from above), the greater the complexity.</div>
&nbsp;
<table style="height: 209px;" width="834">
<tbody>
<tr>
<td style="text-align: center;" colspan="4"><strong>Time complexity:</strong></td>
</tr>
<tr>
<td></td>
<td> Worst Case Scenario</td>
<td>Average Case Scenario</td>
<td>Best Case Scenario</td>
</tr>
<tr>
<td>Accessing an element</td>
<td>O(1)</td>
<td>O(1)</td>
<td>O(1)</td>
</tr>
<tr>
<td>Updating an element</td>
<td>O(1)</td>
<td>O(1)</td>
<td>O(1)</td>
</tr>
<tr>
<td>Deleting an element</td>
<td>O(n)</td>
<td>O(n)</td>
<td>O(1)</td>
</tr>
<tr>
<td>Inserting an element</td>
<td>O(n)</td>
<td>O(n)</td>
<td>O(1)</td>
</tr>
<tr>
<td>Searching for an element</td>
<td>O(n)</td>
<td>O(n)</td>
<td>O(1)</td>
</tr>
</tbody>
</table>

<hr />

<table style="height: 238px;" width="833">
<tbody>
<tr>
<td style="text-align: center;" colspan="5"> <strong> Algorithm complexity:  </strong></td>
</tr>
<tr>
<td></td>
<td>Worst Case</td>
<td>Average Case</td>
<td>Best Case</td>
<td>Space Complexity</td>
</tr>
<tr>
<td>Quicksort</td>
<td>O(n2)</td>
<td>O(n log(n))</td>
<td>O(n log(n))</td>
<td>O(log(n))</td>
</tr>
<tr>
<td>Mergesort</td>
<td>O(n log(n))</td>
<td>O(n log(n))</td>
<td>O(n log(n))</td>
<td>O(n)</td>
</tr>
<tr>
<td>Heapsort</td>
<td>O(n log(n))</td>
<td>O(n log(n))</td>
<td>O(n log(n))</td>
<td>O(1)</td>
</tr>
<tr>
<td>Bubble Sort</td>
<td>O(n2)</td>
<td>O(n2)</td>
<td>O(n)</td>
<td>O(1)</td>
</tr>
<tr>
<td>Insertion Sort</td>
<td>O(n2)</td>
<td>O(n2)</td>
<td>O(n)</td>
<td>O(1)</td>
</tr>
<tr>
<td>Selection Sort</td>
<td>O(n2)</td>
<td>O(n2)</td>
<td>O(n2)</td>
<td>O(1)</td>
</tr>
</tbody>
</table>

Source: <a href="https://howtostartprogramming.in/category/algorithm/" rel="dofollow">Java Algos</a>
<hr />
Ever forget media query syntax?
Tags: frontend, css, mediaqueries, sideprojects
Published: 2022-08-14 16:49:20

I sure do and to combat there being simply too much in the web dev world for one person to remember to remember, I mixed up this little site over the weekend as somewhere to quickly grab that syntax.

It's not meant to be an exhaustive list, just a handful of media queries that I come across day-to-day 😁

Maybe others will find it useful too🙏

✨ [https://mediaquery.style/](https://mediaquery.style/) ✨
What The Hell is COW?
Tags: computerscience, codenewbie, cpp, java
Published: 2022-08-14 16:28:27

### By Jayanti Goswami

Some of you might have seen our poster for Crazy COW. Sounds kind of amusing, does it not?


![Crazy COW competitive coding](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fpm3uzsrdlal06bpuih1.png)

Well, COW stands for Coder of the Week. 

It is a new contest for all of you guys who might be interested in competitive coding. This weekly contest will be held on our [Discord server](https://discord.gg/nyHHW5nmVp). 

Read on to find out more details.

## The Rules of the Contest

1. _Everyone participating has to join a voice channel at a specific time on Friday._ The time will be mentioned on our Discord server and may change by an hour or so every week.
![Discord vc](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/prooo4gy8y9pa3o5d8nc.png)
 
2. _The question will be posted in contest alerts._ You get one hour to solve it independently. 
![Contest alerts](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dcopvh4i7c648vdqx00j.png)
 
3. _There is no specific language._ All languages allowed by the site that the question is from are accepted by us. So, solve it in whichever language you are most comfortable with. 
![Competitive programming languages](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tzaqjvpn9bo6rl8movyz.png)
  
4. At the end, one winner will be chosen. The criteria for winning in order of preference is:
    - All test cases passed.
    - Most test cases passed.
    - Least time taken.

This winner will be crowned **Crazy COW**!

## The Perks that Crazy COW gets

The Crazy COW gets three huge perks:

- Their name will be displayed above everyone else until the next competition. 
- They get a shiny Crazy COW badge that they can show off on any social media platform :)
- They get to choose the question for the next week's competition and crown their successor!

![Crown Crazy COW](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mk1piw3u7vn3pq1ccmpf.png)
 

## How to practice

If you really wanna win but are in desperate need of practice, we have you covered. Every day, except Friday, a question will be posted on the contest alerts and you get 12 hours to solve it and discuss with others. 

So, don't worry about being out of touch. Just practice with us. 

And if you are not sure about how to get started, just take a look at [Sam's blog](https://dev.to/crazycodigo/a-beginners-guide-to-competitive-coding-1009). It is sure to help.

## Wrapping up

If you are not in our Discord server yet, what are you waiting for? [Join us](https://www.youtube.com/watch?v=_nNw08y1RkM), participate, and become the Crazy COW! 

It is the coolest title of all time. Sources? Trust me bro. 

First competition: 19 August, 2022
Cya there!

~ J
Latest Python installation instructions for Windows 11
Tags: python, installation, windows
Published: 2022-08-14 16:19:23

Step 1: Download the Latest Version Of Python for Windows 11
 
1) To begin, we must obtain the most recent Python version available on the internet. Follow the downloading link provided below to be routed to the official Python downloads website. There, click the yellow download button to begin downloading Python.

Download Python Here:  https://www.python.org/downloads.

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

2) When your download is complete, open it in the location where it was saved and double-click on the downloaded ".exe" file. If a little pop-up displays, click "yes" to begin the Python installation procedure.


Step 2: Install Python in Windows 11
 

1) Then, in the Python installation process, select "Customize Installation."
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vcq3x2skj9ujwghznfa8.png)
 

2) Now a popup with optional options will display; check all of the boxes and click next.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ui83ozr06n0cu018s6aq.png)

3) Check the first five boxes on the Advanced Options page, as seen in the image below.
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fep6osrtglysycm3hsxw.png)

 

4) Then, in the small text field, add "C:Python310" and click the install button.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/glov0mdwy3vsx53ad95y.png)
 
 

> Please keep in mind that "Python310" is the name of the installed Python folder, so if you download a different version of Python, the folder name may differ.

5) Now your Python installation will begin; after finished, click the close button.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lts6715tdl0tr1arbjr2.png)
 
Step 3: Verify Python Version
 

1) To launch your command prompt, click on the Windows icon, type "command prompt" in the search field, then hit enter.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vl4xksrhgmk4dskkyveq.png)
 
 
2) In the command prompt, type "python" and press enter; if you see something similar to the image below, you've successfully installed Python on your Windows 11 Device. 🎉🎉
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xekq4qtvxsh9so0vfe67.png)
Console Wrangling
Tags: javascript, webdev, beginners, programming
Published: 2022-08-14 16:15:05

## Have you ever console logged the console?


![Thanos console](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ihj627kwiml7gk0gqo80.jpg)

So you know the good ol’ `console.log()` ? 

Well, that’s not the only thing the console can do, it’s only the most basic. 

Have you ever used the console to log the console? No? You should try it. 

The console will show you what the console can do.


![console console](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0q4ve5ihlkpof7x4q5bj.png)

Today we’ll talk about two of the functions available on the console object:

`console.table()` and `console.trace()`

Lets say we have two objects:

```jsx
const carA = {make: 'Ford', model: 'F150', year: '2018', color: 'white'}
const carB = {make: 'Ford', model: 'F250', year: '2016', color: 'blue'}
```

If we wanted to do some debugging and had to print these objects out to the console we could use `console.log()` but it wont look too nice.

Look how neat `console.table()` can display the two objects:


![console table](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bs04i5n1ekoact10x5fb.png)

You can even sort the two rows by column just by clicking on the headers!

One other console function we’ll talk about today is `console.trace()`. This will output a stack trace to the console.


![console trace](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ag4apxwdgre4514w38l9.png)

And that’s all for today.

I hope I’ve helped make your debugging a little less boring. Now go show off your new console skills in your next stand-up.

Cheers!
5 extraordinary skills for freshmen
Tags: top5skills, collegeskills, career
Published: 2022-08-14 15:57:00

Hey you, welcome to my blog and without any further ado, let's discuss about the top skills you can learn to that 'extra' in your first year of college life.

- Web Development : 

This is the most popular skill that comes in the mind of the freshman students. This skill requires no prior experience and is fun to learn. I would suggest you to follow a roadmap and make as many projects as you can. Youtube is the best learning resource for this skill.

- Video Editing : 

This is an evergreen skill which is in high demand in the market. Currently the video industry is booming and will continue throughout many years ahead. Udemy and skillshare are great place to explore and learn this skill.

- Graphic Designing : 

Learning this is a personal choice. If you believe that you have good design sense and nice drawing skills then trying it hands-on is a good move. Again, Udemy and Skillshare are one-stop solution to learn this skill.

- Automation : 

This is a very rare skill but a fun-to-do skill. Also, if you manage to create an amazing automation flow then you won't need to work throughout your life. Learning this skill is very easy but you need to be very creative to get the best out of this skill. There is no specific resource for learning this skill.

- Content Creation : 

This is a very good way to express yourself. Moreover, it can help you overcome your introvert nature. And if everything goes well then in no time, success will kiss your feet.



So these were the five skills for freshmen which can make you standout in the crowd.
If you liked this blog and want to read more of them, do let me know in the comments or mail me directly at [thisisvaib@gmail.com](mailto:thisisvaib@gmail.com)
What is Bubble Sorting?
Published: 2022-08-14 15:48:02

This is a comparison sorting algorithm that works by swapping the adjacent elements until they are in the correct order. This algorithm does not have a good performance and is not scalable. It is not often used but is a good introduction to learning about algorithms.

For example, in array [1,3,2,4] the algorithm would compare the first two numbers and since 1 < 3, nothing changes. Our array stays the same [1,3,2,4]. However, it then goes on to compare the next two numbers and since 3 > 2, it swaps them. Our array now looks like this [1,**2**,**3**,4]. It proceeds to compare our last two numbers but since 3 & 4 is in the correct order, nothing changes. The algorithm does another full pass of these numbers to make sure there isn't any more sorting to be done.

This is just for a simple 4 numbers. If there are more swaps to be made, it will keep going back over the list until there is no longer a swap. This can easily get out of hand with a large amount of elements in a list. And the more elements, the worse the performance.

Trying to make this work in a programming language on a small scale would be good practice for any language. 

For further research you could include other algorithms, as well as tradeoffs for each (such as performance). Learning about "Big O Notation" will also help you identify best algorithms by performance.
Kotlin Springboot -- Part 01 "/" へのアクセスで template に値を渡してブラウザで表示する Controller を作る
Tags: kotlin, springboot, thymleaf
Published: 2022-08-14 15:30:00


## why

Kotlin x Springboot のことよく知らない。
仲良くなりたかった

----

## 何をするのか

https://spring.io/guides/tutorials/spring-boot-kotlin/

この記事を参考にコントローラーを書いて
ビュー相当の HTML に渡してみてみる。

---

## HtmlController を作成して index に値 title を渡す

コントローラーはなんて名前にしても中身の GetMapping が全てビルド時に読み込まれると解釈した。

プロジェクトの最初に作成された SpringbootApplication.kt と並列に

HtmlController.kt を作成する。

中身にこれを書く。

```kotlin
package com.example.springboot

import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.ui.set
import org.springframework.web.bind.annotation.GetMapping

@Controller
class HtmlController {
    @GetMapping("/")
    fun nanika(model: Model): String {
        model["title"] = "SpringBlog"
        return "index"
    }
}
```

namespace 相当の package を最初に書いて

Controller として使うため の stereotype.Controller 
変数を HTML に渡せる形にするための型の ui.Model
model に中身をセットするための ui.set
大事な GetMapping を動かす為の web.bind.annotation.GetMapping

これらを import して
SpringBlog という文字列を model 型にして
index のテンプレートに渡す。

https://speakerdeck.com/otty375/architecture-of-spring-mvc?slide=20

このスライドにも説明が有る

https://speakerdeck.com/otty375/architecture-of-spring-mvc?slide=39

addAttribute でも渡せるらしい。

---

## templates/index を作成して渡された値の title を表示する

https://speakerdeck.com/otty375/architecture-of-spring-mvc?slide=28

Model を参照してレスポンスデータの生成を行っている。

https://qiita.com/takkii1010/items/c9f83966f9088923a6e7

thymleaf はこうやって書く。

そして最初からできている resource/template に
index.html を作成して

```html
<h1>springboot kotlin sample</h1>
<h2 th:text="${title}" />
```

h1 で普通のテキストと
h2 に th:text でコントローラーから受け取った値を出す
bash みたいな変数の入れ方。

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

するとローカルホストで中身が見える。

---

## まとめ

コントローラーを作って、内部に Getmapping で
アクセスされたルートに関数をマッピングして

関数内部で値を model 型にしてテンプレートに渡す

そしてテンプレートで表示する

これでルーティングと、コントローラーから渡された値の表示ができる。 

main から呼び出す必要は一切なかった。