teleren/devto huggingface dataset:
Day 4 I4G Code Challenge
Tags: leetcode
Published: 2022-09-24 22:30:34

Day 4!!!! Yay
Today's problem is interesting and challenging as well Javascript is not included in the programming language I can solve the problem with. 
So I had to choose another programming language, python is always the next tool to use if Js will not solve my problem
.
The problem statement seems bizarre and a big problem but it's pretty simple and straight forward when you understand the problem.
Problem. Print In order
Tag: Easy
Given three method in a class
class foo():

   firt(self):
     print("first line")
   
   second(self):
     print("second line")
   third(self):
     print("third line")

The task is to modify the above methods such that calling
foo = foo()

foo.first()
foo.second()
foo.third()
//or
foo.first()
foo.third()
foo.second()

//or
foo.third()
foo.first()
foo.second()

Or any permutation of this calls can result in
//first line
//second line
// third line
irrespective of how they are called;


What first come to my mind is to delay third method for some time,delay second method for less time and first method will fire immediately.
So that third will wait for first and second, second will wait for first. 
first fires immediately.
I use python in built time module for that.

[Print Order problem](https://leetcode.com/problems/print-in-order/)

[Code Implementation](https://github.com/ismaelsadeeq/I4G_coding_challenge/blob/main/printOrder.py)
DAY 4 CODE CHALLENGE
Tags: leetcode, challenge
Published: 2022-09-24 22:27:23

## **PRINT IN ORDER**
Todays challenge was a very daunting one, I migrated from JavaScript to Python3 because of the  unavailability of 'print in order' LeetCode problem in JavaScript version. Having started my coding career with python before I drifted to JavaScript I was able to scale through this challenge.

**QUESTION**
Suppose we have a class:
`public class Foo{
public void first() {print("first");}
public void second() {print("first");}
public void third() {print("first");}
}
`
Here, Foo will be passed to three different threads:
Thread A = first()
Thread B = second()
Thread C = third()

**TASK**
Design a mechanism and modify the program to ensure that the second() is executed after the first() and the third is executed after the second().

**PROCEDURE**
Lock method was applied to solve this problem. I started with two locked locks, whereby first thread unlocks the first lock that the second thread was waiting on while the second thread unlocks the second lock that the third thread was waiting on

**OUTCOME**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m3aviaw214vqpvwwocqj.PNG)
Print in Order
Tags: beginners, algorithms, python
Published: 2022-09-24 22:01:14

It's day four already💃🏽. Today's challenge was on printing in order. Basically, the challenge was about synchronisation. It involved designing a mechanism and modifying the program to ensure that second() is executed after first(), and third() is executed after second().


I used the locking tool of the threading module in python which was a new concept I just learnt.

Locks are a synchronisation tool included in the Python threading module. Locks exist in two states:

- Locked
- Unlocked

With the use of the acquire() method, a lock can be locked. All additional attempts to acquire the lock are prohibited once a thread has already gained it until it is released. The release() method can be used to release the lock.

The syntax was to release the first thread and lock the other two. Once the first thread has been executed it is locked and the sequence repeats till all the threads have been executed.

It was a fun challenge to execute overall.

Thank You❤️
Using AdSense Ad Units in Next.js
Tags: nextjs, javascript, webdev, programming
Published: 2022-09-24 21:58:55

## Overview

My blog is built from `tailwind-nextjs-starter-blog`, which you can find [on GitHub here](https://github.com/timlrx/tailwind-nextjs-starter-blog). It makes for a very quick start to a blog and is well architected.

Although it came directly with Google Analytics, it didn't provide any existing infrastructure for AdSense, so I figured I'd document my trials and tribulations getting it working.

*I work for [Akkio](https://akkio.com), where I'm building out a no-code predictive AI platform. If you're looking to harness the power of AI without needing a data scientist, give us a try!*

## What To Do

### 1. Get your site correctly linked to AdSense

Before you even get the code, you'll need to make sure your site is AdSense-ready. You may need to put a script into your header, or add a meta tag to your head - the site should walk you throguh it. You know you're set whenever the "Sites" menu in the AdSense dashboard shows your site as "Ready".

### 2. Overall AdSense Header

Go to "Ads" in the AdSense dashboard, then hit the "By ad unit" header. Create the one you like, then it'll provide you code. You need to copy the first script tag into your header, which looks something like this:

```html
<script
  async
  src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7827406820675555"
  crossorigin="anonymous"
></script>
```

Note that ` crossorigin` will likely need swapped to `crossOrigin`; my code editor has unfortunately decided to automatically format it back to all lowercase on save.

### 3. Individual Ad Units

Insert the following code wherever you need an ad unit:

```html
<ins
  class="adsbygoogle"
  style="display:block; text-align:center;"
  data-ad-layout="in-article"
  data-ad-format="fluid"
  data-ad-client="ca-pub-ADSENSE_ID"
  data-ad-slot="SLOT_ID"
></ins>
<script>
  ;(adsbygoogle = window.adsbygoogle || []).push({})
</script>
```

The script tag essentially signifies to AdSense that there's one more ad unit on the page. AdSense will give you values for all of these, it's mostly just copy-paste.

## Common Issues

### 403: Forbidden

I ran into this error because I was on localhost. AdSense won't work on localhost, because it's not the same as the full site URL you need to add to your AdSense account as part of the update process. You shouldn't get this error on the actual live version of your site.

If you see `push() missing an argument` or similar, I believe it was also due to this.

### Window Dimensions Not Working

Google AdSense switched to fully responsive ads at some point, so it will automatically resize to fit the width of the container. Make sure your container has more than 250px width and height.
HTML 101- Semantics
Tags: html, webdev, opensource
Published: 2022-09-24 21:41:54

**What are HTML Semantics?**

HTML semantics provide meaning to a HTML page, which clearly define the content they hold.

**Why do we need HTML Semantics?**

1. Provides higher accessibility.
2. Helps the browser to better interpret the content.
3. Semantics help to write clearer code which is easier tom maintain.
4. Pages made with semantics are easier to render and also avoid the problem of div suites.

**Different types of Tags- When and How to use?**

`<section>` :- Used when grouping large content together under a common heading. Refers to a section of a page.

`<article>` :- Used for holding content that is independent from rest of the website. Example- Blog posts, Newspaper articles etc

`<header>` :- Used for representing heading, navigation links , logos or icons, company name, search feature, and possibly the global navigation. Generally located at the top of the page.

`<nav>` :- Used for representing navigation links. Navbar of the page should be written inside the tag.

`<aside>` :- Used for placing content in sidebar. Can include heading tags (`<h1>` - `<h6>`) and `<p>` tags inside.

`<figure>` :- Used for content like photos, illustrations, svgs, diagrams etc. `<figure>` tag can contain `<img>` tag.

`<footer>` :- Used for defining footer of page. can contain contact information, site maps etc.
How to Survive a Coding Bootcamp
Published: 2022-09-24 21:28:20

In the world of programming a common thing here is coding bootcamps. They are programs that can take anywhere from 15-17 weeks to complete and they are usually high stress with long hours. That means losing sleep and a decline in health right? Well not exactly. It can be that way but it doesn’t have to be. I know we are given all of these different resources that we are supposed to use to help manage stress, but we never get real solutions to the way we feel. We only get wishful thinking and hopes, no results. I’m here to give real solutions to that stress. 

  First up, sleep. It feels like we can never find a time to sleep when we have deadlines looming over us keeping us awake. We know how important sleep is but, how much should we sleep and how can we make that happen when we are programming for 12 hours a day? Well, it’s recommended that we get between 7 to 9 hours of sleep a night. But, when you have to stay up late to finish a project or squeeze in those last few lines of code it can be hard to get 5 or even 3 hours of sleep. The best fix for this I have found is naps, yes you heard me. Naps are a great way to let your mind and body rest. Since they don’t have to be long to be effective you can take a quick nap during a lunch break and get right back into programming feeling fresh.

  Now let's take a look at another huge thing, food. Are we eating enough? It’s really easy to skip meals when you are fixing a bug, or when you’re stuck. But, food is what fuels the brain. So we need to make sure we are eating three meals a day. How can we do this though? We barely have enough time to get work done let alone cook. Well, if you are blessed enough to have a day off during the week I suggest meal prepping. Meal prepping is a great way to make sure you have food to eat during the week! If you don’t have a day off during the week then it may be a little more difficult but I would highly recommend making time to prepare meals for the next few days.

  Finally we have one of the biggest things, mental health. It’s so easily forgotten when we are working. We stop looking after ourselves and then we stop taking care of our basic needs. All of this can make you feel like you are spiraling,like there's not enough time in a day. THe best way I have found to ward off these feelings and thoughts is to make sure my basic needs are met and to take short breaks throughout the day. I can not stress this enough, we can only put out our best work when we are healthy and rested. Taking breaks will help you from burning out and feeling drained.

https://www.sleepfoundation.org/how-sleep-works/how-much-sleep-do-we-really-need#:~:text=National%20Sleep%20Foundation%20guidelines1,enable%20their%20growth%20and%20development.
Use cache-control for API never crash! (ReactJS)
Published: 2022-09-24 21:25:20

Hello guys, today I’m going to talk a little about a nice tip for when you’re using an external API it never crashes, taking down the site where this return is coming from because of several requests made by users who request it in your application.

> When using max-age to set your cache times, you must consider the file type and how it is used. We will discuss this in more detail later in this article.

In this specific project you will understand why we use this method and reasons to still use it when we are using the return of an external API.

We used the cache-control for an API from the TSE — Tribunal Superior Eleitoral to create a webapp of the results of the 2022 elections in Brazil.

As this data will be accessed from several places and the last webapp created in PHP had more than 2 million requests per hour, there was a lot of downtime on the TSE website, thus not returning any data for a period of 1 hour until the website returned to get on the air again (That was a problem for us)

But how did I solve this problem? Very simple after all, as I went from PHP to ReactJS (best thing I did)… Because the code has more techniques of clean, readable code and with a good user experience… Nothing against PHP, but in this project the ReactJS gave 100x0 in PHP.

Returning to the subject, to solve this problem, a normal fetch call was made with the link where the API is returned in JSON and we added a header


`headers: {
“Content-Type”: “application/json”,

“cache-control”: “s-maxage=10, stale-while-revalidate”
}`

you can see in the code or in the photo of how this code was:



![headers-cache-control](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/myyndk497egi07yu0mqz.png)

But why use cache-control in this case?

Remember that we talked about more than 2 million requests in the TSE API?

Well, with the cache control I can set a “maxAge” a maximum age time for the API to return new data saving the ones requested by the user in the cache and request new data only after 10 seconds giving a very foul way A GOOD TIME TO The BREATHE API.

With the stress test, we had a 98% improvement based on the amount of request x data the API returned every 10 seconds compared to the previous project without the cache-control. As a result, the project became more scalable and safer with data handling.
Object level permissions with Hibernate Reactive and Vertx
Tags: java, development, webdev, postgres
Published: 2022-09-24 21:00:58

---
title: Object level permissions with Hibernate Reactive and Vertx
published: true
description: 
tags: #java, #development, #webdev, #postgres
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
---

{% embed https://youtu.be/zyVCOiEFrJ4 %}

In the 5th part of the Hibernate Reactive with Eclipse Vertx tutorial we observe the topic of object level permissions. It is our duty as software engineers to implement strong protection of applications. We need to verify that secured APIs are accessed by authenticated users and also that they could modify only those records that are owned by such users. In order to this we make use of the concept of object level permissions. Object level permissions are used to verify if a user should be allowed to act on a particular object, which will typically be a model instance. This type of protection could be accessed in many popular web frameworks, such as Django , Laravel , Spring Security etc. Vertx does not provide such tool, and in this tutorial we research how to build such functionality.
Relationships with Hibernate Reactive and Vertx
Tags: java, cloud, webdev, database
Published: 2022-09-24 20:59:10

---
title: Relationships with Hibernate Reactive and Vertx
published: true
description: 
tags: #java, #cloud, #webdev, #database
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
---

{% embed https://youtu.be/5kTlgcAI0A0 %}

In the 4th part of my Hibernate Reactive & Eclipse Vertx tutorial, we cover an important topic of relationships. Relational databases, as PostgreSQL or MySQL make use of table relationships in order to store complex data structures. We talk about common types of relationships (one to one, one to many, many to one) and how they are implemented with JPA and Hibernate. We add a new data model to our application and finally we create an integration test to verify that our code does work correctly.
Kubernetes - Variáveis de ambiente
Published: 2022-09-24 20:44:50

Declarando as variáveis diretamente no aquivo yml do Pod:

```
apiVersion: v1
kind: Pod
metadata:
  name: db-noticias
  labels:
    app: db-noticias
spec:
  containers:
    - name: db-noticias-container
      image: aluracursos/mysql-db:1
      ports:
        - containerPort: 3306
      env:
        - name: "MYSQL_ROOT_PASSWORD"
          value: "q1w2e3r4"
        - name: "MYSQL_DATABASE"
          value: "empresa"
        - name: "MYSQL_PASSWORD"
          value: "q1w2e3r4"
```

Criando um serviço de configMap:

```
apiVersion: v1
kind: ConfigMap
metadata:
  name: db-configmap
data:
  MYSQL_ROOT_PASSWORD: q1w2e3r4
  MYSQL_DATABASE: empresa
  MYSQL_PASSWORD: q1w2e3r4
```

## Primeira forma de vincular o pod com as variáveis do configMap:

```
apiVersion: v1
kind: Pod
metadata:
  name: db-noticias
  labels:
    app: db-noticias
spec:
  containers:
    - name: db-noticias-container
      image: aluracursos/mysql-db:1
      ports:
        - containerPort: 3306
      env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            configMapKeyRef:
              name: db-configmap
              key: MYSQL_ROOT_PASSWORD
```

## Segunda forma de vincular o pod com as variáveis do configMap, copiando todas as variáveis definidas no configMap:

```
apiVersion: v1
kind: Pod
metadata:
  name: db-noticias
  labels:
    app: db-noticias
spec:
  containers:
    - name: db-noticias-container
      image: aluracursos/mysql-db:1
      ports:
        - containerPort: 3306
      envFrom:
        - configMapRef:
            name: db-configmap
```
[Python] Sort a list - Hard & Easy way
Tags: python, beginners, programming
Published: 2022-09-24 20:43:59

Sorting a list in ascending and descending order.

**Hard way!**

```python
arr = [5,2,8,7,1]
temp = 0
for i in range(0,len(arr)):
    for j in range(i+1, len(arr)):
        if arr[i] > arr[j]:
            temp = arr[i]
            arr[i] = arr[j]
            arr[j] = temp

print("Array sorted in ascending order: ")

for i in range(0, len(arr)):
    print(arr[i], end=" ")
    
for i in range(0,len(arr)):
    for j in range(i+1, len(arr)):
        if arr[i] < arr[j]:
            temp = arr[i]
            arr[i] = arr[j]
            arr[j] = temp

print("", end="\n")

print("Array sorted in descending order: ")

for i in range(0, len(arr)):
    print(arr[i], end=" ")
    
```

Easy way!

```python
arr.sort()
print("", end="\n")
print("Array sorted in ascending order: ")
print(arr)

print("", end="\n")
print("Array sorted in descending order: ")
arr.sort(reverse=True)
print(arr)
```

[Demo](https://www.online-python.com/vFnEut3y5s)
Print In Order - Leetcode
Published: 2022-09-24 20:29:50

[Print-In-Order](https://leetcode.com/problems/print-in-order/submissions/)

This problem was quite tricky because I had to read it up to 3 times to understand what was required from us for the task.

First, I created an array of the boolean states of the threads, or print order.

The first thread is meant to run before the order two so I left it as is to run and change the boolean state in the initialized array above.

The second thread, I used a while loop to check if the first thread has been run. Do this by checking the boolean state of the first thread in the array. If yes, you can print the second thread and change the boolean state in the array.

The third thread is just like the second thread but now, we use the while loop check the state of the second thread instead of the first thread.

Following this steps, the solution can be implemented in any object oriented programming language.
Dokuz "dev dependency" paketi tavsiyesi
Tags: flutter, dart
Published: 2022-09-24 20:03:52

📌 DC Flutter Community olarak uygulama geliştirme süreçlerinize kolaylık sağlayacak dokuz dev dependency paketini sizin için listeledik.

1. **change_app_package_name**
Tek bir komut ile proje paket isminizi, platform klasörleri dahil değiştirebilmenize olanak sağlar.
https://lnkd.in/d54WBikK

2. **dependency_validator**
Paket bağlılıklarınızı kontrol eder. Özellikle pubspec.yaml’da yer alıp ancak kod tarafında kullanmadığınız paketleri tespit için etkili bir araç.
https://lnkd.in/d6kr6X3H

3. **dart_code_metrics**
Kod kalitenizi geliştirmek için ilave yeni lint kuralları sağlamakla beraber çeşitli metrikler ile proje kodlarınızı analiz etmenize olanak sağlar.
https://lnkd.in/dpXyqJT5

4. **freezed**
Data-class’lar için pratik bir şekilde kod üretimi sağlar. Siz sadece parametreleri verin, gerisini o halletsin.
https://lnkd.in/dP_atieB

5. **flutter_launcher_icons**
Mobil, masaüstü veya web için uygulama simgenizi platform sürümlerini gözeterek oluşturmaya olanak sağlar.
https://lnkd.in/djD93TiN

6. **flutter_flavorizr**
Platform bazlı flavor yapısı oluşturmanızı sağlar.
https://lnkd.in/du3xASU6

7. **flutter_gen**
Projedeki görsel, font gibi varlıklarınızı kolaylıkla yönetmenizi ve kullanmanıza olanak sunar.
https://lnkd.in/dP7ragN8

8. **custom_lint**
Kendi oluşturduğunuz lint kurallarını, projelerinizde uygulayabilmenizi sağlar.
https://lnkd.in/dRAjcmk7

9. **import_sorter**
Import satırlarınızı gruplayarak düzenli halde sıralanmalarını sağlar.
https://lnkd.in/d5-xN7fS
Complete Tutorial Video for OpenAI's Whisper Model for Windows OS. How to do Speech-to-Text Transcription (Speech Recognition)
Tags: tutorial, python, news, ai
Published: 2022-09-24 20:21:58

Video link > https://youtu.be/msj3wuYf3d8

{% embed https://youtu.be/msj3wuYf3d8 %}

Please also check out video description for more information.

Complete Tutorial Video for OpenAI's Whisper Model for Windows Users - Uses Python - How to do speech-to-text transcription (speech recognition - NLP) for free with better quality than

If you want to transcribe your videos and audio into text for free but with high quality, you have come to the correct video.

In this tutorial video, I will guide you on how to use #OpenAI #Whisper model. I will show you how to install and run Open AI's Whisper from scratch. I will demonstrate to you how to convert audio/speech into text.

Whisper is a general-purpose speech recognition model released for free by Open AI. I claim that Whisper is the best available Speech-to-Text model (Natural Language Processing - #NLP) released to public usage including premium paid ones such as Amazon Web Services, Microsoft Azure Cloud Platform, or Google Cloud API. And Whisper is free to use.

I will show you how to install the necessary Python code and the dependent libraries. I will show you how to download a video from YouTube with YT-DLP, how to cut certain parts of the video with LosslessCut, and how to extract the audio of a video with FFMPEG. I will show you how to do a transcription of a video or a sound. I will show you how to generate subtitles for any video. Finally, I will show you how to generate translated transcription and subtitles of any language video.  

With the translation feature of the Whisper model, you can watch any language (Whisper supports 99 languages) with English subtitles. Let's say you can find English subtitles for your favorite video in German or Japanese or Arabic. It is not a problem. Just follow my tutorial and generated English translated subtitles.