teleren/devto huggingface dataset:
2D Array - HackerRank JavaScript Solution
Tags: javascript, tutorial, programming, algorithms
Published: 2022-02-23 13:20:43

Given a _6 X 6_ Array _arr_:

```
1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
```
An hourglass in _A_ is a subset of values with indices falling in this pattern in _arr_'s graphical representation:

```
a b c
  d
e f g
```
There are _16_ hourglasses in _arr_. An hourglass sum is the sum of an hourglass' values. Calculate the hourglass sum for every hourglass in _arr_, then print the maximum hourglass sum. The array will always be _6 X 6_.

### Example
_arr =_
```
-9 -9 -9  1 1 1 
 0 -9  0  4 3 2
-9 -9 -9  1 2 3
 0  0  8  6 6 0
 0  0  0 -2 0 0
 0  0  1  2 4 0
```
The _16_ hourglass sums are: 
```
-63, -34, -9, 12, 
-10,   0, 28, 23, 
-27, -11, -2, 10, 
  9,  17, 25, 18
```
The highest hourglass sum is _28_ from the hourglass beginning at row 1, column 2: 
```
0 4 3
  1
8 6 6
```
### Function Description

Complete the function hourglassSum in the editor below.

hourglassSum has the following parameter(s):
- int arr[6][6]: an array of integers

### Returns
- int: the maximum hourglass sum

Input Format
Each of the _6_ lines of inputs _arr[i]_ contains 6 space-separated integers arr[i][j].

### Solution
```js
function hourglassSum(arr) {
    // Write your code here
    let maxSum = ''
    for (let step1 = 0; step1 < arr.length-2; step1++){
        for (let step2 = 0; step2 < arr.length-2; step2++){
            const currentSum = arr[step1][step2] + arr[step1][step2+1] 
         + arr[step1][step2+2] + arr[step1+1][step2+1] 
         + arr[step1+2][step2] + arr[step1+2][step2+1] 
         + arr[step1+2][step2+2]
            
            if(currentSum <= 0){
               const temp = currentSum
               if (typeof maxSum == 'string' ){
                   maxSum = temp
               } else if(temp == 0 && maxSum <= 0){
                   maxSum = temp
               }
                else if(temp > maxSum){
                   maxSum = temp
               }
            } else if(currentSum > maxSum){
                maxSum = currentSum
            } 
        }
    }
    return maxSum
}
```
Connecting to Multiple Databases in Laravel
Tags: laravel
Published: 2022-02-23 12:47:42

Laravel is a powerful PHP framework that makes it easy to manage your web application's database connections. In this tutorial, we'll show you how to set up multiple database connections in Laravel and how to switch between them on the fly.

##Replicating Your Database in Mariadb

The first step to connecting to multiple databases in Laravel is to replicate your database in Mariadb. This will allow you to have a read-only copy of your database that can be used to offload some of the read-heavy workload from your primary database server.

To set up database replication in Mariadb, follow these easy steps (taken from [mariadb-replication-easy-step](https://hevodata.com/learn/mariadb-replication-easy-steps/#Method1)):

1. Make sure that Mariadb is installed on your server.
2. Create a new database on your primary server and grant access to it for the replication user.
3. On the secondary server, create a new database and grant access to it for the replication user.
4. On the primary server, run the following command to set up the replication:
    ```sql
    CHANGE MASTER TO MASTER_HOST='secondary_server_ip', 
    MASTER_USER='replication_user', 
    MASTER_PASSWORD='replication_password', 
    MASTER_LOG_FILE='primary_server_bin_log_filename', 
    MASTER_LOG_POS=primary_server_bin_log_position;
    ```
5. Start the replication on the secondary server by running the following command:
    ```sql
    START SLAVE;
    ```
Your database should now be replicating from the primary server to the secondary server.

##Setting Up Laravel to Connect to Multiple Databases

Now that your database is replicated in Mariadb, it's time to set up Laravel to connect to multiple databases.

To do this, open the config/database.php file and add the following code (as described in the [Read & Write Connections](https://laravel.com/docs/5.6/database#read-and-write-connections) documentation):

```php
'mysql' => [
    'read' => [
        'host' => [ '192.168.1.1', '196.168.1.2' ],
    ],
    'write' => [
        'host' => ['196.168.1.2'],
    ],
    'sticky'    => true,
    ...
],
```

This code tells Laravel to use the `read` connection for read-only queries and the `write` connection for all other queries.

##Checking Which Database Server Laravel is Connected To

To check which database server Laravel is currently connected to, you can use the following code:

```php
Route::get('/mysql-test', function () {
  $places = App\Place::all();
  $results = DB::select( DB::raw("SHOW VARIABLES LIKE 'server_id'") );  
  return "Server ID: " . $results[0]->Value;
});
```

This will display the server ID of the database server that Laravel is currently connected to.

And that's it! You now know how to set up multiple database connections in Laravel and switch between them on the fly. 

Happy coding!
Five Year Club at dev.to
Tags: discuss, career, blogging, devto
Published: 2022-02-23 13:05:38

---
title: Five Year Club at dev.to
published: true
description: Today marks 5 years of me being on dev.to
tags: discuss, career, blogging, devto
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/txwjv8jebfu8bmxuy295.png
---

## TL;DR
Today marks 5 years of me being on dev.to. In general, I gotta say that I like the community (I just got this nice badge, so what's not to like 🙂), and wish to be on the platform 5 years from now too.

## Stats
I like stats (and working towards improving them), so I'll share my stats from these 5 years:

- Posts: `92`
- Total post reactions: `847`
- Total post views: `273,102`
- Followers: `2895`
- Following users: `36`

## Top 5 most viewed blog posts
- [Making AJAX calls in pure JavaScript, the old way](https://dev.to/nikola/making-ajax-calls-in-pure-javascript-the-old-way-ed5) - 93k views
- [How to make a native Android app that can block phone calls](https://dev.to/nikola/how-to-make-a-native-android-app-that-can-block-phone-calls--4e15) - 24k views
- [Git branching done right with Gitflow & improving code quality with code reviews](https://dev.to/nikola/git-branching-done-right-with-gitflow--improving-code-quality-with-code-reviews)  - 19k views
- [JWT authentication in an Angular application with a Go backend](https://dev.to/nikola/jwt-authentication-in-an-angular-application-with-a-go-backend--13cg) - 16k views
- [How to get started with Ionic framework 3 on Mac and Windows](https://dev.to/nikola/how-to-get-started-with-ionic-framework-3-on-mac-and-windows) - 12k views

## Personal favorites that, IMHO, could use a bit more view-love
- [Learn Git fast as if your job depends on it](https://dev.to/nikola/learn-git-fast-as-if-your-job-depends-on-it-dgj) - 12k views
- [How to 'make it' as a remote developer?](https://dev.to/nikola/how-to-make-it-as-a-remote-developer-4bii) - 273 views
- [Too many books, not enough time](https://dev.to/nikola/too-many-books-too-little-time-1df1) - 237 views

## Daily-Thought Series
Recently, I started a new [daily-thought series](https://dev.to/t/improvement) where I post a tweet-like tiny blog post entry every day. The post that got the most exposure in that series was [Knowing != Doing](https://dev.to/nikola/knowing-doing-3j6p). Please feel free to check out the rest and chime in on the discussion.

## Learnings
I shared a bunch of [learnings](https://www.nikola-breznjak.com/blog/miscellaneou/writing-300-posts-think-start-blogging/) from when I published my [300th blog post](https://www.nikola-breznjak.com/blog/miscellaneou/writing-300-posts-think-start-blogging/) on my blog.

One thing that still holds to this day is the consistency. What you're consistent with, you will improve.
Gitsasters, or going back in time 🕰️
Tags: git, tutorial, beginners, programming
Published: 2022-02-23 13:02:29

My colleague/friend wrote an insightful piece on overcoming git disasters, or as we refer to them, gitsasters. I thought to give a high-level summary and [invite you to check out real-life instances where the git reset tool comes in handy](https://swimm.io/blog/rewriting-history-and-overcoming-git-disasters-gitsasters-part-1-git-reset/). 

## What is a gitsaster? 
Understanding the concept of git can actually help you know when things go wrong. For example, when you do something you didn't mean to do and just want to go back in time- this is precisely what a gitsaster is. 

Things go wrong in git all the time. There are people like myself who understand what's happening underneath the hood and thus remain calm. 

But, what about those who don't have as deep an understanding? They tend to look at git like a magical black box. 

## Recording changes in git
I don't think a few sentences can give this topic justice. [This article](https://medium.com/swimm/a-visualized-intro-to-git-internals-objects-and-branches-68df85864037) provides a thorough overview on recording changes in git. 

But to sum it up: git doesn't commit changes directly from the working tree into the repository. Changes first get registers in the index/"staging area". You can think of the index as a way of “confirming” your changes before doing a commit. 

##The command git reset, together with its three modes:

- --soft, that moves whatever HEAD is pointing to
- --mixed, that goes on to update the index to what HEAD is pointing to after the soft step
- --hard, which updates the working dir to match the state of the index
What is a difference between TTK & TKINTER
Tags: ttk, tkinter, python
Published: 2022-02-23 13:02:16

Hello everyone, I hope you are well. Today we came to tell you the difference between ttk and tkinter.First let's see what a tinker is.
Tkinter is a module used in Python to create graphic applications.
And you can use its interesting features in the  module, such as making buttons, entry, etc….Tkinter has many great features, but all the features of this module are very old. Now we can use the features of this module to be very new and modern, using ttk.
lets see this difrense with image:

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





 Don't forget to follow my channel
I'm starting a #100DaysOfCode Challenge
Tags: javascript, webdev, career, 100daysofcode
Published: 2022-02-23 12:58:12

## Introduction
I was trying to complete the #100DaysOfCode but always failed in the first two weeks. I just realized the problem of why I was inconsistent for the reason that I was lost on the track! I don't know which topic should I study and that did not give me enough motivation to keep up with it.

In order to be seriously committed and stay motivated is to know where to go. I need to have a plan of what I study in the first 100 days.

## Rules
I'm still following the two main rules of #100DaysOfCode, but I need to add some additional rules with it, which is I will mention below.
- Code minimum an hour every day for the next 100 days.
- Tweet your progress every day with the #100DaysOfCode hashtag.
but, 
- **Report the progress by writing an article on Dev.to, Weekly.**
- Update daily progress in my repo.
- **Challenge can only be skipped 2 days a week.**

## Things I need to learn
I want to have a solid understanding of computer science at a low level instead of just learning frameworks without knowing the design.
1. [CS50X Course](https://cs50.harvard.edu/x/2022/)
2. [Software Architecture & Design Patterns](https://www.udacity.com/course/software-architecture-design--ud821)
5. [Highschool Math and Linear Algebra.](https://www.khanacademy.org/)
4. Vue JS or React JS

## What I expect after completing the challenge
I am expecting to have a better understanding of Software Development. I hope I can start a project systematically from scratch at a low level up to a higher level with a basic understanding of Architecture, algorithms, and math.
What We Love About Web Development
Tags: webdev, podcast
Published: 2022-02-23 12:56:31

{% spotify spotify:episode:6C2TTUv2iw3YY8ZA2wRZL0 %}

## What is HTML All The Things

HTML All The Things is a [web development podcast](https://www.htmlallthethings.com/) and [discord community](https://discord.com/invite/jweMCx9) which was started by Matt and Mike, developers based in Ontario, Canada. 

The podcast speaks to web development topics as well as running a small business, self-employment and time management. You can join them for both their successes and their struggles as they try to manage expanding their Web Development business without stretching themselves too thin.

## Announcements

The **Svelte for Beginners** Udemy course is now live! Mike took his experience in teaching and learning Svelte and created a course. 

This course will teach you the fundamentals of JavaScript frameworks. 

**Get it now on Udemy!** 👇

[Svelte For Beginners](https://www.udemy.com/course/svelte-for-beginners/?couponCode=HATTSALE)

## What's This One About?

Web development has a lot of love, hate, and everything in between. In this week's episode, Matt and Mike try and focus on the love and talk about all the things they love about web development...for the most part - sometimes some of the other sides and realities of web development hijack the conversation, but tangents should be no stranger to listeners of this show.


## Show Notes

* Creating
  * Ability to express art
  * Instant gratification
  * Animations
* Challenge
  * Constantly have to learn new techniques, methods and technologies
* Community
  * People willing to help each other
  * Sharing resources and knowledge
* Abundance of resources
  * Courses
  * YouTube tutorials
  * Blogs
* Frameworks/libraries
* Ability to work from anywhere in the world
* Trying out new frameworks and libraries
* Mentoring


## Thank you!

If you're enjoying the podcast consider giving us a review on [Apple Podcasts](https://podcasts.apple.com/us/podcast/html-all-things-web-development-web-design-small-business/id1412209136) or checking out our Patreon to get a shoutout on the podcast. 

**[Support us on Patreon](https://www.patreon.com/htmlallthethings)**


You can find us on all the podcast platforms out there as well as

[Instagram (@htmlallthethings)](https://www.instagram.com/htmlallthethings/)
[Twitter (@htmleverything)](https://twitter.com/htmleverything)
[TikTok (Html All The Things)](https://www.tiktok.com/@htmlallthethings)
Listen to any article on web with few lines of Python.
Tags: python, machinelearning, beginners, programming
Published: 2022-02-23 12:49:48

Implement your own Listen to article feature for any web article, similar to the Medium’s Listen feature. Turn any article, from your favorite websites, into a mini podcast that you can listen to while doing chores, working out or commuting.

This might seem like a complicated project, that would require a lot of development, but with the ease of use of Python, its libraries and machine learning API for text to speech synthesis, we can hack together a simple MVP with just few lines of code!

Read along for step by step instructions or get the [code here](https://gist.github.com/kristian-io/b2c4cc1d3c1583ffe92062a5c559bbfd).

Let’s start, shall we ?

## Ingredients:

- python
- free API key
- **good mood :)**

## Plan:

1. Download article from the web and parse it to extract the title and text.
2. Turn text into speech audio.


For downloading article and extracting title and text we will use popular Python library [newspaper](https://newspaper.readthedocs.io/en/latest/). We will also install library [requests](https://pypi.org/project/requests/) for making API requests and import them.


![install libraries and import them](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0dy06lgudbzdjuf1h5l6.png)

We define the article we want to turn into our audio file and name it. Also, we set our API key, [get it here for free](https://rapidapi.com/k_1/api/large-text-to-speech/), which we will need later. Now, we can download the article and combine title with text.


![setup and article download](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/we24mym1xmc2y9e8cx6z.png)

**We are halfway done!**

We can now use [Large text to speech API](https://rapidapi.com/k_1/api/large-text-to-speech/) to turn our text into human like audio.


![API post request](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qk4jer2l2erb7oe2j546.png)

Depending on the article length we need to wait for some time for the synthesis to finish, estimate of this time is conveniently returned in the response of our request.

Let’s get our results now.


![API GET request](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rtkkguebfg47ih1zzb08.png)

That’s it! You should have your file, which we called article.wav in the same folder as your python script.

There are obviously other things we could implement, getting more articles and creating a podcast, especially if your commute is going to be long!

Feel free to experiment with the code and let me know in the comments or 👋 [tweet at me](https://github.com/kristian-io).

Download the [full code here](https://gist.github.com/kristian-io/b2c4cc1d3c1583ffe92062a5c559bbfd).
5 Articles every WebDev should read this week (#08)
Tags: webdev, tutorial, javascript, programming
Published: 2022-02-23 12:42:47

A curated list of the top five web development must-reads from last week. Don't miss out on the latest web development stories and insights. Read all about the cutting edge in web development, working in tech and the new tools and frameworks while learning a few new tricks.

---


## State of JavaScript 2021

> The 2021 State of JS survey ran from January 13 to February 2 2022, and collected 16,085 responses. It was created to identify upcoming trends in the web development ecosystem in order to help developers make technological choices. As such, these surveys are focused on anticipating what's coming over the next few years rather than analyzing what's popular now, which is why the features or technologies that are currently most widespread are not always included. They should also be taken as a snapshot of a specific subset of developers, and are not meant to speak for the entire ecosystem.

<https://2021.stateofjs.com/>

---

## Comparing Node JavaScript to JavaScript in the Browser

> If you’ve mainly written JavaScript that runs in the browser and you’re looking to get more of an understanding of the server side, many articles will tell you that Node JavaScript is a great way to write server-side code and capitalize on your JavaScript experience.

<https://css-tricks.com/node-javascript-compared-to-javascript/?utm_source=ESnextNews.com&utm_medium=Weekly+Newsletter&utm_campaign=2022-02-22>

---

## The Basics of Package.json

> In this chapter, we'll give you a kickstart introduction to effectively using package.json with Node.js and npm.

<https://nodesource.com/blog/the-basics-of-package-json>

---

## Hello, CSS Cascade Layers

> One of the most common causes of confusion in CSS is facing specificity while writing styles. For example, changing the display value for an element never works because another element in the cascade overrides it due to having a higher specificity. Or when another element has !important That usually happens when the codebase is growing and we’re not organizing CSS in a way that prevents (or reduces) such problems.

<https://ishadeed.com/article/cascade-layers/>

---

## Inside look at modern web browser (part 1)

> In this 4-part blog series, we’ll look inside the Chrome browser from high-level architecture to the specifics of the rendering pipeline. If you ever wondered how the browser turns your code into a functional website, or you are unsure why a specific technique is suggested for performance improvements, this series is for you. As part 1 of this series, we’ll take a look at core computing terminology and Chrome’s multi-process architecture.

<https://developers.google.com/web/updates/2018/09/inside-browser-part1>

---
 
Follow me on [Twitter: @martinkr](http://twitter.com/_martinkr).

Photo by [Alex Kulikov](https://unsplash.com/@burntime) on [Unsplash](https://unsplash.com)

---

[![Subscribe to the weekly modern frontend development newsletter](https://modernfrontend.dev/banner/banner_583-111.png)](https://modernfrontend.dev/)

---
Virtual Event Features Essential to an Auto Expo
Tags: mixhubb, webdev, beginners, wordpress
Published: 2022-02-23 12:42:16


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

If you are planning to host your first auto expo virtually, you must be wondering what are the specific features essential to an auto expo.
More Details @ https://techmore.org/virtual-event-features-essential-to-an-auto-expo/
The “Either” Issue
Tags: career, politics, capitalism
Published: 2022-02-23 12:36:32

[Either]: https://www.scala-lang.org/api/current/scala/util/Either.html
[kodumaro]: https://kodumaro.cacilhas.info/2022/02/either-issue.html
[scala]: https://scala-lang.org/


![Lamp](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hubab6f6xlfwnwq8arv8.png)

Original post on [Kodumaro][kodumaro].

Once I was running an operation, and my team had to build the application from scratch.

I had met the core developers, we had discussing a lot about which technology would better address our demand and, after many considerations, we had chosen [Scala][scala].

**But** (and there’s always a *but*) Scala programmers are expensive, and the company wanted to save every cent (as always).

So the company hired Java programmers (cheaper than Scala) and ordered us to train ’em.

So far, so good – but (another *but*) try to build from scratch a big and complex system, containing lots of interrelated nodes with countless interactions, and unpredictable corner cases – with a team that has **no experience** on the technology!

Well… the first problem we have gotten was the [`Either` construct][Either].

I usually use `Either` to transport an error using its left side, leaving the right side for the success result. It’s a common approach.

However it must be done with caution, one cannot simply put `Either` in every function return; and there’s no rule to set it, one needs some *feeling*, intuition, which is earned from the experience.

As expected, the base programmers took my code as *written-on-rock* rules, once they had no other reference to follow, and they saw me using `Either` in some functions, so they started to use the same approach… **everywhere**.

It put the project in real trouble: many errors were lost silently, other ones were raised a far cry from where it should’ve been caught – thanks to Scala, the stacktrace was carried along, but even so it used to be hard to debug.

The core team and I weren’t enough to review every <abbr title="Pull Request">PR</abbr> with the required attention, worse ’cause it’s a very subtle and hard-to-catch issue.

After a while, I had to spend a long time cleaning the code: removing the `Either` from returns, and catching errors. It was necessary, but awful for the team morale.

The team wasn’t to blame, they were doing what was expected; but the company should’ve invested more in hiring qualified professionals and in qualifying the newbies.

Unfortunately the Capitalism is about profit, not quality, getting the employees to that kinda highly uncomfortable situation.