teleren/devto huggingface dataset:
Solution: The verse with the maximum number of appearances
Tags: java, solution, programming, algorithms
Published: 2021-02-20 07:42:05

Problem: Given a poem, with each verse on a new line, Find the verse (or verses) that have the maximum number of appearances and how many times it appears in the text.

[![Play Framework Java Course](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kp4dvf528qhlo0egwx4t.png)](https://courses.petrepopescu.tech/)

Solution:
```java
public static List<Pair> max2(String fullText) throws Exception {
        // If there is no text provided, throw an exception
        if (fullText == null || fullText.isBlank()) throw new Exception("No text provided");

        // We split it by line separator so that we get all the verses. We also do a 'toLowerCase' so that
        // we analyze it case-insensitive
        String[] split = fullText.toLowerCase(Locale.ROOT).split("\n");

        // Create a List from the verses (so that we can use Streams
        // And a HashSet, so that we have each verse only once
        List<String> verses = Arrays.asList(split);
        Set<String> uniqueVerses = new HashSet<>(verses);

        // Now, let's process it
        return uniqueVerses.stream()
                // We map each line to a Pair that has the line and the frequency it appears in the text
                .map(line -> new Pair(line, Collections.frequency(verses, line)))

                // We collect it and group them by the number of appearances, now, we will have groups (Map) with the
                // Number of appearances as the key and the list of verses as the value
                .collect(Collectors.groupingBy(p -> p.getValue()))

                // We make the result a Stream so that we can find the MAX
                .entrySet().stream()

                // Get the group that has the maximum number of appearances
                .max(Comparator.comparingInt(p -> p.getKey().intValue()))

                // Retrieve the result and get the List. It will be a List of Pair<String, Integer>,
                // where the Key is the verse and the value is the number of appearances
                .get().getValue();
    }
```

Conclusions:
Using the power of streams, we can easily manipulate our data set to do groupings, counting, and finding the maximum. No need for complex for-loops or external libraries.
(My) Simple Home Wifi Router Login Session Management(Cookie)
Published: 2021-02-20 07:28:24

I saw this, while i was making a change in my Wifi Router Setting,

If i think from a Security Perspective:
Basically My Wifi Router Web Interface is very unsecure, well i think it should use a better approach, this is the worst possible,
I know about JWT, this is PWT(Plain Web Tokens) 😬
Let's see why...

**Snap1: Shows Cookie With Content containing Username and Password in Bas64**
 ![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l5gyp4hvd7jk256mz5g1.png)
So Over here, we can see The Cookie Header contains a HTTP Header (Authorization) in form a Cookie name&value and the value contains the username&password that i just entered.

Base64!!! Hmmm Nice

**Snap2: A Closer look at Cookie Containing Username and Password in Bas64**
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kb9kdr13wrb61kl0blt7.png)
 
**Snap3: Dev Tools are amazing the Network Tab has a Column Initiator Tells from where this the Request Originated, the whole Stack Trace (Beginning from the Click Event Fired)**
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gkqkah4jylfiezubttqq.png)

**Snap3: Finally the Code how cookie was set, Basically by Client JS**
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tam8romhqkxnm6mk7uvr.png)


**If i think from a Router's Actual Work:**
Then in that case it has nothing to do with the Web Interface.
Web Interface are for us to manage few things and that too mostly used in Internal Network


> **Behind the Scenes (My Mind Conversation & Thoughts)**

> But if someone who is part of the network but does not have access can SNIFF the Traffic and capture these details
But this is totally contradictory, since he could have SNIFFED the Initial Login Traffic and received the details and Also the Web Interface is usually over Plain HTTP.
Show a file with Nodejs.
Tags: node, javascript
Published: 2021-02-20 06:46:22


Hello, this time I want to share a small code that shows how to create a function that allows displaying a file with nodejs. At a time when the need arises to be able in our API to create an endpoint that allows generating a saved file from the back-end.

*As a first step we will create a controller that will allow us to generate the functionality*
```js
const viewDocument = (req,res) => {}
```
*Inside we will use a trycatch to recover errors*
```js
const viewDocument = (req,res) => {
try {
			
	} catch (err) {
		return res.status(500).json(err)
	}
}
```
*Now if we can start with the logic, with the node __path__ module we are going to recover the address of the file that we are going to show*
```js
let filepath = path.join(__dirname,"../public/archive","file.pdf")
```
__fs__ will do the job, with its __readFile__ property it will read the path and take the file. With the callback we hope to evaluate the error if there is none, we use the res property, __contentType__ where we assign the media type of the resources and then with the __send__ property we send the file.
```js
fs.readFile(filepath, (err,data) => {
			if(err){
				return res.status(500).json(err)
			}
			res.contentType("application/pdf")
			res.send(data)		
		})
```

*The complete code looks like this:*
```js
const fs = require("fs");
const path = require("path");

const viewDocument = (req,res) => {
	try {
let filepath = path.join(__dirname,"../public/archive","file.pdf")		

fs.readFile(filepath, (err,data) => {
			if(err){
				return res.status(500).json(err)
			}
			res.contentType("application/pdf")
			
return res.send(data)		
		})
	
		
	} catch (err) {
		return res.status(500).json(err)
	}
}
```
I hope it helps you.
Executable for our demo application
Tags: python, eel, pyinstaller, exe
Published: 2021-02-20 06:22:48

In our previous posts we have explored [Eel](https://github.com/ChrisKnott/Eel) library, along with its options and we have created a demo application.

This post is mainly dedicated to pyinstaller, which is a python library which allows to easily distribute python code. Pyinstaller will help us to distribute our eel application.

First step is to install pyinstaller:
```
pip install pyinstaller
```
Pyinstaller also supports encryption of Python bytecode modules, in order to use this feature, it must be installed:
```
pip install pyinstaller[encryption]
```

As we have installed the required libraries, we are going to explore how can we distribute our application.

# Create exe file (windows)

Remember to `cd` to our project folder, our python script is named app.py and "web" folder contains out html, css and js. We can create an exe file (under windows, .so under mac or linux) with the following command:
```
python -m eel app.py web
```
Pyinstaller will analyze our python script, will create a spec file, will create a folder named build for holding log and working files and finally will create a folder named dist for writing the executable. Dist folder is the one we should send to our users.

The output from the previous command will be a folder (dist) which contains all python dependencies and our exe file, which is the one we should run. However, it would be better to distribute a single file instead of a folder with several number of folders, subfolders and files. 

A single executable file can be built with the following command:
```
python -m eel app.py web --onefile
```
# Hiding console window

With the previous command, a single file has been created, this is easier to distribute and for the user; however, if we run our exe file we can notice that the chrome window appears but a command window also does.

Hiding the command window can be achieved by adding a flag to our current command:
```
python -m eel app.py web --onefile --noconsole
```

Now we have a single executable file and once it is executed, a single window will show up. Finally, what we can do is add encryption of our bundled files, this can be achieved with the key flag and a key of lenght equal to 16.

```
python -m eel app.py web --onefile --noconsole --key=abcdefghijklmnop
```

Now we are capable of distributing our python applications with a user friendly GUI in a single executable file. 

There is still one issue, executable files will work only on the same platform where it was built, e.g., an executable file generated on windows 10 - 64 bit won't work on windows 10 -32 bit, or in windows Server. Obviously, it also won't work on MAC OS or linux based OS. 

So you must build your executable on all the platforms where you want to distribute your application. For achieving this, you can explore task automation tools which allows you to perform continuous integration and continuous delivery.

One CI/CD popular tool, is Jenkins. We might have a Jenkins series in the near future.
When will we start paying for open source modules?
Tags: opensource
Published: 2021-02-20 06:15:43

Is there a world in which we pay for what we now use for free?

I would love to see a world where developers can build what they love and make a living doing it. Recent innovations like [Github sponsors](https://github.com/sponsors), and Patreon have allowed some [prominent open source contributors](https://github.com/sponsors/sindresorhus) the ability to work full time on their open source projects which I think is really cool. 

If you take any project's dependency tree it's filled with a pyramid of hundreds of modules. I could image a payment structure that somehow divided down fees for each package perhaps based on a set of criteria perhaps module size, version count, commit count, where the price would be fractions of a cent over a period of time. 

Imagine using a module and paying $0.15 per month. For a small module that gets 4,018 downloads a month thats around $600 for that one module. 

I think we've taken for granted this era of technology where companies valued in the millions are built using hours of free labor. 

As someone who loves creating open source projects, it would be nice if as a developer I could lead a different self-guided way of making money that didn't revolve around working for a large tech company.
Add time stamp in your shell prompt 
Tags: bash, shell, terminal, linux
Published: 2021-02-20 06:00:12

Bash prompt can be set by setting the environment variable `PS1`. We need to update this variable to get time in our prompt.

There are 4 ways to get the time in prompt. If you see manual page for `bash`, you can see time can be set using:
```
\t     the current time in 24-hour HH:MM:SS format
\T     the current time in 12-hour HH:MM:SS format
\@     the current time in 12-hour am/pm format
\A     the current time in 24-hour HH:MM format
```
Note that the time is not the current time but the time when prompt was last updated. Prompt will be updated when previous command completed.

Sample usage:
```sh
PS1="\t $ "   # 11:13:54 $ 
PS1="\T $ "   # 11:14:01 $ 
PS1="\@ $ "   # 11:14 AM $ 
PS1="\A $ "   # 11:14 $ 
```
Add whichever style you like to your `$HOME/.bashrc` and every time you open a new terminal, you will see time in command prompt.

If you wish to show current directory with time in prompt, a nice prompt setting could be like
```sh
PS1="\w \A $ "
PROMPT_DIRTRIM=2
# Resulting in prompt to look like
# ~/.../bluetooth/nimble 11:16 $ 
```
Here `PROMPT_DIRTRIM` would set the number of parent directories you wish to see in the prompt.

Checkout [designing a minimal bash prompt](https://dev.to/chhajedji/minimal-and-super-useful-shell-prompt-1g8l).
How can I cache output of a method's parameters, so I don't have to create a new object when the input(s) are the same?
Tags: csharp, help, beginners, janky
Published: 2021-02-20 05:26:35

I'm working on Janky in C\#, and I have a `JankyToken` class. I'm gonna be making a lot of `JankyToken`s, so I need to know, how can I make a method (`Create`) of `JankyToken` that will cache it?

This is what I have so far:
```csharp
// NOTE: `Type` is short for `JankyToken.Type` which is an
// enum that describes the token (e.g. `GT`, `LTEQ`, `ASS`, etc...).

/**
* @param type The type of token.
* @param value Additional data that describes custom tokens (e.g. Identifiers).
*/
public JankyToken Create(Type type, String value) {
    cache = /* Some method of retrieving the cached params */;
    if(cache != null) return cache;
    else {
        result = new JankyToken(type, value);
        /* Some method of caching the result */
        return cache;
    }
}
```

<div alt="Thanks! Cheers!">
##<b><center><b>Thanks!<br/>Cheers!</b></center></b>
</div>
Volunteer for COVID Project
Tags: covid, ai, smartphone, detection
Published: 2021-02-20 05:21:39

Hey all! I'm not sure if it's the appropriate place to ask, and if not really apologize.

I'm running a nonprofit with young researchers from 20 countries and we're building a smartphone app to detect COVID. We've got our new website designed in Figma but need a React developer to finish coding off the work left behind by a volunteer who just quit. Can anyone help? If so, please find more details here:

https://virufy.org/join.html
Header files in C
Tags: programming, cprogramming, tutorial, beginners
Published: 2021-02-20 05:14:52

In this tutorial, we will learn what are <a href="https://usemynotes.com/what-are-header-files-in-c/">header files in c</a> programming and the types of header files, and how to use header files.  So let us go into the deep models.

##What are header files in c?

Header files are those files in which c functions declaration and macro definitions are shared between various source files. By using the header files we can save time as the program becomes short and readable. There are two types of header files built-in header files and user-defined header files. 

The header files serve two purposes: first, the system header files declare the interface to the parts of the operating system. They help in supplying the definition and declaration needed for invoking the system calls and libraries. Secondly, the header files contain the declaration for interfaces between the source files of the program.

All the header files have a ‘.h’ extension. This extension contains a c function declaration and the macro definitions. The header files can be requested using the preprocessor directive which is #include.
 
##What are the types of header files?
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6dqppce8mb35uz0exiyn.png)

There are 2 types of header files

<table>
<ul>
<li>Built-in the header file</li>
<li>User-defined header file</li>
</ul>
</table>

###Built-in header file

This is the header file that is provided by the compiler. We can not change anything in the built-in header files. Header files provide the basic functionality. 

<b>For example -</b>
```
    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    #include <stdlib.h>
    #include <time.h>
    #include <ctype.h>
    #include <conio.h>
    #include <float.h>
```
 
###User-defined header file

The User-defined header files are defined by the user. These are created using the file program. The user-defined header files are like the built-in header file.

<b>For example:</b> #include “File_name.h”

 
##How to use header files?

To use these Header files in a program we have to use the #include directive. Whenever we want to include built-in header files we write < > (angle brackets).

----

-Learn into deep - <a href="https://usemynotes.com/what-are-header-files-in-c/">Header Files in C</a>
Hacktoberfest 2020 shirt arrived
Tags: hacktoberfest
Published: 2021-02-20 03:49:05

I managed to finish the challenge despite that the rules changed 3 times during the month. Most of my contributions went to [DefinitelyTyped](https://definitelytyped.org/), a collection of TypeScript definitions that make my own life easier.

![a blue T-shirt with some stickers on top of it](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4pyhgkb0uds3n9lyrdnq.png)

I picked the dark-colored shirt, so that it wouldn't get ruined if I decide to roll around in the mud. Yes I still do that, because it relieves stress.
Changing React's custom 'Atom' icon using favicon.io in 4 easy steps
Tags: react, favicon, javascript, beginners
Published: 2021-02-20 03:34:59

React is a great framework! Deploying my react projects on Netlify and other host servers has been just as easy. 

Amongst the bunch of free packages that come with a react npm (npx) install is React's custom Atom icon that shows on the browser's tab,both on the localhost workspace and on your app's deployment. 



![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w0phzcqva3oeb9dlwyfy.jpg)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/igmp8a84gsmxucucfjul.jpg)

This isn't a big deal for practice projects, however for personal projects, be it a personal portfolio or a work project, the Atom icon 'gats to go'.


CHANGING THE ATOM ICON:
STEP 1- DELETE the favicon.ico file in your react's public folder.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e81uxqnfwb43tmgl6tb0.png)

This contains the already existing Atom icon and doing a hard refresh on your browser AFTER DELETING the file will remove the Atom icon from your tab, which is an ok place to stop if all you wanted was to get rid of the Atom icon.
If you do however want to replace the Atom icon with an icon of say, your initials maybe, or a more custom logo, then on to step 2.

STEP 2- Visit favicon.io and make your custom icon - https://favicon.io/ .
It's basically a straightforward site to use. No signups!😁. It has an option to convert either images, texts or emojis to icons with really easy edit options. Explore, design, create.

STEP3- Download your icon in it's zip format and extract your icons.

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

I abbreviated my name to 'CN' in my favicon example, edited with a red font and a black background.


STEP 4- Copy the image named favicon.ico into your code editor and rename it to 'favicon.ico'(or whatever your old deleted Atom icon was saved as) and you're good to go!

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

It should look something like this in your code editor-

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

That's it!

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

N.B- You will need to do a hard browser refresh (Ctrl + F5 in Windows OR Shift + Reload button in Mac) or clear browser cache manually for the new icon to override the old cached one.
Generate dbdiagram.io Diagrams for Your Database
Tags: database, erdiagram
Published: 2021-02-20 03:04:22

---
title: Generate dbdiagram.io Diagrams for Your Database
published: true
description: 
tags: #database, #erdiagram
//cover_image: https://direct_url_to_image.jpg
---

# Generate dbdiagram.io Diagrams for Your Database

[dbdiagram.io](https://dbdiagram.io/home) from [Holistics](https://www.holistics.io/) is an online tool to allow you to draw database schema diagrams online using their own [Database Markup Language (DBML)](https://www.dbml.org/home/). You can learn syntax in minutes, but it may take you longer to represent your database. SchemaCrawler generates DBML syntax from your existing database. Then you can see what it looks like in the [dbdiagram.io online editor](https://dbdiagram.io/d), as well as make modifications. The advantage of having the DBML file is that you can use the [DBML CLI](https://www.dbml.org/cli/) to generate DDL  to create the database in a variety of dialects, including MySQL and PostgreSQL.

Try it out. Make sure that you have [Docker](https://docs.docker.com/desktop/) installed on your system, or download [SchemaCrawler](https://www.schemacrawler.com/). Download a sample SQLite database called ["chinook-database-2.0.1.sqlite"](https://github.com/schemacrawler/chinook-database/releases/download/v16.11.7/chinook-database-2.0.1.sqlite) into your current directory.

Then run a command like:

```sh
docker run \
--mount type=bind,source="$(pwd)",target=/home/schcrwlr/share \
--rm -it \
schemacrawler/schemacrawler \
/opt/schemacrawler/bin/schemacrawler.sh \
--server=sqlite \
--database=share/chinook-database-2.0.1.sqlite \
--info-level=standard \
--command script \
--script-language python \
--script dbml.py
```

(If you are using PowerShell on Windows, replace the trailing backslash on each line with a back-tick "`".)

Copy the output into the [dbdiagram.io online editor](https://dbdiagram.io/d) and see what it looks like. Once you have got this working, you can connect to any database - whether Oracle, MySQL, PostgreSQL, Microsoft SQL Server, IBM DB2 or any other database that SchemaCrawler supports. And if you like, you can download the [DBML CLI](https://www.dbml.org/cli/) to generate DDL  to create the database.

You can build the DBML generation in a GitHub Action or GitLab build too. An example is in the [schemacrawler/SchemaCrawler-Action-Usage-Example](schemacrawler/SchemaCrawler-Action-Usage-Example) repository.

If you want to customize the script, grab the source from  of ["dbml.py" from SchemaCrawler's GitHub repository](https://github.com/schemacrawler/SchemaCrawler/blob/master/schemacrawler-scripting/src/test/resources/dbml.py), and follow instructions on the [scripting gist](https://gist.github.com/sualeh/4aebf7098f5907467df20d00f03962cd).

To learn about how to use SchemaCrawler, download the [SchemaCrawler distribution zip file](https://github.com/schemacrawler/SchemaCrawler/releases/) and go through the examples.
Is Axios Isn't Trust Worthy Anymore 😒
Tags: javascript, axios, webdev, alert
Published: 2021-02-20 02:37:23

Hello DEVs, currently I'm working on a MERN Stack project and using Axios to fetch the backend API. However, from last 3 days I'm facing installation and usability issue with Axios. I checked NPM Registery and got myself correct.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xffnbkwmw19w02z1jn5n.jpg)
As you can see on the above image, Axios is failing on build. 
Now, being a huge community and getting so much of dependants this irresponsibility is not expected. 
I've started using fetch() instead. Let me know if you have any strong and stable recommendation. 
Happy Coding🥂