I just want to create some demo for enum to create a builder . I improved this concept step by step in demos. Notice that all the codes are doing same job but in a different way.
Author: admin
TypeScript Syntax
Type Aliases, Union Types, Literal Types, Index Signature
You can find different usages of Type Aliases in the following demo code.
Type Aliases is defined with type
word.
Union Types is defined with the |
character to separate the different possible types.
Literal Types can be string, number or boolean
type SelectedEvent = "Click"; // string literal type
const buttonEvent: SelectedEvent = "Click";
type Color = "Red" | "Green" | "Blue"; // string literal type with union type
const buttonForeColor: Color = "Red";
type num = 1 | 3 | 5 | 7 | 9; // number literal type with union type
type bool = true | false; // boolean literal type with union type
type TRUE = true;
type FALSE = false;
Index Signature is defined as below
type Dictionary = {
[index: string]: any;
};
const person: Dictionary = {
"firstName": "Kenan",
"lastName": "Hancer",
"age": 36
};
interface StringArray {
[index: number]: string;
}
const names: StringArray = ["Bob", "Fred"];
let name1: string = names[0];
Type Aliases can be used with Union Types and Literal Types as below
type obj = {success: true} | {success: false}; // object
type Result<T> = { success: true, value: T } | { success: false, error: string | number }; // object
type PersonCommonFields = { firstName: string, lastName: string };
type Person = PersonCommonFields & { isDeleted: true | false };
type Name = string; // simple type
type NameResolver = () => string; // function
type NameOrResolver = Name | NameResolver;
Demo1
Continue readingJavaScript Object.assign(), Object.create()
Object.create()
The Object.create()
method creates a new object, using an existing object
Demo1
Continue readingJavaScript Object.entries(), Object.values(), Map, Set Usage
Demo1
Continue readingNode.js Axios Usage
How to install Java with Jabba
Runtime version managers make developers life easier. So, I tested different Java version managers. But, Jabba is the easiest one for me.
You can read previously posted How to install java articles.
Java Specification Versions:
Here are the major releases:
- Java 1.0 (January 1996) – The original version.
- Java 1.1 (February 1997) – Introduced several significant features, including the JavaBeans API.
- Java 2 (J2SE 1.2) (December 1998) – Introduced the
Swing
application framework.- J2SE 1.3 (May 2000) – Introduced the
HotSpot
JVM.- J2SE 1.4 (February 2002) – Introduced regular expressions, image I/O API, and more.
- Java SE 5 (J2SE 1.5) (September 2004) – Introduced generics, metadata annotations, enumerated types, and more.
- Java SE 6 (December 2006) – Introduced scripting support, JVM improvements, and more.
- Java SE 7 (July 2011) – Introduced the
try-with-resources
statement, the diamond operator, and more.- Java SE 8 (March 2014) – Introduced lambdas, streams, and the
java.time
package.- Java SE 9 (September 2017) – Introduced the module system.
- Java SE 10 (March 2018) – Introduced local-variable type inference (
var
).- Java SE 11 (September 2018) – Introduced
String::lines
,isBlank
, and other methods, plus thejava.net.http
HttpClient.- Java SE 12 (March 2019) – Introduced switch expressions (preview) and more.
- Java SE 13 (September 2019) – Introduced text blocks (preview) and more enhancements.
- Java SE 14 (March 2020) – Introduced pattern matching for
instanceof
(preview) and other improvements.- Java SE 15 (September 2020) – Continued the introduction and enhancement of several features.
- Java SE 16 (March 2021) – Introduced sealed classes (preview) and other enhancements.
- Java SE 17 (September 2021) – This version is an LTS (Long Term Support) release, which means it will receive updates for a longer period than the interim releases.
- Java SE 18 (March 2022)
- Java SE 19 (September 2022)
- Java SE 20 (March 2023)
- Java SE 21 (September 2023)
Java has moved to a time-driven release model, with new versions being released every six months. Not all of these are long-term support (LTS) versions. As of Java 17, the LTS versions have been Java 8, Java 11, and Java 17.
Installing Jabba
Click Jabba link to see more detailed information about Jabba
$ curl -sL https://github.com/shyiko/jabba/raw/master/install.sh | bash && . ~/.jabba/jabba.sh
Usage
# list available JDK's
$ jabba ls-remote
# you can use any valid semver range to narrow down the list
$ jabba ls-remote zulu@~1.8.60
$ jabba ls-remote "*@>=1.6.45 <1.9" --latest=minor
# install Oracle JDK
$ jabba install 1.8
# install Oracle Server JRE
$ jabba install sjre@1.8
# install Adopt OpenJDK (Hotspot)
$ jabba install adopt@1.8-0
# install Adopt OpenJDK (Eclipse OpenJ9)
$ jabba install adopt-openj9@1.9-0
# install Zulu OpenJDK
$ jabba install zulu@1.8
$ jabba install zulu@~1.8.144 # same as "zulu@>=1.8.144 <1.9"
# install IBM SDK, Java Technology Edition
$ jabba install ibm@1.8
# install GraalVM CE
$ jabba install graalvm@1.0-0
# install OpenJDK
$ jabba install openjdk@1.10-0
# install OpenJDK with Shenandoah GC
$ jabba install openjdk-shenandoah@1.10-0
# install from custom URL
# (supported qualifiers: zip (since 0.3.0), tgz, tgx (since 0.10.0), dmg, bin, exe)
$ jabba install 1.8.0-custom=tgz+http://example.com/distribution.tar.gz
$ jabba install 1.8.0-custom=tgx+http://example.com/distribution.tar.xz
$ jabba install 1.8.0-custom=zip+file:///opt/distribution.zip
# uninstall JDK
$ jabba uninstall zulu@1.6.77
# link system JDK
$ jabba link system@1.8.72 /Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk
# list all installed JDK's
$ jabba ls
# switch to a different version of JDK (it must be already `install`ed)
$ jabba use adopt@1.8
$ jabba use zulu@~1.6.97
$ echo "1.8" > .jabbarc
# switch to the JDK specified in .jabbarc (since 0.5.0)
$ jabba use
# set default java version on shell (since 0.2.0)
# this version will automatically be "jabba use"d every time you open up a new terminal
$ jabba alias default 1.8
Continue reading How to install Java with brew and jenv
jenv
is a tool that helps you switch between different java versions in your development machine. But, Jenv doesn't install Java for you.
Use your platform appropriate package manager to install Java
. On macOS, brew
is recommended.
Install Java with Homebrew
First, ensure that you have Homebrew installed in your system. Homebrew is a package manager for Mac OS. So if you want to learn more details about it, visit my blog below.
I also posted how to install Java JDK manually in the following post.
Actually I already mentioned how to install Java JDK in the above post, but I will shortly show one more time
$ brew tap adoptopenjdk/openjdk
$ brew search jdk
==> Formulae
openjdk openjdk@11
==> Casks
adoptopenjdk
adoptopenjdk12
adoptopenjdk13-openj9
adoptopenjdk14-openj9-jre-large
adoptopenjdk9
adoptopenjdk10
adoptopenjdk12-jre
adoptopenjdk13-openj9-jre
adoptopenjdk14-openj9-large
jdk-mission-control
adoptopenjdk11
adoptopenjdk12-openj9
adoptopenjdk13-openj9-jre-large
adoptopenjdk8
oracle-jdk
adoptopenjdk11-jre
adoptopenjdk12-openj9-jre
adoptopenjdk13-openj9-large
adoptopenjdk8-jre
oracle-jdk-javadoc
adoptopenjdk11-openj9
adoptopenjdk12-openj9-jre-large
adoptopenjdk14
adoptopenjdk8-openj9
sapmachine-jdk
adoptopenjdk11-openj9-jre
adoptopenjdk12-openj9-large
adoptopenjdk14-jre
adoptopenjdk8-openj9-jre
adoptopenjdk11-openj9-jre-large
adoptopenjdk13
adoptopenjdk14-openj9
adoptopenjdk8-openj9-jre-large
adoptopenjdk11-openj9-large
adoptopenjdk13-jre
adoptopenjdk14-openj9-jre
adoptopenjdk8-openj9-large
$ brew cask install adoptopenjdk
$ java --version
openjdk 14.0.1 2020-04-14
OpenJDK Runtime Environment AdoptOpenJDK (build 14.0.1+7)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 14.0.1+7, mixed mode, sharing)
Continue reading How to install Ansible with brew or pip
You can install Ansible quickly in your system with Homebrew( or PIP(Package manager for Python)
Install Ansible with Homebrew
If you are using macOS, then you can use Homebrew.
First, ensure that you have Homebrew installed in your system. Homebrew is a package manager for Mac OS. So if you want to learn more details about it, visit previous post below.
Run the following commands in your terminal without $ sign.
$ brew update
$ brew install ansible
Checking Ansible version
$ ansible --version
ansible 2.9.7
config file = None
configured module search path = ['/Users/kenanhancer/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/kenanhancer/.pyenv/versions/3.8.2/lib/python3.8/site-packages/ansible
executable location = /Users/kenanhancer/.pyenv/versions/3.8.2/bin/ansible
python version = 3.8.2 (default, May 6 2020, 12:47:50) [Clang 11.0.3 (clang-1103.0.32.59)]
Install Ansible with PIP
Ensure that you have Python and PIP in your system. Check the following page about Python installation.
$ pip install ansible
$ ansible --version
Updating Ansible
$ pip install --upgrade ansible
Installing specific Ansible version
$ pip install ansible==2.2.2.0
$ pip install ansible==2.0.1.0
How to install Python with pyenv version manager
I am using different programming languages like C#, Java, Node.js etc and need to manage runtime versions in my local. So, I like to use runtime version managers.
For example, there are some runtime version managers in Node.js community like nvm or n.
Let's say I work for one Node.js project in dev machine with Node v8.0.0 but other project needs Node v6.0.0
In order to handle, different versions in same machine, we may use runtime version managers.
I just want to find a way to switch between different Python runtime version so that found pyenv runtime version manager.
Pyenv is a simple, powerful and cross-platform tool for managing multiple versions of Python on a single machine. It is very useful when you need to switch between different Python versions for different projects, or when different applications on your system require different Python versions.
So, we can install, uninstall, list or switch between different versions.
Pyenv installation
Click pyenv link for more detailed installation.
Installing pyenv with Homebrew
First, ensure that you have Homebrew installed in your system. Homebrew is a package manager for Mac OS. So if you want to learn more details about it, visit my post.
Run the following commands in your terminal. But, just copy commands without $ sign.
$ brew update
$ brew install pyenv
Setting PATH
Checking shell
output of echo $SHELL
can be bash
, zsh
or fish
$ echo $SHELL
/usr/local/bin/bash
# OR
/bin/zsh
Run the following command for bash, zsh, etc configuration.
$ echo 'eval "$(pyenv init -)"' >> ~/.zshrc
and restart your terminal manually or run the following command to restart automatically.
$ exec "$SHELL"
Upgrading pyenv
$ brew upgrade pyenv
Uninstall pyenv
$ rm -rf $(pyenv root)
$ brew uninstall pyenv
Pyenv commands
List all Python versions installed in system
$ pyenv versions
system
3.7.3
* 3.8.2 (set by /Users/kenanhancer/.pyenv/version)
Show current active Python version in system
$ pyenv version
3.8.2 (set by /Users/kenanhancer/.pyenv/version)
Continue reading Reverse String Algorithm
I will test different solutions to reverse a string value in JavaScript.
Syntax of String substr()
string.substr(start, length)
Solution 1: String substr()
Iteration starts from 1 to lenght of string.
Solution 2: String substr()
Iteration starts from lenght of string to 0.
Continue reading