teleren/devto huggingface dataset:
Kotlin Convert String to Long
Tags: kotlin, string, long
Published: 2021-05-07 09:27:02

https://grokonez.com/kotlin/kotlin-convert-string-long

Kotlin Convert String to Long

In the tutorial, <a href="https://grokonez.com">JavaSampleApproach</a> will guide you how to convert <strong>Kotlin String to Long</strong>.

Related posts:
- <a href="https://grokonez.com/kotlin/kotlin-convert-string-int">Kotlin Convert String to Int</a>

<!--more-->
<strong>Working environment</strong>: 
- Java 8
- Kotlin 1.1.61
<h3>I. Kotlin toLong() method</h3>
<h2>1 String.toLong(): Long</h2>
- use method signature: <code>public inline fun String.toLong(): Long</code>

<pre><code class="language-java">
package com.javasampleapproach.string2long
fun main(args : Array&lt;String&gt;) {
	// use method:
	// -&gt; public inline fun String.toLong(): Long = java.lang.Long.parseLong(this)
	val number: Long = &quot;123&quot;.toLong();
	println(number) // 123
	
	// if the string is not a valid representation of a number
	// -&gt; throw NumberFormatException
	try{
		&quot;12w&quot;.toLong();
	}catch(e: NumberFormatException){
		println(e.printStackTrace())
		// -&gt; print on console:
		/*
			java.lang.NumberFormatException: For input string: &quot;12w&quot;
			at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
			at java.lang.Long.parseLong(Long.java:589)
			at java.lang.Long.parseLong(Long.java:631)
			at com.javasampleapproach.string2long.ConvertString2LongKt.main(ConvertString2Long.kt:12)
		*/
	}
}</code></pre>

- <code>Strig.toLong()</code> will throw a <strong>NumberFormatException</strong> if the string is not a valid representation of a number.
- <code>String.toLong()</code> just uses <code>Integer.parseLong</code> of Java for converting
-> detail: <code>public inline fun String.toLong(): Long = java.lang.Long.parseLong(this)</code>

<h2>2 String.toLong(radix: Int): Long</h2>
If we want to work with <strong>radix</strong>, we can use another method signature <code>toLong(radix: Int)</code> 
-> detail: <code>public inline fun String.toLong(radix: Int): Long = java.lang.Long.parseLong(this, checkRadix(radix))</code>

More at:

https://grokonez.com/kotlin/kotlin-convert-string-long

Kotlin Convert String to Long
Infinispan Cache Solution | Spring Cache | Spring Boot
Tags: springboot, springcache, infinispan, cache
Published: 2021-05-07 09:03:32

https://grokonez.com/spring-framework/spring-data/infinispan-cache-solution-spring-cache-spring-boot

Infinispan Cache Solution | Spring Cache | Spring Boot

Infinispan cache is a distributed in-memory key/value data store, it is a excellent cache for software system.The tutorial will guide you how to start with Infinispan by Spring Boot for making a caching solution.

Related Articles: 
- <a href="https://grokonez.com/spring-framework/spring-boot/start-embedded-gemfire-application-springboot" target="_blank">How to start Embedded Gemfire Application with SpringBoot</a>
- <a href="https://grokonez.com/spring-framework/spring-boot/create-springboot-gemfire-restfulapi" target="_blank">How to create a SpringBoot Gemfire RestfulApi</a>

<!--more-->
<div id="tuttoc" class="jsa-toc"></div>

<div id="tutcontents">
<h2>I. Technology for Infinispan cache tutorial</h2>
– Java 1.8
– Maven: 3.3.9
– Editor: Spring Tool Suite – Version 3.7.3.RELEASE
– Spring Boot: Version: 3.8.0.RELEASE
<h2>II. Overview</h2>
<h3>1. Structure of Project</h3>
<img class="alignnone wp-image-791 size-full" src="https://grokonez.com/wp-content/uploads/2016/08/spring-caching-spring-boot-infinispan-structure-of-project.png" alt="spring caching- spring boot - infinispan - structure of project" width="689" height="682" />
<h3>2. Step to do</h3>
- Create Spring Boot project
- Add needed dependencies
- Configure Infinispan cache
- Create Data Model
- Create Caching Service
- Create Web Controller
- Enable Caching
- Run & Check Result with JConsole
<h3>3. Demo video</h3>
<h2>III. Practices</h2>
<h3>1. Create Spring Boot project</h3>
Open <strong>Spring Tool Suite</strong>, on main menu, choose <strong>File-&gt;New-&gt;Spring Starter Project</strong>, input project info as below pic:

<img class="alignnone wp-image-790 size-full" src="https://grokonez.com/wp-content/uploads/2016/08/createproject-springboot-springcaching-infinispan.png" alt="createproject-springboot-springcaching-infinispan" width="580" height="721" />

Press <strong>Next</strong> button, then press <strong>Finish</strong>, Spring Boot project is created.
<h3>2. Add needed dependencies</h3>
Need Infinispan Dependencies and Spring Cache &amp; Spring Web MVC dependencies

https://grokonez.com/spring-framework/spring-data/infinispan-cache-solution-spring-cache-spring-boot

Infinispan Cache Solution | Spring Cache | Spring Boot
How to create a SpringBoot Gemfire RestfulApi
Tags: gemfire, springboot
Published: 2021-05-07 09:17:12

https://grokonez.com/spring-framework/spring-data/create-springboot-gemfire-restfulapi

How to create a SpringBoot Gemfire RestfulApi

Spring Data REST provides a mechanics for creating and retrieving an Object from Gemfire storage.
In the article, JavaSampleApproach will introduce you how to create a Gemfire RestfulAPI.

Related Articles:
- <a href="https://grokonez.com/spring-framework/spring-boot/start-embedded-gemfire-application-springboot" target="_blank">How to start Embedded Gemfire Application with SpringBoot</a>
- <a href="https://grokonez.com/spring-framework/spring-boot/infinispan-cache-solution-spring-cache-spring-boot" target="_blank">Infinispan Cache Solution | Spring Cache | Spring Boot</a>

<!--more-->

<iframe width="853" height="480" src="https://www.youtube.com/embed/miD9QwMKv48?rel=0" frameborder="0" allowfullscreen></iframe>
<div id="tuttoc" class="jsa-toc"></div>

<div id="tutcontents">
<h2>I. Technologies for SpringBoot Gemfire Restful Api</h2>
– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE

<h2>II. Overview</h2>
<h3>1. Project Structure</h3>

<img src="https://grokonez.com/wp-content/uploads/2016/12/springboot-gemfire-restfulapi-project-structure-1.png" alt="springboot gemfire restfulapi project structure" width="589" height="473" class="alignnone size-full wp-image-2375" />

<h3>2. Step to do</h3>
- Create a Spring Boot project
- Create a Java Model class
- Config Gemfire storage
- Create a Gemfire repository
- Run & Check result

<h2>III. Practices</h2>
<h3>1. Create a Spring Boot project</h3>
Open Spring Tool Suite, on main menu, choose <strong>File->New->Spring Starter Project</strong>, input project info, press <strong>Next</strong> then <strong>Finish</strong>, spring boot project will be created successfully.

<strong>Gemfire</strong> & <strong>Restful</strong> dependencies:

Open <strong>pom.xml</strong> file, add needed dependencies:

More at:

https://grokonez.com/spring-framework/spring-data/create-springboot-gemfire-restfulapi

How to create a SpringBoot Gemfire RestfulApi
How to start Embedded Gemfire Application with SpringBoot
Tags: springboot, gemfire
Published: 2021-05-07 09:11:59

https://grokonez.com/spring-framework/spring-data/start-embedded-gemfire-application-springboot

How to start Embedded Gemfire Application with SpringBoot

Gemfire is a memory caching solution for scaling software system, JavaSampleApproach will guide you how to create an Embedded Gemfire Application with SpringBoot.

Related article: 
<a href="https://grokonez.com/spring-framework/spring-boot/infinispan-cache-solution-spring-cache-spring-boot" target="_blank">Infinispan Cache Solution | Spring Cache | Spring Boot</a>
<a href="https://grokonez.com/spring-framework/spring-boot/create-springboot-gemfire-restfulapi" target="_blank">How to create a SpringBoot Gemfire RestfulApi</a>

<!--more-->
<div id="tuttoc" class="jsa-toc"></div>

<div id="tutcontents">
<h2>I. Technologies</h2>
– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE

<h2>II. Overview</h2>
<h3>1. Project Structure</h3>
<img src="https://grokonez.com/wp-content/uploads/2016/12/embedded-gemfire-application.png" alt="embedded gemfire application" width="742" height="487" class="alignnone size-full wp-image-2327" />

<h3>2. Step to do</h3>
- Create Spring Boot project
- Add needed dependencies
- Create a Gemfire Region Model
- Config Gemfire in Local model
- Implement Gemfire Repository
- Implement client for check Gemfire's working
- Run SpringBoot project and result

<h2>III. Practices</h2>
<h3>1. Create Spring Boot project</h3>
Open <strong>Spring Tool Suite</strong>, on Menu bar, choose: <strong>File->New->Spring Starter Project</strong>, input needed project's info:
<img src="https://grokonez.com/wp-content/uploads/2016/12/projectgemfire.png" alt="embedded gemfire application project info" width="501" height="469" class="alignnone size-full wp-image-2328" />

Press: <strong>Next</strong> then <strong>Finish</strong>, Spring boot project will be created

<h3>2. Add needed dependencies</h3>
- Add <strong>gemfire</strong> & <strong>spring-shell</strong> dependencies:

More at:

https://grokonez.com/spring-framework/spring-data/start-embedded-gemfire-application-springboot

How to start Embedded Gemfire Application with SpringBoot
Quick WHM/cPanel All email passwords reset 
Tags: bash, cpanel, password, script
Published: 2021-05-07 08:42:14

---
title: Quick WHM/cPanel All email passwords reset 
published: true
description: Quick and dirty script to reset ALL mailbox passwords for a single domain, under cPanel/WHM
tags: bash, cpanel, password, script
canonical_url: https://deeb.me/20210507/quick-whm-cpanel-all-email-passwords-reset
cover_image: https://deeb.me/wp-content/uploads/pexels-photo-209037.jpeg
---

You generally don’t want to use this script. This is a last resort, when all mailbox passwords for the entire account need to be changed. For this script to work, you need root access to your WHM/cPanel server. This could ruin everything, be warned!

**Here be dragons!**

```bash
#!/bin/bash
newpass='SomeStr0ngPasswordGoesHere!'
accountname='example'
domainname='example.com'

uapi --user=$accountname Email list_pops \
  | grep email \
  | awk '{print$2}' | awk -F\@ '{print$1}' | \
  while read m; do
    echo changing password for $m
    uapi --user=@accountname Email passwd_pop domain=$domainname email=$m password=$newpass
  done
echo done
```


Here are the links to the official API docs:

- https://documentation.cpanel.net/display/DD/UAPI+Functions+-+Email%3A%3Apasswd\_pop
- https://documentation.cpanel.net/display/DD/UAPI+Functions+-+Email%3A%3Alist\_pops

**Is there a better way to do this?** probably

**Can I randomize the password?** sure, but how will you send the new passwords to your users?

Hope it helps!
My Binary Search Solution is better than yours 
Published: 2021-05-07 07:57:26


```
const binary = (val, arr) => {
  let lower = 0;
  let upper = arr.length - 1;
  while (lower <= upper) {
    console.log("ols");
    const middle = lower + Math.floor((upper - lower) / 2);
    if (val === arr[middle]) {
      return middle;
    }
    if (val < arr[middle]) {
      console.log("right");
      upper = middle - 1;
    } else {
      console.log("left");
      lower = middle + 1;
    }
  }
  return -1;
};
```
How much time do you spend writing tests?
Tags: watercooler, webdev, testing
Published: 2021-05-07 07:46:16

---
title: How much time do you spend writing tests?
published: true
description: 
tags: watercooler, webdev, testing
cover_image: https://qabyexample.com/wp-content/uploads/2019/01/test-driven-development-header.png
---
It’s a decades-old debate of whether developers should write tests or not. While some think it’s important, others believe that it may be too much to ask from developers.

How much time do you spend writing tests?
How do you create your invoices?
Tags: watercooler, productivity, startup, finances
Published: 2021-05-07 07:30:28

---
title: How do you create your invoices?
published: true
description: 
tags: watercooler, productivity, startup, finances
cover_image: https://blog.hubstaff.com/wp-content/uploads/2017/08/the-complete-guide-to-invoicing-and-payments-for-freelancers.png
---
With a proper invoice app all your billable hours, products, and taxes are all added up in a snazzy invoice. This is especially useful for smaller business owners or freelancers.

My favorite is a free, open-source project [Manta](https://github.com/hql287/Manta) - a desktop application for creating invoices with beautiful and customizable templates.

What tools do you use to create invoices?
Well that was easy - my first contribution to bugsmash
Tags: devbugsmash
Published: 2021-05-07 07:19:30


I've been coding for years, but I'm new to the whole open source thing so I decided that the bugsmash would be a fun way to get more involved. 

#### About The Bug

So I went to the issue list and picked a bug that I thought would be quite straight forward based on my previous coding experience. 

{% github https://github.com/forem/forem/issues/4079 %}

The bug said that embeded comments didn't work as expected, and that the html inside the comment broke.

### How I Smashed It
The first step to fixing a bug is to reproduce the behavior you want to fix. So thats what I did. The "problem" was that I was not able to reproduce it. After a couple of tries, and a look at the source code my conclusion was that it was probably fixed unknowingly in an earlier release. The rendering of the html was completely different when embedding a comment today - than it was in the broken comment from the original issue. 

So I added a comment to the issue, sharing my conclusion. And it was approved as a valid bug-smash. Even though I technically didn't to anything else than research. :)

### Reflection
It felt almost to easy. But at the same time I feel very velcome in the community, and like the DEV team really appreciated my effort even though I didn't code anything. At least they were able to close the issue! 

I will definitly see if there is another bug I can smash too!
HTML : Headings
Tags: codenewbie, codequality
Published: 2021-05-07 07:16:27

HTML provides not only plain paragraph tags, but six separate header tags to indicate headings of various sizes and thicknesses. Enumerated as heading 1 through heading 6, heading 1 has the largest and thickest text while heading 6 is the smallest and thinnest, down to the paragraph level. This topic details proper usage of these tags.

# Using Headings
Headings can be used to describe the topic they precede and they are defined with the `<h1>` to `<h6>` tags. Headings support all the global attributes.
`<h1>` defines the most important heading.
`<h6>` defines the least important heading.

# Defining a heading:
```html
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
```

# Correct structure matters
Search engines and other user agents usually index page content based on heading elements, for example to create a table of contents, so using the correct structure for headings is important.

In general, an article should have one h1 element for the main title followed by h2 subtitles – going down a layer if
necessary. If there are h1 elements on a higher level they shouldn't be used to describe any lower level content.

# Example document 
```html
<h1>Main title</h1>
<p>Introduction</p>
 <h2>Reasons</h2>
 <h3>Reason 1</h3>
 <p>Paragraph</p>
 <h3>Reason 2</h3>
 <p>Paragraph</p>
 <h2>In conclusion</h2>
 <p>Paragraph</p>
```

<a href="https://www.buymeacoffee.com/rkycom" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>

With all that being said, I highly recommend you keep learning!

Thank you for reading this article. Please feel free to connect with me on [LinkedIn](https://www.linkedin.com/in/www-rajeshkumaryadav-com/) and [Twitter](https://twitter.com/rky_com).
Go Crash Course Part VI: Blocks, Scopes and Shadowing
Tags: go, beginners, programming
Published: 2021-05-07 07:15:58

## Blocks

In go a block is defined with a set of `{}`. Usually when we create a function we are in a block already. But we can define a block pretty much anywhere.

```go
i := 10
{
	i := 5
	fmt.Println(i) // i is 5
}
fmt.Println(i) // i is 10
```

## Scope

Scope defines where certain variable would be defined in. A scope can be block scoped, function scoped or package scoped. Each scope encompasses the previous. A package scoped variable would be available to the function and block but not the other way around. 

```go
x := 10
var z int // z declared here
{
	fmt.Println(x) // this is fine
	y := 15
	z = 20 // defined here 
}
fmt.Println(y) // this is not fine
fmt.Println(z) // this is fine
```

## Shadowing

We can shadow any variable that is defined in the outer scope. 

```go
x := 10
{
	x := 15
	{
		x := 20
		fmt.Println(x) // 20
	}
	fmt.Println(x) // 15
}
fmt.Println(x) // 10
```

Just block level shadowing is uncommon. There are rare use cases for this. But I haven't found really good use case for block level shadowing or even for blocks for that matter.

## Next Steps

This is Part 6 of this Go crash course series.
HTML : Doctypes in HTML5
Tags: codequality, html
Published: 2021-05-07 07:06:45

Doctypes - short for 'document type' - help browsers to understand the version of HTML the document is written in for better interpretability. Doctype declarations are not HTML tags and belong at the very top of a document. This topic explains the structure and declaration of various doctypes in HTML

# Adding the Doctype
The <!DOCTYPE> declaration should always be included at the top of the HTML document, before the `<html>` tag.

See HTML 5 Doctype for details on the HTML 5 Doctype.
```<!DOCTYPE html>```

# HTML 5 Doctype
HTML5 is not based on SGML (Standard Generalized Markup Language), and therefore does not require a reference to a DTD (Document Type Definition).

HTML 5 Doctype declaration:
`<!DOCTYPE html>`

# Case Insensitivity
Per the W3.org HTML 5 DOCTYPE Spec:
>A DOCTYPE must consist of the following components, in this order:
1. A string that is an ASCII case-insensitive match for the string "<!DOCTYPE".

therefore the following DOCTYPEs are also valid:
```<!doctype html>
<!dOCtyPe html>
<!DocTYpe html>```

<a href="https://www.buymeacoffee.com/rkycom" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>

With all that being said, I highly recommend you keep learning!

Thank you for reading this article. Please feel free to connect with me on [LinkedIn](https://www.linkedin.com/in/www-rajeshkumaryadav-com/) and [Twitter](https://twitter.com/rky_com).
JUnit5 Unit Testing, Test events were not received.
Tags: kotlin, junit5, test, android
Published: 2021-05-05 17:19:42

---
title: JUnit5 Unit Testing, Test events were not received.
published: true
description: JUnit5 Unit Testing noob error
tags: kotlin, junit5, test, android
---

#The Problem
I came from Junit4 testing, and I want to try Junit5 and started writing some unit tests and I'm curious why I received this message: ```Test events were not received.```

After some digging I've found out more detailed errors:
```
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':splash:testDebugUnitTest'.
> No tests found for given includes: [com.raquezha.heograpiya.splash.SampleTestTest](filter.includeTestsMatching)
```

So I google on how to solve the problem and stumble on this site [gradle.org site](https://docs.gradle.org/current/userguide/java_testing.html#using_junit5)


I just have to add this code to enable JUnit Platform to run my tests:

Gradle DSL (build.gradle)
```
test {
    useJUnitPlatform()
}
```
Kotlin DSL (build.gradle.kts)
```
tasks.named<Test>("test") {
    useJUnitPlatform()
}
```

But after adding those code another problem occurred:


``` A problem occurred evaluating project ':app'.
"> Could not find method test()" ```

I've added this because maybe for some this is the solution but unfortunately this did not work for me. If above did not work for you can try the solution below.

#Solution
After digging a little because all of my searches were not working I stumble upon this stackoverflow [post](https://stackoverflow.com/questions/58168384/how-to-run-tests-by-gradle-instead-of-intellij-with-junit5-and-springboot2-in-mu) it turns out I'm missing one import!


I just add this missing dependency:
```
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.0-M1'
```
And after successful gradle sync, tadah!
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/826v4n82a2m87qbtjn2b.png)

I hope this helps someone fix this noob error.

--

Here's what I'm using
1. Android Studio Arctic Fox | 2020.3.1 Canary 15
2. Gradle 7.0
3. Kotlin 1.5.0
4. Dependencies
```
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.0-M1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.0-M1'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.0-M1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.0-M1'
```
HTML : Creating a simple page in HTML5 (Beginner's Guide)
Tags: html, codenewbie, developer, programming
Published: 2021-05-07 06:57:54

The following HTML example creates a simple "Hello World" web page.
HTML files can be created using any text editor. The files must be saved with a .html or .htm extension in order to be recognized as HTML files. Once created, this file can be opened in any web browser.
```html
<!DOCTYPE html>
<html lang="en">
 <head>
 <meta charset="UTF-8">
 <title>Hello!</title>
 </head>
 <body>
 <h1>Hello World!</h1>
 <p>This is a simple paragraph.</p>
 </body>
</html>
```

#Let's understand each of tags - 

**`<!DOCTYPE>`** - Defines the HTML version used in the document. In this case it is HTML5.

**`<html>`** - Opens the page. No markup should come after the closing tag (`</html>`). The lang attribute declares the primary language of the page using the ISO language codes (en for English).

**`<head>`** - Opens the head section, which does not appear in the main browser window but mainly contains information about the HTML document, called metadata. It can also contain imports from external stylesheets and scripts. The closing tag is `</head>`.

**`<meta>`** - Gives the browser some metadata about the document. The charset attribute declares the character encoding. Modern HTML documents should always use UTF-8, even though it is not a requirement. In HTML, the <meta> tag does not require a closing tag.

**`<title>`** - The title of the page. Text written between this opening and the closing tag (`</title>`) will be displayed on the tab of the page or in the title bar of the browser.

**`<body>`** - Opens the part of the document displayed to users, i.e. all the visible or audible content of a page. No content should be added after the closing tag `</body>`.

**`<h1>`** - A level 1 heading for the page

**`<p>`** - Represents a common paragraph of text.

<a href="https://www.buymeacoffee.com/rkycom" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>

With all that being said, I highly recommend you keep learning!

Thank you for reading this article. Please feel free to connect with me on [LinkedIn](https://www.linkedin.com/in/www-rajeshkumaryadav-com/) and [Twitter](https://twitter.com/rky_com).