teleren/devto huggingface dataset:
Right way to compare double and float in Java?
Tags: java, programming, coding, development
Published: 2022-12-02 05:29:40

---
title: Right way to compare double and float in Java?
published: true
description: The right way to compare double, float and other floating point values in Java with example and explanation
tags: java, programming, coding, development
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2022-11-26 08:45 +0000
---
If you have been doing Java programming then you may know that the use of == operator is not the correct way to compare floating point values in Java. If you use equality operator to compare float and double variables then it can cause an endless loop in Java, but is there a way to prevent that loop from running infinitely? Yes, instead of using == operator, you can use relational operator e.g. less than (<) or greater than (>) to compare float and double values.

By changing the above code as following, you can prevent the loop from infinitely  :

```java
for(double balance = 10; balance > 0; balance-=0.1) {\
   System.out.println(balance);\
}
```

If you think little bit than you will realize that greater than will definitely end this loop, but don't expect it to print numbers like 9.9, 9.8, 9.7 because floating point numbers are just approximation, they are not exact. Some numbers e.g. 1/3 cannot be represented exactly using float and double in Java.

After running following program in your computer you may end up with something like this

##Java Program  to compare float and double values:
Here is the complete Java program to check if two float or double values are equal, greater or less than of each other. 

```java
public class FloatComparator {

    public static void main(String args[]){
        float firstValue = 10.2f;
        float secondValue = 10.3f;
        float thirdValue = 10.2f;

        if(firstValue > secondValue){
            System.out.print("First Value and second value are not equal");
        }

    }
}
```
 
By the way, this is not the only way, you can also use equals() method of Wrapper classes like Float and Double to do the floating point comparison. They are in fact preferred way if you want to check if two floating point values are equal or not but if you just want to know that they are not equal then using < and > operator is rather easy.

That's all about right way to compare float and double values in loop in Java. This simple trick of using logical operator less than and greater than instead of equality operator to compare float and double variable can save you a lot of headache.
Scrum Master Training in Chennai
Tags: scrummaster, course
Published: 2022-12-02 05:18:23

IntelliMindz [Scrum Master Certification in Chennai](https://intellimindz.com/scrum-master-training-in-chennai/) is your gateway to learn the most popular project management methodology. Our Scrum Master training in Chennai positions you to become a master of Agile adoption in an organization with maximizing results. This Scrum Master Training in Chennai introduces the best practices of Scrum methodology. Master the Scrum project management approach and enhance your ability to develop and deliver quality products to Customers.

IntelliMindz Scrum Master course in Chennai is a hands-on practical oriented and interactive Course designed to enhance your knowledge of Scrum. This Scrum Certification training is best for anyone eager and willing to learn Scrum Master. We at IntelliMindz provide a comprehensive overview of the Scrum framework for project management and will prepare you to become a certified Scrum Master Professional. This Scrum Master training in Chennai at IntelliMindz will open a wide range of opportunities for you in multiple industrial sectors.
How To Explain Test Automation Framework To The Interviewer(With 2 Examples)
Tags: webdev, beginners, programming, tutorial
Published: 2022-12-02 03:31:45

Test Automation Framework Interview Questions: In this video, I am going to explain, How To Explain  Test Automation Framework To The Interviewer. No matter if you are explaining the Framework in your Telephonic interview or in person, You can use this mind map to explain in a simple manner. 

{% embed https://youtu.be/FdTfbGlrPIk %}

#automationtesting  #testautomation #testautomationframework #scrolltest

👨‍🎓 Become an Automation Rockstar  : https://thetestingacademy.com/


✅  Subscribe​ to The Testing Academy Channel.
→ https://sdet.live/89q8


🔔 TURN ON NOTIFICATIONS🔔 

I have discussed about two Test Automation Framework in Java, TestNG selenium and Web-driver, ReportNG, POM, POI lib, Maven Project.

Download Test Automation Framework #1 : https://github.com/barancev/webdriver...


Mind Map : https://mm.tt/1380022206?t=6OwQFbLDNy


Download  Test Automation Framework #2 :
https://github.com/PramodDutta/PageOb...

with Playwright 
https://github.com/PramodDutta/Playwr...


-----------------------------------------------------

👪 Join our Community - http://bit.ly/learntesting2019


✅ Automation Community - https://thetestingacademy.com


🐦Follow us on Twitter  - https://twitter.com/itstechmode


📖 Like us on Facebook - https://www.facebook.com/scrolltest


🎤  Listen to our Podcast - https://anchor.fm/thetestingacademy


-------------------------------------------------------
🚀 Tools and services I recommend:
Some of the courses that I recommend to become better Automation Tester 🙌🙌

✅Selenium Training and Certification -
https://scrolltest.com/go/edureka


✅Learn Jenkins for QA -
https://bit.ly/learnjenkins-p1


✅Programming Java -
https://bit.ly/learnjava2020-p1


✅Test Automation - 
https://bit.ly/learnautomation2020


✅API Testing - 
https://www.learnapitesting.com


✅Cypress Tutorial with LIVE Projects -
http://cypresstutorial.com


#TheTestingAcademy
— The Testing Academy
macにasdfをinstallする
Tags: webdev, programming
Published: 2022-12-02 04:23:06

## asdfってなに？
https://asdf-vm.com/

asdfとは各種プログラミング言語のバージョン管理を行うことができるクライアントツールです。
rubyだとrbenv、nodejsだとnodenv、またそれらを一括で管理できるようにanyenvといったコマンドツールを利用していましたが、昨今の開発現場では様々な言語・ミドルウェアが利用されるため、もともとanyenvで管理していたものをasdfに乗り換えてみようということです。

Dockerに閉じ込めてしまえばいいのでは？と思うこともありますが、まあそれはそれで・・・といった感じです。

## 準備
[Getting Started](https://asdf-vm.com/guide/getting-started.html)の通りに進めていけばすんなり設定できると思います。

いくつか方法はありますが、今回はmac上でかつzshを利用しているシーンでのインストール方法をいくつか記載します。

### git clone
gitとcurlはインストールされている前提です。

```
$ git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.2
```
branchは適時確認します。

```
$ echo '. $HOME/.asdf/asdf.sh' >> ~/.zshrc
```
zshは再読み込みしておきます。

```
$ asdf version
```

### sheldon
zshのプラグインマネージャにsheldonを利用しているので、その設定を記載します。
sheldonのインストールや設定はまた別の機会にします。

```
vim ~/.sheldon/plugins.toml

[plugins.asdf]
github = "asdf-vm/asdf"

$ asdf version
```

### zinit
私はsheldonに移行したため、zinitは過去の設定なのですがこちらも記載します。

```
$ vim ~/.zshrc

zinit light asdf-vm/asdf

$ asdf version
```


## 試す

以下のコマンドでインストールできるプラグインの一覧が出力されます。

```
$ asdf plugin list all
```

rubyプラグインを追加

```
$ asdf plugin add ruby
```

rubyをインストール

```
$ asdf list all ruby
...
3.1.2
3.2.0-dev
...

$ asdf install ruby 3.1.2
```

システム全体で利用、またはプロジェクト毎に設定します。

```
$ asdf global ruby 3.1.2

or

$ cd prj1
$ asdf local ruby 3.2.0-dev
```

## 最後に
同様にredisやpostgresもインストールしてバージョン管理できますが、最初に言ったとおり正直それはDockerでいいかな、という気がしています。

とはいえasdfはかなり多くの言語を一括で管理できるので、これまでバラけていたバージョン管理が多少楽にはなるのではないかなと思います。
Binary Search - Itreative & recursive
Published: 2022-12-02 04:11:51



[Binary Search](https://leetcode.com/problems/binary-search/)

```js
// solution 1 : via iteration
/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var search = function (nums, target) {
  let high = nums.length - 1;
  let low = 0;

  while (low <= high) {
    let mid = parseInt((low + high) / 2);

    if (nums[mid] === target) {
      return mid;
    } else if (nums[mid] > target) {
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }

  return -1;
};

// Solution 2 : via recursion
const searchRecursive = function (nums, target) {
  let n = nums.length;
  const binarySearch = function (nums, low, high, target) {
    if (high >= low) {
      let mid = parseInt((low + high) / 2);

      // If the element is present at the middle
      // itself
      if (nums[mid] == target) return mid;

      // If element is smaller than mid, then
      // it can only be present in left subarray
      if (nums[mid] > target) return binarySearch(nums, low, mid - 1, target);

      // Else the element can only be present
      // in right subarray
      return binarySearch(nums, mid + 1, high, target);
    }

    // We reach here when element is not
    // present in array
    return -1;
  };

  return binarySearch(nums, 0, n - 1, target);
};

searchRecursive([-1, 0, 3, 5, 9, 12], 9);

```
Python Variables Scope Global Keyword |Local Variables
Tags: python, programming
Published: 2022-12-02 04:06:22

What is Variable in Python and How to Create Variables in Python
Python in Variable: It is a name of storage space which is used to store data. Its value may be changed. It always contains the last value stored to it. There is no need to declare a variable in python. A variable is created by assigning a value to it.


Variable is a name which is used to refer to a memory location. Variable also known as identifier and used to hold value.

In Python, we don't need to specify the type of variable because Python is a type infer language and smart enough to get variable type. 

Variable names can be a group of both letters and digits, but they have to begin with a letter or an underscore. It is recommended to use lowercase letters for variable name.  and x both are two different variables. 
[Read More](https://www.learncodingnivi.com/2022/11/python-variables-scope.html)
PHP Variables Learn| Types Variables| Declare Variables
Tags: php, variables, programming
Published: 2022-12-02 04:04:33

How to Create Php Variables| Php For Beginners with Examples
Php Variables: Variables is a name of storage space which is used to store data. Its value may be changed. It always contains the last value stored to it. Variables is a container which holds the value. Variable in PHP starts with dollar($) sign. In PHP, a variable is declared using a $ sign followed by the variable name. Here, some important points to know about variables. 

As PHP is a loosely typed language, so we do not need to declare the data types of the variables. 
It automatically analyzes the values and makes conversions to its correct datatype.
After declaring a variable, it can be reused throughout the code.
Assignment Operator (=) is used to assign the value to a variable. 
What is declared syntax?





$variablename=value;

What are variables in PHP, explain with example?




<?php

$x=100;

$x=50;

$x=250;

echo "The value of x is:".$x;

?>

**********OUTPUT**********

The value of x is:250

What is string in PHP with example?




<?php

$str="Learn Coding";

echo "I like $str";

?>

**********OUTPUT**********

I like Learn Coding

Can you concatenate strings in PHP?




<?php

$str="Learn Coding";

echo "I like ".$str;

?>

**********OUTPUT**********

I like Learn Coding


PHP Variables Learn| Types Variables| Declare Variables

Table of Contents
What are the rules to declare variable in PHP?
1. It must start with the dollar sign.

2. There is no need of data type (int, float, char) to define a variable.

3. Variables can, but do not need, to be declared before assignment.

4. After the dollar sign, the first letter of a variable should be alphabet or underscore(_).

5. After the dollar sign, the first letter of a variable should not be a digit.

6. After the first character, it may be a combination of alphabets and digits.

7. Blank spaces are not allowed in variable name.

8. A variable must start with a dollar ($) sign, followed by the variable name.

9. It can only contain alphanumeric character and underscore (A-z, 0-9, _).

10. A variable name must start with a letter or underscore (_) character.

11. A PHP variable name cannot contain spaces.

12. One thing to be kept in mind that the variable name cannot start with a number or special symbols.

13. PHP variables are case-sensitive, so $name and $NAME both are treated as different variable.
[Read More](https://www.learncodingnivi.com/2022/12/php-variables-learn.html)
Largest Positive Integer That Exists With Its Negative
Tags: javascript, leetcode
Published: 2022-12-02 03:44:39

[Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/)

```js
/**
 * @param {number[]} nums
 * @return {number}
 */
var findMaxK = function (nums) {
  let map = {};

  for (let i = 0; i < nums.length; i++) {
    if (nums[i] > 0) {
      let oppositeIndex = nums.includes(-nums[i]) ? nums.indexOf(-nums[i]) : -1;
      if (oppositeIndex > -1) {
        map[nums[i]] = nums[oppositeIndex];
      }
    }
  }

  return Object.keys(map).length > 0 ? Math.max(...Object.keys(map)) : -1;
};

findMaxK([-1, 2, -3, 3]);
findMaxK([-1, 10, 6, 7, -7, 1]);
findMaxK([-10, 8, 6, 7, -2, -3]);

```
How to auto-shutdown GCP VMs and save $
Published: 2022-12-02 03:41:32

The following script will shut down an instance that hasn't had any SSH connections in a while. The debounce defaults to 300 seconds.

1. Copy these files into your VM:

`/usr/bin/auto-shutdown.py`:

```python
#!/usr/bin/env python3

import json
import math
import os
import subprocess
from pathlib import Path
import time
from datetime import datetime

def main():
    timeout = int(os.environ.get("IDLE_TIMEOUT", "600"))
    interval = 60

    idle_since = getBootTime()

    while True:
        out = subprocess.check_output("last -F | jc --last", shell=True)
        for user in json.loads(out):
            if user.get("logout", None) == "still logged in":
                idle_since = max(idle_since, datetime.now().timestamp())
            elif "logout_epoch" in user:
                idle_since = max(idle_since, user["logout_epoch"])

        idle = round(datetime.now().timestamp() - idle_since)
        if idle > timeout:
            print(f"Idle for {idle}s, shutting down...")
            subprocess.check_call("shutdown now", shell=True)
        else:
            print(f"Idle for {idle}s, checking again in {interval}s...")
            time.sleep(interval)


def getBootTime():
    uptime = float(Path("/proc/uptime").read_text().split()[0])
    return datetime.now().timestamp() - uptime


if __name__ == "__main__":
    main()
```

`/etc/systemd/system/auto-shutdown.service`:

```
[Unit]
Description=Auto-shutdown VM

[Service]
ExecStart=/usr/bin/auto-shutdown.py
Restart=always
Environment=PYTHONUNBUFFERED=true

[Install]
WantedBy=multi-user.target
```

2. `pip3 install jc` and if `which jc` shows conda, then `sudo ln -sf /opt/conda/bin/jc /usr/bin/jc`
3. `sudo chmod u+x /usr/bin/auto-shutdown.py`
4. `sudo systemctl daemon-reload`
5. `sudo systemctl enable auto-shutdown.service`
6. `sudo systemctl restart auto-shutdown`
7. `systemctl status auto-shutdown.service`

[Inspiration](https://gist.github.com/ravwojdyla/05249805680f5cd8b54b6f01cd0c383b).
Faster builds with VMs than with Google Cloud Build
Published: 2022-12-02 03:36:26

Google Cloud Build has to pull your Docker image on every build, which can be slow if the image is 1GB+ (e.g. when using [cutting edge Wasm tooling](https://dev.to/chrismwendt/wasm-difficulties-in-rust-haskell-and-go-5f8m) that doesn't work on all OSes/architectures yet).

Here's how to speed up your builds using plain VMs instead:

`initiate-build.sh` creates/starts/resumes the build VM if it's nonexistent/stopped/suspended, copies a `Dockerfile` and context, then runs `build.py` on the VM and copies the artifact back to your local machine:

```bash
set -xeuo pipefail

cd "$(dirname "${BASH_SOURCE[0]}")"

: "${INSTANCE:=some-build-vm}"

status() {
  gcloud compute instances list --format="value(status)" --filter="name=$INSTANCE" | tr -d '\n'
}

state="$(status)"
case "$state" in
"")
  gcloud compute instances create "$INSTANCE" --machine-type=n2-standard-2 --create-disk=boot=yes,image=projects/ubuntu-os-cloud/global/images/ubuntu-2210-kinetic-amd64-v20221101,size=100
  ;;
"SUSPENDED")
  gcloud compute instances resume "$INSTANCE"
  ;;
"STOPPED")
  gcloud compute instances start "$INSTANCE"
  ;;
"RUNNING") ;;
*)
  echo "Unrecognized instance state $state"
  exit 1
  ;;
esac

rm -rf scratch
mkdir scratch
cp setup.py auto-shutdown.py auto-shutdown.service Dockerfile otherfiles scratch
gcloud compute scp --recurse scratch "$INSTANCE":"~"
gcloud compute ssh "$INSTANCE" -- 'bash -c "( cd scratch && python3 setup.py ); rm -rf scratch"'
gcloud compute scp "$INSTANCE":"~/artifact" artifact
```

`build.py` installs Docker if needed, sets up an auto-shutdown after 5mins of inactivity (to mimic the serverless nature of Google Cloud Build), builds the Docker image, then copies the artifact out:

```python
#!/usr/bin/env python3

import subprocess
from subprocess import check_call


def main():
    ensure("jc", "jc")
    ensure("docker", "docker.io")

    check_call("sudo chmod 755 auto-shutdown.py", shell=True)
    check_call("sudo mv auto-shutdown.py /usr/bin", shell=True)
    check_call("sudo mv auto-shutdown.service /etc/systemd/system", shell=True)
    check_call("sudo systemctl daemon-reload", shell=True)
    check_call("sudo systemctl restart auto-shutdown", shell=True)

    check_call("sudo docker build -t img .", shell=True)

    check_call(
        f"sudo docker run --rm --entrypoint cat img /artifact > ~/artifact", shell=True
    )


def ensure(command, pkg):
    try:
        check_call(["which", command])
    except subprocess.CalledProcessError:
        check_call("sudo apt-get update", shell=True)
        check_call(["sudo", "apt-get", "install", "-y", pkg])


if __name__ == "__main__":
    main()
```

See [auto-shutdown](https://dev.to/chrismwendt/how-to-auto-shutdown-gcp-vms-and-save--pe1).
Tutorial: Enable Azure AD SSO and MFA for Oracle E-Business Suite (EBS) via Datawiza
Tags: ebs, oracl, azure, mfa
Published: 2022-12-02 03:25:51


https://www.youtube.com/watch?v=S7Nwdp_-bx8

Step by step guide to setup Datawiza to enable SSO and MFA (2FA) for Oracle E-Business Suite (EBS). Learn more: https://www.datawiza.com/enable-sso-mfa-for-oracle-e-business-suite-in-minutes/

Datawiza integrates with any identity provider and MFA (2FA) service, like Microsoft 365 (Office 365; O365; Azure AD), Cisco Duo, Okta, AWS, Google, Auth0, Ping, ForgeRock, OneLogin, ADFS. 

Datawiza secure access to any web apps including:
- Business apps, like Oracle PeopleSoft, E-Business Suite, Siebel, SAP and more.
- Homegrown apps written in any language, like JAVA, PHP, .Net, Python, Go and more. 
- Critical tools like Wordpress, Kibana, Kubernetes, Jenkins, Grafana, SuperSet, AirFlow and more.
How to use Cider with Shadow-cljs
Tags: cider, cljs, shadowcljs
Published: 2022-12-02 02:56:15

---
title: How to use Cider with Shadow-cljs
published: true
description: 
tags: cider,cljs,shadowcljs
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2022-12-02 02:54 +0000
---


1. Run shadow-cljs
   npx shadow-cljs -d nrepl/nrepl:1.0.0 -d cider/cider-nrepl:0.28.7 cljs-repl app
2. Open http://localhost:9630 in Firefox
3. Wait until Shadow-cljs finish building
4. Open http://localhost:8280 (the app) in Firefox
5. In Emacs, run cider-connect-cljs with host = localhost, port = 8777, type = shadow, build = app

Suggestions are welcomed.
Where to Promote an Application Made for Developers
Tags: developers, marketing
Published: 2022-12-02 02:52:40

Developers are a special audience and promoting your product to them requires a different approach than other types of promotion. It can be hard to promote to developers because they are a tech savvy audience that doesn’t always respond to traditional forms of advertising.


We prefer to find out about products through word of mouth, recommendations, and online communities. Developers are also typically more skeptical of marketing claims and may be more likely to give feedback on products they use.

Advertising is not always the most efficient way to reach developers. It can be costly and time consuming to create ads that will resonate with this audience. Additionally, developers may not trust ads and may be more likely to respond to recommendations from their peers.

So, where should you promote your application?

Place where you can promote your stuff made for developers
Social media — Twitter, Reddit, and other social media platforms can be great places to start promoting your application. These platforms allow you to reach a wide audience and engage with potential customers in real-time.
Community — For example Product Hunt, betalist, indiehackers and so on.

Both are generic place where you can share what you make. But here’s two places I made intentionally for developers audience.

FindDev.tools https://finddev.tools/
This is a site where people can [share any tools related to developer](https://finddev.tools/). Such as serverless service, database platform, UI Component, learning resource and everything else that useful for developer. Whether is it paid or a free product. You can submit the tool you made for developer and promote it here. Everythis will be categorized nicely , to make people easier for looking alternatives to certain tool

2. Freestuff.dev https://freestuff.dev/

I also made a [list of free service or tools for developers to use](https://freestuff.dev/) . It’s open source so people can easily peek into how it’s made on Github. That way we’re also accepting submissions through Pull Request.

What’s the difference between finddev.tools and freestuff.dev ?

Both are useful to introduce what you make for developer, but freestuff.dev is intended for only free / open source alternative, while finddev.tools aim to be the “producthunt” for developer.
Code Smell 183 - Obsolete Comments
Tags: webdev, javascript, beginners, programming
Published: 2022-12-02 02:32:12

*Comments are a code smell. Obsolete comments are a real danger and nobody maintains what can't be executed.*

> TL;DR: Don't trust comments. They are dead.

# Problems

- Bad documentation

- Maintainability

# Solutions

1. Replace comments with tests

# Refactorings

{% post https://dev.to/mcsee/refactoring-005-replace-comment-with-function-name-4lpf %}

# Context

We know comments add almost no value to our code.

We need to restrict comments only to very important decisions.

Since most people change logic and forget to update comments they might become obsolete easily.

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/fd5b6b44920df66b6558be35f729f0f7)
```cpp
void Widget::displayPlugin(Unit* unit)
{

 	// TODO the Plugin will be modified soon, so I don't implement this right now

 	if (!isVisible) {
		// hide all widgets
		return;
 	}

}
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/36f9dde4301f0ab77c034aeba7c0b391)
```cpp
void Widget::displayPlugin(Unit* unit)
{ 
	if (!isVisible) {
		return;
 	}
}
```

# Detection

[X] Semi-Automatic 

We can warn for comments in our code and try to remove them.

# Exceptions

- Very important design decisions

# Tags

- Comments

# Conclusion

We need to think before adding a comment. Once It is in the codebase is beyond our control and can start to lie anytime.

# Relations

{% post https://dev.to/mcsee/code-smell-05-comment-abusers-2ba5 %}

{% post https://dev.to/mcsee/code-smell-152-logical-comment-2bg0 %} 

{% post https://dev.to/mcsee/code-smell-151-commented-code-5d8l %}

# Disclaimer

Code Smells are just my [opinion](https://dev.to/mcsee/i-wrote-more-than-90-articles-on-2021-here-is-what-i-learned-1n3a).

# Credits

Photo by [Volodymyr Hryshchenko](https://unsplash.com/@lunarts) on [Unsplash](https://unsplash.com/s/photos/obsolete)
    
* * *

> Obsolete comments tend to migrate away from the code they once described. They become floating islands of irrelevance and misdirection in the code.
 
_Bob Martin_

{% post https://dev.to/mcsee/software-engineering-great-quotes-26ci %}

* * *

This article is part of the CodeSmell Series.

{% post https://dev.to/mcsee/how-to-find-the-stinky-parts-of-your-code-1dbc %}