When I want to practice for interviews, I like to do exercises on CodeWars and LeetCode. I recently found a kata on CodeWars that I really enjoyed. The problem was to create a factorial calculator that returns the number as a String. So I thought to myself, what’s so difficult about that? The factorial function can be done in just a couple of lines.

So I wrote out the standard recursive factorial function and converted it to a String.

The problem is that in Java, Integers can only have a value between -2147483648 and 2147483647. This is why the above…


Since Java is strongly typed, you will often need to convert one type to another. The Java Language Specifications states that there are 13 such conversions possible. Here I will focus on two of these, widening and narrowing type conversions.

While some type conversions need to be deliberately stated, sometimes you may not even notice that you have converted a type. Consider the following example:

Without any extra syntax, x (of type integer) is converted to a double when defining result. This is called Widening Type Casting.

Smaller data types can be converted to larger data types automatically. A…


After last weeks blog post, What is a Stack and how to Create one in Java, I figured it would be nice to give a practical example of using a stack in Java.

Reverse Polish Notation (also known as Postfix Notation) is a different way to write mathematical expressions. Normally, we use Infix notation to write algebraic expressions, where operators are between operands. While RPN expressions may be difficult to understand at first, they simplify algebraic expressions due to RPN doing away with parenthesis and the order of operations.

In RPN, the operators follow the operands. For example 3 +…


A stack, also known as LIFO (last in, first out), is a linear data structure with two main operations — push and pop. Items are added to the top of the stack, and items are removed from the top of the stack. The name ‘stack’ is very self explanatory, think of having some boxes and stacking them one on top of the other. You place boxes only on the top of the stack, and to remove them, you need to take boxes back off from the top.

A stack can be implemented as an array or linked list. I like…


Personally, I never liked switching back and forth between my browser and terminal when working with git repos on GitHub. For this reason, I was excited to hear about the new GitHub CLI.

Installing GitHub CLI 1.0 (beta)

MacOS

  • homebrew:
brew install gh
  • macPorts:
sudo port install gh

Windows

  • scoop:
scoop bucket add github-gh https://github.com/cli/scoop-gh.git
scoop install gh
  • chocolatey:
choco install gh
  • manual:
download the msi from https://github.com/cli/cli/releases/tag/v1.0.0

Linux

If you have Homebrew installed, you can simply use:

brew install gh
  • apt:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0
sudo apt-add-repository https://cli.github.com/packages
sudo apt update
sudo apt install gh
  • dnf:
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo


Usually forms are controlled in React. Using a controlled form gives you a high level of abstraction, easier testing, a single source of truth and more benefits over standard uncontrolled forms.

Using a standard React controlled form however, has two major downfalls — lots of code and a re-render on every key press. React Hook Form solves both of these problems. It is also arguably easier to learn than using controlled forms, if you are new to React.

React Hook Form Benefits

When creating a basic controlled form in React, you have to do the following:

  • use a class component (takes more code than…


When learning React, you will be introduced to the tool React.Component.setState() and instructed to never update the state property directly. In any programming language, if you are provided an accessor method (a getter or a setter), it’s safe to assume that you shouldn’t access the variable directly. This holds true for setState() as well.

Why You Should Never Update State Directly

There are a few reasons to never update state directly:

  • setState() is asynchronous. If you set state directly, it may be overwritten from a call to setState().


Binary Numbers from a Decimal Perspective

Decimal numbers have a base of 10, meaning that any decimal number can be represented as the sum of powers of 10.

And in summation form:


Linked lists are the foundation of other data structures and can be used to create stacks, queues, and more. They can be very efficient when used correctly and can also be inefficient when used incorrectly. Random access is very expensive for a Linked List.

A linked list is a collection of data where each data is contained in a node and this node points to the next node. In Ruby, we will have two classes. …

Steve Pesce

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store