teleren/devto huggingface dataset:
Longest Consecutive Sequence
Tags: java, programming, dsa, beginners
Published: 2022-02-06 12:58:49

Given an array of positive integers. Find the length of the longest sub-sequence such that elements in the subsequence are consecutive integers, the consecutive numbers can be in any order.
 
Example 1:
Input:
N = 7
_a[] = {2,6,1,9,4,5,3}_
Output:
6
Explanation:
The consecutive numbers here
are 1, 2, 3, 4, 5, 6. These 6 
numbers form the longest consecutive
subsequence.

It is a MEDIUM LEVEL question, asked in **Amazon**,**Walmart**, **Microsoft**.

To solve this question click here:(https://practice.geeksforgeeks.org/problems/longest-consecutive-subsequence2449/1)

**Approach 1:**
It can be solved if we first sort the array and then find the longest subsequence. Write your code while keeping in mind that the elements can repeat.
This approach is not that efficient as the _Time Complexity is O(nlog n+n)_ as to sorting algorithm will take time of nlogn.

**Approach 2:**
In second method I used **HashSet** to:
-remove duplicate elements from the array.
-to find the starting element of the sequence.
_Time Complexity: O(n)
Space Complexity: O(n)_

**JAVA CODE**
```
import java.util.*;
class LongestConsecutiveSeq{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the size of the array:");
        int n=sc.nextInt();
        int[] arr=new int[n];
        System.out.println("Enter the elements of the array:");
        for(int i=0;i<n;i++)
        {
            arr[i]=sc.nextInt();
        }
        System.out.println(findLongestConseqSubseq(arr,n));
    }
    static int findLongestConseqSubseq(int arr[], int n)
    {
        //creating hashSet to remove duplicacy
        HashSet<Integer> st=new HashSet<>();

        for(int i=0;i<n;i++)
            st.add(arr[i]);
        
        int ans=0,c=1;
        for(int i=0;i<n;i++)
        {
            c=1;
            if(!st.contains(arr[i]-1))
            {
                int val=arr[i]+1;
                while(st.contains(val))
                {
                    val++;
                    c++;
                }
                ans=Math.max(ans,c);
            }
        }
        return ans;
    }
}
```
HTML to PDF — Java
Tags: programming, java, html, tutorial
Published: 2022-02-06 12:33:50

![](https://cdn-images-1.medium.com/max/2000/1*qbTaTtkKF6qZZ9wyr0xKQA.jpeg)

## Use Case

At the beginning of the year 2020, my wife wanted to redo her CV, so I offered to give her a small [tool](https://github.com/ErwanLT/cv-generator) where she had only to inform her trainings, her diplomas and her experiences and who would then put them in a document.
At first I wanted to create a document in word format, but I was not satisfied with the rendering, the HTML of the frontend looked better than the final document, that’s when I wondered if there was no way to turn this HTML into PDF.
Which led to the use of **html2pdf**, my frontend sent me an object corresponding to her CV and I just had to format it and generate the PDF.

## HTML2PDF

### The Dependency

First imported via your favorite dependency manager (here [maven](https://medium.com/javarevisited/6-best-maven-courses-for-beginners-in-2020-23ea3cba89)).
{% gist https://gist.github.com/ErwanLT/0d1b7bae5431f4a0babe9ec84de6e1a3.js %}
### What is a PDF?

What is a PDF? It’s a file format, so let’s start from the beginning, create a file (thanks captain obvious).

### Fill the File

To do this, nothing is simpler than to use the **HtmlConverter** class and its *convertToPdf* method which takes as a parameter :

* A String : The HTML code as a String

* An OutputStream : The PDF file.
{% gist https://gist.github.com/ErwanLT/b644e43bfaa56f624ee0fc6b938b5bf1.js %}
In the above example, the html variable is a [StringBuilder ](https://www.java67.com/2014/05/difference-between-stringbuilder-and-StringBuffer-java.html)that is built by browsing the properties of a previously populated object.
Warning, tags such as *<head>* are not taken into account, so how to insert css?

That simple :

* Use the style property of the HTML tag

    <**span** style=”font-weight: bold;”>

* use *<style></style>* tags and feed the content between the two by the content of a css file that you will read before
{% gist https://gist.github.com/ErwanLT/8023b3b399c3c89a4c23084bfa16c6bd.js %}
And then use the class property of the HTML tag to add your style

    html.append("<div class=\"card\">")

***Warning*** : complex file like the [Bootstrap ](https://medium.com/javarevisited/7-free-courses-to-learn-bootstrap-for-web-designers-and-developers-5135215648f1)css can produce some errors in the console of your IDE, but nothing to fear, the file will be generated anyway.

## pros and cons

### Pro

* Easy to use.

* Well documented.

* Converting HTML to PDF is a fraction of the possibility of this library.

### Cons

* Code redundancy if the object in question is already displayed on the frontend side.

* Complex CSS files can generate console errors.

* Maintenance difficulty in case of a large file.
Some Issues With Jekyll Type Sites on Github Pages for Google Search Console
Tags: github, shriekdj, jekyll, codewithshriekdj
Published: 2022-02-06 12:19:08

Some Days Ago I Created a Repo on github at [https://github.com/shriekdj/shriekdj.github.io](https://github.com/shriekdj/shriekdj.github.io) And I got Some Issues With It Not With The Site Building But With It's Interaction With **Google Search Console**.

I Know It Was Small Site But Just For Learning I Used google search console.

Firstly It Will Ask You To add your site as a **Property**. Here property is term for verification of Website Ownership Who is submitting the site to google.

If You Can change the site's html the add the verification script in your `<head>` tag of your site.

There is As part where you Have to add Sitemap to Google Search Console But You Also Had To add the Complete URL of Your Sitemap into robots.txt file.

### FOR Jekyll Site You Need to add this things in your site.
- Create `robots.txt` file and also add the sitemap url in it
>> It Helps to Crawling of your site by Search Engine Bots.

- Create `.htaccess` In Your Site for In Future Your gonna give site a custom domain.
>> For 301 type redirection

- Create a `CNAME` file only if your starting to change the site doomain.
My first Calculator App using Kotlin, Android Studio
Tags: kotlin, beginners, app, android
Published: 2022-02-06 11:22:36


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hkznueivnms3uyj9il8y.PNG)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aup7oazjm20l8k63oyvi.PNG)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qj972jcb3u5l51dp1oq0.PNG)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y957jb39ze6dkz5ln442.PNG)
My Comeback as a web developer
Tags: javascript, webdev, discuss, productivity
Published: 2022-02-06 11:10:59

## My Comeback As A Web Developer

Hello everyone today I'm writing about how I wish to make myself more productive using my knowledge of web development and the current trend **Web3.0**

I came to realize that online presence makes a difference as an open-source developer, it is hard to say I don't usually give attention to what I want versus what I actually need

### What I Needed

What I needed wasn't technical know-how alone but;

1. Communication skills
2. Open Source contributions
3. Solve a **Real-life Problem**
4. Under the hood processes
5. Not only **Passion** but **Determination** is required

### What I thought I Needed

I started learning _web development_ self-taught in 2019, then all I wanted was a change in hobby, I didn't realize it would be a game-changing decision in my future and had many chances of making a living. As usual, every developer's dream was to work at a Silicon-Valley based IT firm especially **FAANG**, like everyone I also had a passion for such type of work. Since then my thought was;

1. I needed to be a _black-belt_ with **Problem-Solving and Algorithms** to land a dream job
2. Working with FAANG guarantees a successful career
3. Freelancing or building SaaS or even Content-Creation requires some defined set of skills

There's a lot more to programming than having a successful code compile, one of which includes having your code merged into a large scale open-source project or giving an answer to a question on sites like _stack-overflow_ and getting massive up-votes or knowing you inspired someone into the tech-world

I hope by the end of this year I don't have any regrets about what I should have learned or done this year like last year

With all that said I hope y'all find this writing inspiring, I'll be sure to write more content using this medium and many more
Build avec CMake un programme utilisant des threads
Tags: cpp, cmake, french
Published: 2022-02-06 11:05:04

---
layout: post
title: Build avec CMake un programme utilisant des threads
published: true
tags: [Cpp, CMake, French]
---

## La problématique
Lorsque vous utilisez la [bibliothèque de support des threads](https://en.cppreference.com/w/cpp/thread) de la bibliothèque standard, si vous utilisez __gcc__ ou __clang__ vous allez devoir linker votre programme avec la bibliothèque __pthread__. Pourquoi ? Car la __libc++__ et la __libstdc++__ (les implémentations de la bibliothèque standard de __clang__ et de __gcc__) ont été linkées dynamiquement avec __pthread__. Du coup, dans votre ligne de compilation vous devez ajouter `-lpthread`.

Si vous utilisez CMake comme système de build, la première idée qui vous vient est sûrement de regarder si vous n’êtes pas sur Windows, ou bien si vous utilisez clang ou gcc et de linker avec __pthread__ dans ce cas là. Mais il existe une manière plus courte et plus portable de le faire !

## La solution
Il suffit tout simplement d’appeler la fonction __find_package__ pour chercher le package __Threads__, puis de linker votre cible avec la bibliothèque __Threads::Threads__. 

```CMake
find_package(Threads REQUIRED)
target_link_libraries(your_target PRIVATE Threads::Threads)
```

Voilà, c’est aussi simple que ça ! Pas besoin d’avoir de comportement différent en fonction du compilateur ou de la plateforme, et en plus c’est portable.

## Exemple complet
Voici un exemple complet. On essaye donc de compiler ce fichier __main.cpp__ :
```C++
#include <iostream>
#include <thread>
#include <chrono>

int main ()
{
    using namespace std::chrono_literals;
    std::cout << "Before sleep" << std::endl;
    std::this_thread::sleep_for(2s);
    std::cout << "After sleep." << std::endl;
}
```

Et voici le __CMakeLists.txt__ correspondant :
```CMake
cmake_minimum_required(VERSION 3.9)
project(ThreadExample VERSION 1.0.0 DESCRIPTION "A simple program using threads support library.")

find_package(Threads REQUIRED)
add_executable(my_target main.cpp)
target_link_libraries(api PRIVATE Threads::Threads)
```

## Sources
* [https://en.cppreference.com/w/cpp/thread](https://en.cppreference.com/w/cpp/thread)
* [https://cmake.org/cmake/help/latest/module/FindThreads.html](https://cmake.org/cmake/help/latest/module/FindThreads.html)
Retrospective
Tags: discuss, personal, improvement, growth
Published: 2022-02-06 11:04:28

---
title: Retrospective
published: true
description: 
tags: discuss, personal, improvement, growth
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ds715fqhb1nr3ydxgjlt.jpg
---

_Originally published on [my blog](https://www.nikola-breznjak.com/blog/daily-thoughts/retrospective/)._

> If you want to learn about yourself, do a retrospective at least once per month. [Journaling](https://www.nikola-breznjak.com/blog/daily-thoughts/journaling/) will help.

---

This is [why I write](https://www.nikola-breznjak.com/blog/daily-thoughts/why-do-i-write-these-daily-thoughts-posts/) these 'daily thoughts' posts.
Fast apache kafka local deployment
Tags: docker, kafka, tutorial, programming
Published: 2022-02-06 10:49:05

Hey, dev.to!

If you are using apache kafka, you know that local deployment required a lot of things. You need to download zookeeper, apache kafka, edit configs and then run them. And, of cause, it takes time. The detailed description you can find in this article https://dev.to/lehauchicha/spring-boot-application-with-apache-kafka-299n. But is it possible to speed up the local deployment process of apache kafka ?

The answer is yes!
In this article we will deploy apache kafka locally using docker-compose. All you need is download and install docker from official site: https://www.docker.com/get-started

Lets create docker-compose.yml file:
```yaml
version: '2'
services:
  zookeeper:
    image: confluentinc/cp-zookeeper:latest
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
    ports:
      - 22181:2181
  
  kafka:
    image: confluentinc/cp-kafka:latest
    depends_on:
      - zookeeper
    ports:
      - 29092:29092
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
```
As you can see here we specify images for zookeeper and kafka with ports. That's it!

Lets run kafka, using docker-compose:
```
docker-compose up -d
```
you will see such result:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9i7twbj5it6r9h6errgo.png)

Now kafka ready for usage in your applications!

One more thing, for convenient configuring kafka topics, I would like to suggest UI Tool for Kafka - Offset Explorer, which you can find by link https://kafkatool.com/download.html.

For connection to deployed kafka you need install tool and add connection parameters here on properties tab:

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

and here on advanced tab:

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

That's it. Thank you for reading!
Substring with Concatenation of All Words - LeetCode
Tags: leetcode, concatenationleetcode, substringleetcode, leetcodehard
Published: 2022-02-06 10:23:00


LeetCode has a hard coding Problem in Its' Algorithm Section "Substring with Concatenation of All Words". Today We are going to solve this problem. LeetCode Link of the Problem is HERE

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9syf38bjm9u4vba2tsej.jpg)
Question
You are given a string s and an array of strings words of the same length. Return all starting indices of substring(s) in s that is a concatenation of each word in words exactly once, in any order, and without any intervening characters.
You can return the answer in any order.
Examples
Input: s = "barfoothefoobarman", words = ["foo","bar"]
Output: [0,9]
Explanation: Substrings starting at index 0 and 9 are "barfoo" and "foobar" respectively.
The output order does not matter, returning [9,0] is fine too.
Input: s = "wordgoodgoodgoodbestword", words = ["word","good","best","word"]
Output: []

Input: s = "barfoofoobarthefoobarman", words = ["bar","foo","the"]
Output: [6,9,12]
Constraints:
1 <= s.length <= 104
s consists of lower-case English letters.
1 <= words.length <= 5000
1 <= words[i].length <= 30
words[i] consists of lower-case English letters.

Solution to Substring with Concatenation of All Words
The Skeleton code given by LeetCode is
class Solution(object):
    def findSubstring(self, s, words):
        """
        :type s: str
        :type words: List[str]
        :rtype: List[int]
        """
So, for this question, my current proposal is to cut a substring of the corresponding length (the sum of the lengths of each element in words) from s and then trim this substring according to the length of a single word in words. A list is formed by smaller substrings. To determine if the sorted results of words and lists are the same, compare them. If that's the case, we'll go back to the beginning. Otherwise, keep going.
Complete Solution:
Complete Solution is available here 
https://hecodesit.com/substring-with-concatenation-of-all-words-leetcode/
Create a Weather App live in React JS 
Tags: react, javascript, webdev, programming
Published: 2022-02-06 10:19:31

Hey Guys, I am an experience React JS/ Shopify Expert ( working as a full time employed) for 6+ years. Thought i should start a tutorial series in Youtube each weekend to give something back to community ( of all i've learnt so far). Will create a weather Application live in React today. Anybody find it interesting to learn, please tune in. Will also do Q/A live.  
https://www.youtube.com/watch?v=A-BQZIhC3X8
Coding lessons from cross stitch
Tags: programming
Published: 2022-02-06 09:41:54

I've been thinking a lot about cross stitch and coding this week and how they're connected.

## Cross stitching - the back

When you cross stitch you're creating something that'll look good, framed on your wall. But the back is important too - it should also look good. If you look at the back of a cross stitch you should see vertical lines.

Why is that important? Partly because it's the mark of a good cross stitcher, and it's a mark of pride that you've done good work (at least it is for me).

But it's also to make sure nothing shows through on the front that you don't want to be seen. For example, if you do a stitch on one side of the material, then do another stitch on the other, the thread hanging between them might be visible through the holes between the stitches. You don't want that.

It's also because it's more efficient. Good cross stitchers use less thread. They then build up a massive collection of threads left over from kits, which somehow never seems to contain the right colour, but that's a separate problem (see cover photo).

## How does this relate to coding?

The front of cross stitch is like the part that the users see. It looks pretty and it's obvious what it's meant to be. The back of cross stitch is the actual program - the part that only developers see. And it should also be pretty and obvious what it's meant to be.

Just as with cross stitch, where you should be able to look at the back and know where you are, you should also be able to look at your code and know what it's doing.

It's a skill you learn as you go on. As you get better at cross stitching you'll get faster and more efficient, and the back will look prettier. As you get better at coding you'll get faster and more efficient, and your code will be prettier.

But there's one way in which coding is better. When coding you can go back and make the code prettier later (aka refactoring). Once you've done your cross stitch, it's done. You don't unpick it to make the back look better (not least because unpicking makes the thread fray and you'll end up using twice as much).

## Other ways cross stitch teaches us about coding

There's a lot I could write about here, but @larainnepasion already did that with their article on [How coding is like crocheting](https://dev.to/larainnepasion/how-crocheting-is-like-coding-1mkn). Everything in that article could be said about cross stitching too.

### Too much of one thing is not good for you

We're all familiar with the threat of RSI from too much keyboard usage. But it's not the only way you can get it. I have RSI from too much cross stitching. It's a lesson that doing something a lot is not good for you, even if you really enjoy it.
Why is dynamically adding properties slow in JavaScript?
Tags: javascript, webdev, programming, performance
Published: 2022-02-06 09:33:00

JS gives an ability to add properties to the object after it was created. 
It gives a lot of freedom but has a performance cost at the same time.

## 👉 JavaScript’s object model

The ECMAScript specification defines all objects as dictionaries, with string keys mapping to property attributes

Property access is the most common operation in real-world programs => "Value" needs to be accessed fast, so shapes come into play.

![JavaScript’s object model](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y9pi8k21l9oz1s6ihdbw.png)

## 👉 Shapes

Multiple objects have the same shape if their properties are the same. 
If it's the case, the JS engine stores their Shape separately, and then JSObjects point to it.

Shapes store the "Offset" of the value inside JSObject, instead of the "Value" itself.

![Shapes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5yupfnnvjh2vgxe25rsd.png)


## 👉 Transition chains

When you dynamically add properties to the object, its Shape form a so-called transition chain.
Next time you access a property of the object, the JS engine needs to traverse its transition chain.

At scale, performance suffers in this case.

![Transition chains](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l5ew0431exqiruamw7o3.png)

## 👉 How to optimize it like a top-performer?

vNode properties are accessed on every render in Preact, so this operation needs to be extremely fast.

To achieve it, Preact developers [add all properties in advance and assign undefined/null to yet unknown](https://github.com/preactjs/preact/blob/f2ca940973955739625698e133cc1e86fe9c6677/src/create-element.js#L58).

```js
const vnode = {
  type,
  props,
  key,
  ref,
  _children: null,
  _parent: null,
  _depth: 0,
  _dom: null,
  _nextDom: undefined,
  _component: null,
  _hydrating: null,
  constructor: undefined,
  _original: original == null ? ++vnodeId : original
};
```

---

P.S. [Follow me on Twitter](https://twitter.com/fromaline) for more content like this!

{% twitter 1487059240468590596 %}
How to display json in Flutter ?
Tags: flutter, dart, mobile, android
Published: 2022-02-06 09:20:03


Often, when we developing applications using APIs, we work with json models. You have to look at the objects in the debugger, print them to the console, e.t.c.
I’ve done this a lot and I’m tired of it!
Therefore, I want to introduce you the [**flutter_json_view**](https://github.com/Frezyx/flutter_json_view) package.



- Now this package can work through 2 constructors for **json strings** and files.

- The package has the ability to **customize individual type**s of fields and the **all UI**.

- The package does not depend on other packages. This makes him **lightweight and independent**.


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

**Github link:**
I will be happy if you support the project and put a star
https://github.com/Frezyx/flutter_json_view
Journey begins | Jinxx
Published: 2022-02-06 08:51:19

Day 0 
I have decided to write tech related post from today, things that I will be learning, things which i get to know, interesting projects and many more. I will give my 100 percent to make sure that my blog/article comes up daily from now. I am doing this for me so that i can add an habit of writing some thing and it will also help me remember the things which I have learned, and yes it will increase my tying speed as well.
Day 7 of 100DaysOfCode
Tags: 100daysofcode, challenge, python, backend
Published: 2022-02-06 08:36:17

## Day 7 of 100 Days Of Code
_The post is for yesterday._

Here can you find what I learned (& published) yesterday.

### What I published / coded / updated yesterday?
* Started with...
* Learning some things about pytest,
* Merging the pull request for the [AntiScamBot backend](https://github.com/AntiScamBot) python rewrite.
* Improving some things.
* Ended with the blog post.