Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Friday, 21 February 2020

CODING > Java 02 Password generator

Definition

As there is nothing more frustrating than create a new random password for everyone in a company, the automated process to do so could be required somewhere.

Summary

In the following script we create a java class "PassGen01" which has three main variables, containing two arrays of words and a random two digit number.

Later we have another two number generator (0 to 3 as the possible positions of the two arrays we have)

Finally, everything is concatenated into the variable "pass" and shown into console through a System.out

Code

public class PassGen01 {
public static void main(String[] args) {

String[] pass_list01 = {"Spring", "Summer", "Autumn", "Winter"};
String[] pass_list02 = {"Day", "Month", "Year", "Decade"};
int pass_num_random = ((int)(Math.random() * (99 - 10) + 10));

int pass_list_index_random01 = ((int)(Math.random() * (3 - 0)));
int pass_list_index_random02 = ((int)(Math.random() * (3 - 0)));

String pass = (pass_list01[pass_list_index_random01])
+ (pass_list02[pass_list_index_random02]) 
+ (pass_num_random) 
+ "!";
System.out.println(pass);
}

}

Results

AutumnMonth25!
SummerMonth95!
AutumnDay77!
AutumnYear65!
SpringYear94!

Tuesday, 18 February 2020

CODING > Java 01 Start


Starting on Java

Java is a general-purpose programming language that is class-based, object-oriented, and designed to have as few implementation dependencies as possible.
Java is for many, the starting point on coding as it represents the easy and flexible start as it is used as the base of so many server and desktop based applications

Downloading Java

There are many versions of different code languages and environments, depending if you are gonna use a interpreter for some application already written for any specific language or developing those apps themselves, you would need one or the other.
  • JRE: If you want to run Java programs, but not develop them, download the Java Runtime Environment
  • JDK: To start coding and executing java we would need  the Java Development Kit.
    Link here
At this point there should be some advice:

The Oracle JDK License has changed for releases starting April 16, 2019.

The new Oracle Technology Network License Agreement for Oracle Java SE is substantially different from prior Oracle JDK licenses. The new license permits certain uses, such as personal use and development use, at no cost -- but other uses authorized under prior Oracle JDK licenses may no longer be available

Apart from the Development kit, you would need as well some environment to start typing your code and run it, test it or break it. For that you need an IDE or Integrated Development Environment, we picked Eclipse

Start coding

After following the main tutorial, we arrive to our first java class / app which returns a classic "Hello World!"
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello world!");
}
}

Links

Tuesday, 4 February 2020

CODING > Python I start

Starting on Python

I started messing with Python after seeing a colleague automatize half of his work in networking with Python coding, still learning though but seems promising.

Download Python

Go to Python.org and from there, downloads, select your operative system (windows, mac or Other) and download the installer that most suits your needs. I am going for the windows x86-64 executable installer.

Once that file is downloaded, open it and the installer will ask usual options, I strongly recommend to add python to the windows PATH enviroment variables. (If you are asking what the duck is that, take a look here)

Start coding

Head yourself to open your Python console, in windows, start menu and search for Python. The following was my first approach following the Python documentation.


>>> the_world_is_flat = True
>>> if the_world_is_flat:
...     print("Be careful")
...
Be careful


As a quick explanation, we set a variable the_world_is_flat and tell the program later to type Be careful with a condition, if that variable exists. The result is the last, fifth line.

Links