teleren/devto huggingface dataset:
A little bit about binary search
Published: 2022-02-01 09:19:30


Algorithms are step-by-step well defined instructions accomplish a program or task. I chose to write and learning more about binary search, because it’s an interesting algorithm kind and help much for high performance for a program or task.

Suppose you’re looking up a phone number in the phone book, the owner name phone starts with L. You open the phone book in the middle and find the K letter phones list, you does know K is before L and eliminate almost half of phone book options. 

Imagine a social network with millions of users, and you are try find a user starts with F. If when you try search about user starts with F, the social network programming search in all millions users, this does spend unnecessary time and resource for it.

<aside>
📌 Binary search is a kind algorithm of does search and that minimize search options. But remember, it’s just does works with sorted lists.

</aside>

## Search a number

Suppose now, you’re search a number **32** in an array. You know that number **32** is near the middle, and you take a position that returns **42** number**. 42** is fewest that **32,** so you can eliminate half numbers.

<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5k3sdq3a3gcjbmu9n7tb.jpeg" alt="complete array" />

Now, you can have an array with three positions, and take a middle position again and that returns **20** number. 

<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6t3dkxmaz41pwb0db5u0.jpeg" alt="half array" />

Now, you know **20** is fewest that **32**, and left over one number for search, it’s **32**!

<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wosryeytir64qf7qtspl.jpeg" alt="result binary search" />

## Hands-on

Let’s see how to write binary search with Dart language. The `binarySearch` function takes an array and item, the function returns which position of item at array.

```dart
void main() {
  const list = [5, 20, 32, 43, 65, 88];

  print(binarySearch(list, 32)); // 2
  print(binarySearch(list, -1)); // null
}

int? binarySearch(List<int> list, int item) {
  // low and high to track search
  var low = 0;
  var high = list.length - 1;

  while (low <= high) {
    // check the middle of element
    var middle = low + high;
    var guess = list[middle];

    // If found them
    if (guess == item) return middle;
    // The guess is fewest than item
    if (guess < item)
      low = middle + 1;
    // The guess is higher than item
    else
      high = middle - 1;
  }

  // The item does not exists
  return null;
}
```
What if you get access to GutHub copilot
Tags: github, discuss
Published: 2022-02-01 08:52:40

GitHub copilot is only available to some peoples as it is not released completely. If you haven't signed up, you should do it now because you get access after a month. Visit [here](https://github.com/features/copilot/signup).

I want to ask you all guys a question. What will you ask GitHub copilot to do if you get access to it?

Funny, serious, any type of idea is accepted in comment section👇.
How to set up Wireguard on VPS (using Docker)
Tags: vpn, wireguard, docker
Published: 2022-02-01 08:32:42

## Introduction
You can very easily set up a Wireguard server, using docker (for docker-compose accuracy) on your Linux server. This option may also work on Windows, however I am not testing it

## Requirements
1. Linux Server (with root access)
2. Ability to open ports
3. [`docker`](https://docs.docker.com/engine/install) & [`docker-compose`](https://docs.docker.com/compose/install/) installed

## Before you start...
Please open ports `51820` (UDP), otherwise it won't work

## Installation process
- Enter these two commands, they will create required directories

```
mkdir -p ~/wireguard/
mkdir -p ~/wireguard/config/
```

- Run `nano ~/wireguard/docker-compose.yml` and paste below-mentioned content into the `docker-compose.yml` file

```
version: '3.8'
services:
  wireguard:
    container_name: wireguard
    image: linuxserver/wireguard
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/Warsaw
      - SERVERURL=00.00.00.00
      - SERVERPORT=51820
      - PEERS=10
      - PEERDNS=auto
      - INTERNAL_SUBNET=10.0.0.0
    ports:
      - 51820:51820/udp
    volumes:
      - type: bind
        source: ./config/
        target: /config/
      - type: bind
        source: /lib/modules
        target: /lib/modules
    restart: always
    cap_add:
      - NET_ADMIN
      - SYS_MODULE
    sysctls:
      - net.ipv4.conf.all.src_valid_mark=1
```
Fill this config:
- `TZ` is a Timezone - Get yours from TZ Database in [Wikipedia](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
- `SERVERURL` is your server IP
- `PEERS` are basically configs, if you want 10 configs, just type 10, and peers will generate automaticly

Hit `CTRL` + `X` and then `Y` then `ENTER` to save the file

To run Wireguard enter these two commands:
`cd ~/wireguard/`
`docker-compose up -d`

- Enter `docker-compose logs -f wireguard` - There should be QR codes, with connection profiles
- Or go to `~/wireguard/config/` to see `.conf` files for every peer.

Enjoy your fresh & private VPN
Finishing books
Tags: discuss, personal, improvement, growth
Published: 2022-02-01 08:32:39

---
title: Finishing books
published: true
description: Don't be afraid to not finish a book
tags: discuss, personal, improvement, growth
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ircvzc29zf16vdhh29vw.jpeg
---

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

> Don't be afraid to not finish a book. [Reread](https://www.nikola-breznjak.com/blog/books/many-books-little-time/) the good ones.

---

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.
Create React Components using Figma and AWS Amplify Studio
Tags: aws, amplify, figma, react
Published: 2022-02-01 08:27:57

At **re:Invent 2021**, [AWS Amplify announced AWS Amplify Studio](https://aws.amazon.com/blogs/mobile/aws-amplify-studio-figma-to-fullstack-react-app-with-minimal-programming/), a visual development portal to build and operate web applications. Together with [Figma](https://figma.com), you can easily manage UI components and generate [React](https://reactjs.org/) components without any development tasks.

![React Components with Figma and AWS Amplify](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7dbopz8cswj695a813rl.png)

[**This guide**](https://sbstjn.com/blog/react-figma-amplify-studio-example/) explains how to use a default [create-react-app](https://create-react-app.dev/docs/getting-started/) with [AWS Amplify](https://aws.amazon.com/amplify/) and React components created in Figma.
Building a Full-Stack App Project in React and Spring Boot
Tags: react, javascript, java, tutorial
Published: 2022-02-01 08:02:19

Create an API in Spring Boot and a Frontend in React with this code-along tutorial. The app is a simple app with Pokémon data (stored locally in a PostgreSQL database): you can add new Pokémon with images, set the quantity of those Pokémon, and delete them. This basically covers the CRUD API functionality. On the frontend side we are using Vite to setup the app and Tailwind for styling. Additionally we will using these libraries in React: react-query, axios, @heroicons/react, and react-hot-toast.

{% youtube uIdx4DbCRd4 %}
Aquila HUB 0.2.0. is released
Tags: product, opensource, datascience, machinelearning
Published: 2022-02-01 07:49:30


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

We're excited to announce the release of Aquila HUB 0.2.0.

This release achieves 10x performance upgrades to support your traffic needs.

We're continuing and constantly evaluating experimental IPFS support in Aquila HUB. Now you can run an IPFS node and leverage the decentralized distribution of your Fasttext models. We are also planning to add support to more language models in future releases.

Release notes: https://github.com/Aquila-Network/AquilaHub/releases/tag/v0.2.0
Release blog: https://blog.aquila.network/now-available-aquila-hub-020
How to calculate total travel hours between city x and y and vice versa
Tags: sqlserver, interview, questions
Published: 2022-03-05 08:25:23

---
title: How to calculate total travel hours between city x and y and vice versa
published: true
date: 2022-02-01 07:41:25 UTC
tags: sqlserver, interview, questions, 
canonical_url: https://blog.rajanand.org/how-to-calculate-total-travel-hours-between-city-x-and-y-and-vice-versa
series: SQL Interview Questions and Answers
---

## Question

You are working for an airline company and you have received a dataset of Pilot's travel time between cities. You need to determine the reciprocal and find the total travel hours between cities. That means, the pilot's travel from city '1' to '2' and city '2' to '1' should be considered as one and then the total travel hours has to be calculated.

Write an SQL query to achieve the expected output.

![04-reciprocal-input-data-output.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1643696437905/pppVnfP9w.png)

## Answer

Let us create the test data first.

```
--create test data
USE demo;

CREATE TABLE dbo.travel_detail (
    id int identity(1,1),
    from_city varchar(100),
    to_city varchar(100),
    travel_time_hours smallint
)
GO

INSERT INTO dbo.travel_detail values
    ('Oslo','Helsinki',125),
    ('Helsinki','Oslo',110),
    ('Stockholm','Oslo',132),
    ('Oslo','Stockholm',180),
    ('Copenhagen','Helsinki',148),
    ('Helsinki','Copenhagen',84),
    ('Stockholm','Copenhagen',116),
    ('Helsinki','Stockholm',124)
GO

SELECT * FROM dbo.travel_detail

--clean up
--USE demo;
--DROP TABLE dbo.travel_detail

```

To achieve the desired result, you should swap the city names within the row based on some order. That means, you can sort the from\_city and to\_city names in a row in ascending or descending order and then keep the first city as `city_1` and the other as city\_2. To do this, you can use less than <kbd> &lt; </kbd> or greater than <kbd>&gt;</kbd> operator on `from_city` and `to_city`.

![04-reciprocal-step-1.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1643698330299/7HQnHHdEK.png)

This way you will be able to aggregate the `travel_time_hours` by grouping `city_1` and `city_2`.

```
--solution
USE demo;

select 
city_1,
city_2,
total_travel_hours = sum(travel_time_hours)
from (
    select 
    city_1 = case when from_city < to_city then from_city else to_city end,
    city_2 = case when from_city > to_city then from_city else to_city end,
    travel_time_hours
    from dbo.travel_detail
)x
group by city_1, city_2
order by city_1, city_2

```

This is the solution I have come up with. If you have achieved the output in other way, let me know in comments.

[Sign up](http://newsletter.rajanand.org/) to receive these interview questions directly in your inbox.
Day 8/100 Java
Tags: 100daysofcode
Published: 2022-02-01 07:11:44

Hey there,

Day 8/100

**Language:**
JAVA

**Time Period Spent:**
2hrs

**Course Taken:**
Udemy: Java Programming Masterclass - Tim Buchalka

**Todays Learning:**
- For Loop Recap
- While and Do while
- Code Challenges:
	
	- Sum 3 and 5 Challenge
	- Sum Odd
	- Digit Sum

**Additional Notes:**
So while loop is as per any other language. We loop through something while the condition is true. If done incorrectly, we can cause an infinite loop, or until we run out of memory for numbers to be stored into. We always want to break a loop with a condition meeting a criteria.

We use while do loop so we can define an unknown criteria. For example, a normal loop we need to define the starting step and the final step so we have a range. In a while loop we don’t need to do this.

I’ve been keeping quite entertained with this course considering my attention span on stuff is quite minimal. Seems like i've found a tutor I enjoy for once. Normally I just resort to StackOverflow questions and documentation.
Tag Breakdown🧱
Tags: webdev, html, beginners
Published: 2022-02-01 07:04:25

Have you wondered, why are we writing HTML elements like `<p>...</p>` or some structure like that?

And what the cr*p is an HTML element, in the first place?

Let me demonstrate first for an example,
```
<p>My Cat is very grumpy</p>
```

![Element anatomy from MDN documentation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q1sg69t961eqhjcot9y3.png)

**Opening tag:** It instructs a browser, "Hey you, now start reading content after me as a paragraph, or whatever the tag I meant for."
So, as

> Browsers read from Top to Bottom & Left to Right.

It will read the content as a paragraph.

**Content:** This is the part we, as a user or viewer see. So, the letters you are seeing as a word and sentence, is the part that is written as content in HTML.

**Closing Tag:** This is the sign for browsers that, "You have done a good job, now you can stop reading content as paragraph and move on for next instruction."

So, let's back to the second question: What an HTML element is?
So, in general,

> The consistency of the opening tag, content, and closing tag is called an HTML element.

But, that's not the only way of writing an element. Elements can be a lot more complex and nested in other elements. Like, hope you remembered from the last week `<h1>` tag and `<p>` tag was inside `<body>` tag/element. And we can nest other tags as well, like:
```
<p>My cat is <strong>very grumpy.</strong></p>
```
Will display 'My cat is **very grumpy.**'

But, there is some tag/element that don't need content or closing tag, ie:

```
<img src="image.jpg" alt="" >
```

This tag is used for showing an image. So, this will be an image element, but it doesn't need any content or closing tag. It's called a self-closing tag (But there is a lot. So we will dedicate our week to the image element later on.)

And tag uses attributes simply for their name or some complex instruction or accessibility. We will be discussing those in the next week so till then, stay safe.

Visit [This Web App](https://ah-jim-seed.web.app/) for all posts in one place.
Quick tutorial on how to use LESS
Published: 2022-02-01 06:54:32

**Hello folks**! This is a quick peep on how to use **LESS** in your project. This tutorial will teach how to use **LESS** with **Nodejs**.

```

// npm install 

``` 

Type in the above code to install Node and Node package manager in your computer. 

```
npm init

```  
Type this in the terminal of your project to include Nodejs in your project. This makes it possible for you to use `npm` to install various packages or libraries in your project.

After you've set up your `html` and `css` files , the next step is to use **LESS** to your desire.

- Create a LESS file with `.less` extension
- Write some LESS code 
- Now, install LESS in your project by simply typing the below code in your project terminal

 ```

// npm install -g less

```

> The `-g` makes less global in your system i.e It will be available for use in other projects

- Now you have to compile your LESS code inside your **CSS** file for it to work inside your `html` file. 
  This is done by typing the below in your project terminal

```

// lessc nameoflessfile.less nameofcssfile.css

```

This will compile your LESS code inside your CSS file and make it available for use.

> Note: You don't need to download less again in your next project since it's already global, all you have to do is just create your less file and compile it inside your css file.


[Click here to learn more about less](https://lesscss.org/features/#features-overview-feature).

Thanks for reading..
What is AWS & Should You learn AWS as a Developer?
Tags: aws, cloud, cloudarchitecture, cloudservice
Published: 2022-02-01 06:50:27


⏹️What is AWS & Should You learn AWS as a Developer?
 
- AWS Stands for Amazon Web Services is a Cloud Services Provided by amazon.
- AWS is the IaaS ( Infrastructure as a Services )
- They give you the infrastructure to build your code on.

⏹️ There are major three fully fledged cloud providers -

- Google Cloud
- Microsoft Azure
- AWS - Amazon Web Services

⏹️ Now, Should You learn AWS as a Developer?
For,


⏹️ Front-end Developers :
- There are other many sites that can do it in better way without adding complexity as in AWS.


⏹️ Back-end Developers :
- You still don't have to learn AWS until or unless you work on a project that transfers tons of data continuously.


⏹️ When You Have to Learn AWS?
- If and only if your work - Project - Company requires.
- If you are willing to explore & learn AWS.


⏹️ Just in case if You want to learn AWS :


- So in General You should start with Front-end, Back-end Move to Servers & Hosting learn about networking, Linux.

- Learn a bit about the Command line, Learn about how to deploy a server, how to deploy it on the cloud before you move to AWS.

- AWS is the Universe of cloud services or You can say it is a data center.

- You can not learn every service provided by AWS don't try to learn everything.

- Learn Services that are commonly used in industry



1. Elastic Compute Cloud (EC2) - renting a server per hour (from small to huge)

2. Simple Storage Service (S3) - Cloud object storage service.

3. Lambda - Which are Serverless Computers

4. Simple Email Service ( SES ) - a service for sending mail

5. Simple Queue Service ( SQS ) - for maintaining queue structures.

6. DynamoDB - Fast NoSQL Key-Value Database

7. Identity and Access Management ( IAM ) - cloud security service which helps you to manage users assign policies, and form groups to manage multiple users.


- These services help developers build, deploy, and scale an application in the cloud platform.


⏹️ Companies using AWS :


- Whether it’s technology giants, startups, government, food manufacturers, or retail organizations, there are so many companies across the world using AWS to develop, deploy and host applications.


- According to Amazon, the number of active AWS users exceeds 1,000,000.


Here is a list of companies using AWS :


● Netflix
● Intuit
● Coinbase
● Capital One
● Adobe
● Airbnb
● AOL
Current Projects
Tags: sdl, cpp, python, godot
Published: 2022-02-01 06:25:09

Currently, I have two(three) projects that I'm working on:

The first is my freelancing website, GhostPen.org. Anyone can use it and can do just about anything on there. It uses python/flask for the backend and vanilla web stack for front end (with jquery)

The second project is a portfolio xr website. It will feature my best works across all of my skillsets and hopefully be an amazing experience for anyone who visits.

My bonus project is something I've been chipping away at for years, and that is a developing a game engine from scratch, simply for the purpose of gaining a deeper understanding of programming and computers in general. 

I've made dozens of iterations of a game engine over the years, even before I fully understood what a game engine was. And now I  (maybe) understand it enough to explain key concepts of how it will function.
Getting ready for new ventures
Tags: keep, going
Published: 2022-02-01 06:06:34

---
title: Getting ready for new ventures
published: true
description: new year's thoughts
tags: keep,going
//cover_image: https://direct_url_to_image.jpg
---

I remember the mix of feelings when I launched my first project. I made what I considered at the time enough promotion, sadly it didn't take off at the end. First lesson learned, having a decent product it's only the beginning of the journey (flashback ends).

After more failures than successes, I am still here, getting ready for the the next rodeos. Getting ready for the ups and downs, exhausted at times when you feel your brain is going to explode processing new information. But pushing the boundaries it's always satisfying, the experiments are meant to enlighten you and shed some light to your path.

If you are a self learner it's very important to stick to this. Sooner than later this process is going to payoff. You don't know when or how, but that's the way everything fits in the future (luck is a cheap description as well). Keep coding, keep doing, keep failing but keep learning.

Let's hope for the better and get ready for the unknown...
Alpine JS : An Intro
Tags: javascript, beginners
Published: 2022-02-01 06:06:32

# Alpine JS : An Intro
## Topics
* Overview
* How to Code
* Creating a basic button

## Overview
Your new, lightweight, JavaScript framework. [-Alpine Js](https://alpinejs.dev/)

It is a light weight js framework inspired by Vue JS!

## How To Code
For it you have this script tag --
`<script src="https://unpkg.com/alpinejs" defer></script>`

but in the site it will be showing like this 
`<script src="//unpkg.com/alpinejs" defer></script>`
just add **https:** before **//unpkg.com**

so for writing code just add the script tag inside the head tag
```
<head>
  <title>Title</title>
  <script src="https://unpkg.com/alpinejs" defer></script>
</head>
```

Now in the body tag add a attribute like this
`<body x-data="data()"></body>`

Now add another script tag! And write the following inside it!
```
<body x-data="data()">
  <script>
  function data(){
    return{
      
    }
  }
  </script>
</body>
```

Now understand what was data() it would fetch all the data from here.

So becoz it is an object so add variables like this `varName : "value"`

## Creating a basic button

So lets create some variables!

```
<script>
  function data(){
    return{
      shown : false,
      click(){
        
      },
    }
  }
  </script>
```

Here there is a var called shown with false as its value, and a function named click() so lets code them all.
```
<button>Toggle</button>
<div>Content</div>
```
Add these.

Give a attribute `x-show="shown"` to the div. (x-show means if the value is being shown or not [it is an if statement], it goes away[the button] because the var shown is false if it is true the button will be visible).

Now give a attribute `x-on:click="click()"` to the button (it will run when the button is clicked).

Coding the function.

```
click(){
        this.shown = !this.shown
},
```

Now it will toggle the shown var as true and then false!

## Enjoy!

All the code :-

```
<head>
  <title>Title</title>
  <script src="https://unpkg.com/alpinejs" defer></script>
</head>
<body x-data="data()">
  <button x-on:click="click()">Toggle</button>
  <div x-show="shown">Content</div>
  <script>
  function data(){
    return{
      shown : false,
      click(){
        this.shown = !this.shown
      },
    }
  }
  </script>
</body>
```

Consider Following??

[Dev.To](https://dev.to/sumanta_thefrontdev)
[GitHub](https://github.com/SumantaGitWeb)
AWS Lambda in-built UUID
Tags: aws, javascript, node
Published: 2022-02-01 05:19:15

- Use `AWS.util.uuid.v4()` to generate UUID in AWS Lambda (NodeJS)
- No need to install https://www.npmjs.com/package/uuid.

**Example:**

```
const AWS = require('aws-sdk');

exports.handler = async (event) => {
   console.log(AWS.util.uuid.v4());
}
```
**How this works:**
Below snippet from aws-sdk-js shows - it does having uuid node dependency included.

```
  /**
   * @api private
   */
  uuid: {
    v4: function uuidV4() {
      return require('uuid').v4();
    }
  } 
```

**Benefits**
- Avoiding addition of npm dependency `uuid`.
- Reduced code size. Saves few milliseconds of cold start time.

**Option: Node.js in-built module crypto**
```
const {randomUUID} = require('crypto'); //Crypto is part of Node.js runtime since v14.17 
console.log(randomUUID());
```
Current Node.js lambda runtime 14.x does supports above code.
 
Learned about this option from @galkin comments to this post. Thank you.

Image by <a href="https://pixabay.com/users/ianza-2026973/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3044577">Ian Lindsay</a> from <a href="https://pixabay.com//?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3044577">Pixabay</a>