teleren/devto huggingface dataset:
Data Structure Algorithms: Binary Search
Tags: beginners, java, algorithms
Published: 2022-02-21 06:06:55

Binary Search is applied on the sorted array or list of large size. It has a time complexity of O(log n) making it very fast as compared to other searching algorithms. The only limitation is that the array or list of elements must be sorted for the binary search algorithm to work on it.

**Algorithm**

```
1.	Start with the middle element: 
If the target value is equal to the middle element of the array, then return the index of the middle element.
If not, then compare the middle element with the target value, 
If the target value is greater than the number in the middle index, then pick the elements to the right of the middle index, and start with Step 1.
If the target value is less than the number in the middle index, then pick the elements to the left of the middle index, and start with Step 1.
2.	When a match is found, return the index of the element matched.
3.	If no match is found, then return -1
```
**Time Complexity**
Binary search has a time complexity of O(log n).
 
**Java Example**

```
package com.pgichure.samples.dsa.binary;

public class BinarySearch {

	public static void main(String[] args) {
		
		int[] values = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
		
		int search_number = 13;
		
		int index = 0; // this will hold the index of middle elements
		
		int max = values.length - 1; //the maximum index
	    int min = 0; //the minimum index
	    
	    int step = 0;  // to find out in how many steps we completed the search
	    
	    while(max >= min)
	    {
	    	
	    	index = (max + min) / 2;
	        // we made the first guess, incrementing step by 1
	        step++;
	        
	        if(values[index] ==  search_number){
	        	System.out.println(search_number + " found at index "+ index + " after "+step+" steps");
	        	System.exit(0);
	        }
	        else if(values[index] >  search_number) {
	            // target would be in the left half
	            max = (index - 1);
	        }
	        else{
	            // target would be in the right half
	            min = (index + 1);
	        }
	    }
	}

}
```
**Source Code**
You can access the source code [here](https://github.com/Gichure/data-structure-and-algorithms/tree/main/binary-search).
User Office Hours: Introduction to Snyk Code
Tags: snyk, officehours, security
Published: 2022-02-21 08:20:22

February 15, 2022

During this session, we’ll explore how to get started with Snyk Code. We’ll look at: 

Snyk Code language & framework support
How to enable Snyk Code in the web UI
Best practices for using Snyk Code's IDE plugins

Throughout the session, you can ask us anything !. Bring all of your Snyk questions and we’ll do our very best to answer them.

 [![Video](https://i.ytimg.com/vi/UFq3OJBmwsM/sddefault.jpg)](https://www.youtube.com/watch?v=UFq3OJBmwsM)
Excel to SQL via System.Data.DataSet
Published: 2022-02-21 08:16:36

---
canonical_url: https://ironsoftware.com/csharp/excel/examples/excel-sql-dataset/
---

Convert any XLS or XLSX Excel file (WorkBook) to a `System.Data.DataTable` for full interoperability with `System.Data.SQL` or to populate a **DataGrid**.

**C#:**
```
using IronXL;
using System.Data;
 
 //Open any Excel document.
WorkBook workbook = WorkBook.Load("test.xls");
 
// Convert the whole Excel WorkBook to a DataSet
// This allows us to work with DataGrids and System.Data.SQL nicely
var dataSet = workbook.ToDataSet();
foreach (DataTable table in dataSet.Tables)
{
    Console.WriteLine(table.TableName);
 
     //Enumerate by rows or columns first at your preference
	foreach (DataRow row in table.Rows)
	{
	    for (int i = 0; i < table.Columns.Count; i++)
	    {
	        Console.Write(row[i]);
	    }
	}
}
```

**VB:**
```
Imports IronXL
Imports System.Data
 
 'Open any Excel document.
Private workbook As WorkBook = WorkBook.Load("test.xls")
 
' Convert the whole Excel WorkBook to a DataSet
' This allows us to work with DataGrids and System.Data.SQL nicely
Private dataSet = workbook.ToDataSet()
For Each table As DataTable In dataSet.Tables
	Console.WriteLine(table.TableName)
 
	 'Enumerate by rows or columns first at your preference
	For Each row As DataRow In table.Rows
		For i As Integer = 0 To table.Columns.Count - 1
			Console.Write(row(i))
		Next i
	Next row
Next table
```
Make any PDF have Searchable, Copyable Text (Code Example)
Published: 2022-02-21 08:12:08

---
canonical_url: https://ironsoftware.com/csharp/ocr/examples/make-pdf-searchable/
---

We can use Iron's advanced Tesseract engine make scanned PDF documents searchable and indexable, with text users can copy and paste.

**C#:**
```
using IronOcr;
 
var Ocr = new IronTesseract();
using (var Input = new OcrInput())
{
    Input.AddPdf("scan.pdf","password")
 
    // clean up twisted pages
    Input.Deskew();
 
    var Result = Ocr.Read(Input);
    Result.SaveAsSearchablePdf("searchable.pdf");
}
```

**VB:**
```
Imports IronOcr
 
Private Ocr = New IronTesseract()
Using Input = New OcrInput()
	Input.AddPdf("scan.pdf","password") Input.Deskew()
 
	Dim Result = Ocr.Read(Input)
	Result.SaveAsSearchablePdf("searchable.pdf")
End Using
```
3.Stringbuilder class in java
Tags: java, programming, beginners
Published: 2022-02-21 08:11:18

**Java Stringbuilder class**

- Strings in java are immutable (not editable)

- so to make changes in string we use this string builder class which makes the string mutable (editable)

- there are different methods which comes with stringbuilder class as shown below
![Image Stringbuilder class in java](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8k4m95irpxqhq6vi61vg.png)

**1.Append:**

- This method will simply append an string to existing string.

**2.Insert:**

- this will insert an character or strig at given position in given string.

**3.Replace:**

- this will replace certain part of string with another string.

- it take position of string which need to be replaced.

**4.Delete:**

- this method will delete certain part of string by taking starting and ending position.
Setup KinD (Kubernetes In Docker) on Amazon EC2
Tags: kubernetes, docker, linux
Published: 2022-02-21 08:06:26

<h3>Install Docker on Linux - </h3>
As I'm using an Amazon Linux I can install docker with a 
<b>yum install docker -y</b>
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f6a3nhjz04egwr4umyf0.png)
Start docker service - <b>systemctl start docker</b>

For Docker Installations - https://docs.docker.com/engine/install/

<h3>Install Go -</h3>
Go to https://go.dev/dl/
Copy the link of go tarfile for linux platform
Install using wget 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jj4ozt9d7th2fi78kvlx.png)
Extract it using <b>tar zxf go1.17.7.linux-amd64.tar.gz -C /usr/local</b>
- Add <b>/usr/local/go/bin</b> to the PATH variable.

<h3>Install KinD</h3>
<b>go install sigs.k8s.io/kind@v0.11.1</b>
You can replace v0.11.1 with the latest stable kind version

<h3>Move the KinD Binary to /usr/local/bin -</h3>
- You can find the kind binary inside the directory go/bin
- Move it to /usr/local/bin - <b>mv go/bin/kind /usr/local/bin</b>
- Make sure you have a path setup for /usr/local/bin
 
<h3>Install Latest Version of Kubectl:</h3>
<b>curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"</b>
<b>chmod +x kubectl</b>
<b>mv kubectl /usr/local/bin</b>

<h3>Create a cluster with kind</h3>
<b>kind create cluster --name labcluster</b>
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gxstcri6r7mts27q3c9b.png)
<b>kubectl get nodes -o wide</b>
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a6ne23e3oyskueaw9utc.png)
<b>docker ps</b>
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yoq41iocxe3fmra3fhob.png)  
You are now running KinD successfully in Linux 
Once done you can delete the cluster using 
<b>kind delete cluster</b>

<h2>Multi-Node Cluster -</h2>
Create a config file kind-example-config.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker

<b>kind create cluster --config kind-cluster-config.yaml</b>
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eqfsmvt644z7o1ru2o9i.png)

You now have a running KinD Cluster with one master and two worker nodes.
<b>kubectl get nodes -o wide</b>
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nq8xuhea7u0x5ex30ki2.png)
Angular material cross field form validation
Tags: angular, javascript, typescript, material
Published: 2022-02-21 08:05:56

@angular/cli - 12.0.1
@angular/material - 12.0.1

{% github anirbmuk/MaterialFormDemo no-readme %}

This article talks about performing field-level validations across a reactive form using Angular material. The solution aims to perform cross-field form validation and then display the error as mat-error for a selected field.

This is how it would be:

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

Both the errors shown above are registered on the FormGroup. But the goal is to display them as mat-error on certain fields.

So how do we do this? To begin with, let's set up the form and the corresponding cross-field validations.

![Setup](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1bgglyfvdn6czwsnp0ma.png)

And we are set up in terms of the code required for the validation part. But how do we display the error as mat-error for a specific field? The mat-error only displays error when the specific field is in an error state. But our requirement is to mark it invalid when the form is invalid (and not just the specific field).

To achieve this, we use an interface called `ErrorStateMatcher`. This interface implements a method `isErrorState`, where we can write the logic to mark a form-control as invalid.

We create a class which implements this interface, and then create two instances of this class to use for the two validation methods.

![Base class](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m6vqyg6xb3eq8zjvnxsk.png)

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

Now we map these instances to the fields on which we would want to see the mat-errors.

![HTML 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qnj6cdj0sjr7eh3aajh1.png)

![HTML 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eco86kh07qed1h3tukv1.png)

The **[errorStateMatcher]** properties are mapped to the respective class instances, which allow the respective fields to be invalid and show mat-error once the form becomes invalid.

Cheers!
[Anirban Mukherjee](https://anirbmuk.appspot.com/en)
hate CSS? use this extension instead
Tags: showdev, webdev, css, html
Published: 2022-02-21 08:01:57

let's be honest, many developers just hate working with CSS because:
1. you have to try a lot of CSS properties values just to get something just right (aka make it pixel perfect)
2. it's extremely repetitive!! 

how many times we just write the exact same thing?

`display: flex, justify-content: center...`

most CSS priorities just keep repeating over and over again to create any UI

soo... I made a browser extension to <a href="https://intab.io">visually change any website's CSS</a>  instead!
<br>

🎨 &nbsp; 35+ CSS properties 
👌  &nbsp;&nbsp; customizable CSS selector
✍ &nbsp; integrated code editor
⚡ &nbsp; super lightweight <small>- 500KB</small>

___

![InTab visual css edtior](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/74rjo3m5mo55hqshqpwl.png)
 
___

📱 &nbsp;&nbsp; <b>∞</b> virtual devices + realtime sync
🔎 &nbsp; clean CSS inspector on hover
🕶 &nbsp; breakpoints visualizer
🌲 &nbsp; HTML layers tree
☢ &nbsp; x-ray mode

___

![InTab virtual devices](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vcxk3heb8jkooezi0kxm.png)
 
___

<b>why not devtools?</b>

- modifying CSS is slow and exporting changes is a pain
- refresh the page & all the CSS changes are gone!
- hard to inspect CSS with lots of crossed-over properties
- constantly resizing devtools or using one device at a time to test responsiveness


so to fix all of those issues I made InTab.

👉🏻 give it a shot at [intab.io](https://intab.io)
🎉 just launched this also on [ProductHunt](https://www.producthunt.com/posts/intab-2-0)

please show some 💗

Cheers!
Enjoy Programming-Themed Humor? Here's today's daily developer joke!
Tags: jokes, dailydeveloperjokes
Published: 2022-02-21 08:00:04

---
title: "Enjoy Programming-Themed Humor? Here's today's daily developer joke!"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
published: true
tags: #jokes, #dailydeveloperjokes
---

Hi there! Here's today's Daily Developer Joke. We hope you enjoy it; it's a good one.

![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1259169f6cb.png)

---

For more jokes, and to submit your own joke to get featured, check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/). We're also open sourced, so feel free to view [our GitHub Profile](https://github.com/dailydeveloperjokes).

### Leave this post a ❤️ if you liked today's joke, and stay tuned for tomorrow's joke too!

_This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit._

<!--
Joke text:
___Q:___ A SQL developer walked into a NoSQL bar.

___A:___ They left because they couldn't find a table.
 -->
Create DVD Drive ISO Library XenServer or XCP-ng
Tags: xcpng, dvd, iso
Published: 2022-02-21 07:51:12

1) Login to the server via `ssh` or can `WinSCP` software to connect using `scp` protocal.

2) Create an folder:

```
mkdir /opt/os
```

3) Open the folder
```
cd /opt/os
```

4) Download setups (.iso) files 
```
wget http://in.mirror.coganng.com/ubuntu-cdimage/20.04.3/ubuntu-20.04.3-desktop-amd64.iso
```

5) Mount ISO folder
```
xe sr-create name-label="OS" type=iso device-config:location=/opt/os device-config:legacy_mode=true content-type=iso
```

Now, create new VM, all the `.iso` files will be available in the dropdown.

If you upload any `.iso` file after the `xe sr-create`, you need to rescan the storage resource (sr) to recognize new `.iso` files. To do this follow steps:

1) Find UUID of the `sr`
```
xe sr-list
```

2) Rescan `sr` folder:
```
xe sr-scan uuid=<uuid-of-sr>
```

Now you will be able to see the new `.iso` files.



Reference: 
https://www.youtube.com/watch?v=eNuBw3O0SmU
Heaps Usage : Heapify Vs Heap-Sort
Published: 2022-04-27 18:48:44

---
title: Heaps Usage : Heapify Vs Heap-Sort
published: true
date: 2022-02-21 07:50:47 UTC
tags: 
canonical_url: https://jainneha.hashnode.dev/heapify-vs-heap-sort
---

 **Definition of Heap :** Heap is a Complete Binary Tree, which satisfy the property that parent node value is larger than child nodes' (in case of MAX-HEAP) or smaller (in case of MIN-HEAP). This property of Heap has to be followed by each node with it's child nodes at each level of tree.

**Storage in memory :** Binary Tree is being stored in memory in form of array as data structure, following level traversal to order elements such that, for each index i as parent, children would be 2i+1 and 2i+2

**Heapify(Construct Heap)** is an approach (either top-down or bottom-up), which arranges elements in any array such that, when checked for any index i as parent, its child nodes values at index 2i+1 and 2i+2 would follow either MAX-HEAP or MIN-HEAP property. It doesn't sort array in ascending or descending order.

**Heap-Sort :** Sort array in ascending or descending order. As name suggests, we are using Heap BT property here to rearrange array elements. Heap Sort is an application of Heap BT.

Steps to sort an input array via Heap-Sort:

1. Arrange array elements in order as of MAX-HEAP or MIN-HEAP, using Heapify(Construct Heap) logic. (Logically it will follow Heap BT property, but storage wise it is still an array)
2. Put a loop over array, start from root node, compare it with last leaf node, swap if required and delete leaf node. Insert deleted element in a different array. Follow this until all nodes are deleted. Now, when we delete any node in Heap, we need to do Heapify residual array as part of delete operation on Heap BT. And the deleted elements while insertion in array follows order as ascending (MIN-HEAP) or descending (MAX-HEAP). 

This is similar to selection sort, which on comparison in each pass, places max/min element to final position and gets excluded in comparison in next pass.
A powerful Javascript playground for Desktop 🔥
Tags: webdev, javascript, productivity
Published: 2022-02-21 07:41:50

 ---
title: A powerful Javascript playground for Desktop 🔥
published: true
description: Learn and experiment by prototyping your ideas with JavaScript.
tags: webdev, javascript, productivity
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jqd6rbtclr5clo0i6h26.png
---

Last year I introduced a **Javascript playground** feature to  my note-taking app [Znote](https://dev.to/alagrede/dev-tool-a-markdown-editor-for-developers-1j13). Facing success with the community I decided to improve this feature to offer the best experience as possible to quickly run and test Javascript. 

Ten months later, this aspect of Znote continues to change my use of JavaScript in my daily work, because now I am able to create scripts, explore a Dataset, automate tasks directly through the application.

![Example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h24bg8m1iw89sk0h2hpq.gif)

Based on Markdown file, I'm able to run separately Javascript code block as browser or NodeJS code, create embedded functions, install NPM packages... So many possibilities that I had to create a dedicated [documentation website](https://doc.notebookjs.app/#/) to ensure to make users aware of all the possibilities. 


## The Birth of NotebookJS

To complete my value to the community and because Znote is primarily a note-taking app, I decided to create a dedicated app [NotebookJS](https://notebookjs.app/) entirely focused around this Javascript playground.

![NotebookJs screenshot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sebt6jwitmzylcfzoq5u.png)

Based on **files** and organized **in tabs**, NotebookJS give a unique way to quickly prototype Javascript, visualize data and document your work without forcing you to start complex projects.

I propose this app as complement of Znote to cover the most useful use-cases. I also set a cheap price to definitely buy the application, mainly **to support my work** and hidden fees behind it. 

I'm so happy to provide a valuable software 😊. I would really like constructive feedback, so **I will offer during 10 days, a perpetual free license to all users subscribing to the NotebookJS** [newsletter](https://notebookjs.app/) and wanting give it a try to my app.

You will receive the license on the email you provide on the newsletter form. Moreover, you will also receive later (ONLY) tutorials and tips about this application.

Leave your impression below or start a Github [discussion](https://github.com/alagrede/znote-app/discussions) if this requires a new thread.

I'm waiting you here: [NotebookJS](https://notebookjs.app/)

I hope you will enjoy this app as much as I did creating it. ❤️
Combining TypeScript utility types
Tags: typescript, javascript, beginners
Published: 2022-02-21 07:31:56

By now, we had a basic introduction to some of the utility types of TypeScript.

However, the real power unleashes when you combine them.

When we used the [partial and required types](https://daily-dev-tips.com/posts/typescript-utility-types-partial-and-required/), you might have noticed that they have one downside: they affect all properties.

By combining them with [pick and omit](https://daily-dev-tips.com/posts/typescript-utility-types-pick-and-omit/), we can ensure only specific fields are affected.

Let's take a look at how this would work.

> Disclaimer: This article is for TypeScript beginners. We have not yet covered Generics, so nothing will use generics in this article.

## Making specific fields required

Let's take the following example interface:

```js
interface User {
  id?: number;
  firstname: string;
  lastname: string;
  age?: number;
}
```

What if we want to make just the `id` required but leave the age optional?

Depending on our end use-case, we have two options here.

First, let's say all other fields can be optional, but the `id` must be set.

We can choose to make a new type combining `Partial` and `Required`.

It will looks like this:

```js
type LoggedUser = Partial<User> & Required<Pick<User, 'id'>>;
```

What we say here is:

- Take the user interface and make everything optional (Partial)
- Include a required type, but `Pick` only the `id` field to make required
- Assign this combination to the `LoggedUser` type.

We end up with a type with three optional fields: `firstname`, `lastname` and `age` and one required field: `id`.

But, in some cases, this is not exactly what we wanted, as we don't want the first and last name to be optional.
We could, of course, include them in the `required` statement, but that would defeat the purpose.

In that case we can write the following type:

```js
type LoggedUser = Required<Pick<User, 'id'>> & Omit<User, 'id'>;
```

What this one does:

- Require the `id` field by picking it from the user
- Include the remaining user interface, but omit the id field
- Assign this combination to the `LoggedUser` type

We have three required fields in this scenario: `firstname`, `lastname`, and `id`. And one optional field, the `age`.

As you can see, using a combination of utility types is really where they shine.
You can make crazy combinations, and once we dive into generics, we can turn these into re-usable types!

### Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on [Facebook](https://www.facebook.com/DailyDevTipsBlog) or [Twitter](https://twitter.com/DailyDevTips1)