Access Git Personal Token

This entry shows how and why you need to generate Git Personal Token

Git Personal Token is required to interact with Git Server. It is different from the Git Account Password. The token can be created for a set period of time, and can also be “revoked”. Think of it like an access card. It is tied to your account but can be created, used for access, and deactivated.

Below we go over the steps to create and use the Gi Personal Token

Read more

Python Week – Day 3 – Quiz App

Blog Status: Draft (In the progress of adding more explanation at each step) but is 90% complete

On Day 2, we created a Coin Flip App to demonstrate Import, If-Else, For Loop, Red From User Input, Random Number, and Logging.

Today, let’s create a Python Quiz App that should be useful for studying for quizzes. This project demonstrates a few more core python concepts (Dictionary, Function, Read from a File).

Below are the steps to create the Python Quiz App:

  • Step 1: Create a words dictionary, and randomly select an item to ask a question
  • Step 2: Populate the words dictionary from a CSV file
  • Step 3: Ask the user to choose which quiz to take, then randomly select a question from that quiz
  • Step 4: Ask the user to select a quiz category, then ask randomly selected questions from a randomly selected quiz
  • Step 5: Further clean up code by creating a quiz_common module

Read more

Python Week – Day 2 – Simple Coin Flip Game

Follow the instruction from Day 1 to create another python project. In this python project, create a file called flip.py

How does a Coin Clip game work?

Normally, it works by someone tossing a coin, which can be a tail or a head, and another person guess before toss. The guesser wins if the guess matches.

If this coin is a perfectly made coin, there should be a 50/50 chance that it would be head/tail.

A very simple coin flip game could work as follow:

  1. Ask for head or tail
  2. Flip a coin
  3. If the guess matches the result, then it’s a win

To build this game, I will work you through the steps, the simplest first, then onto

  1. Just print “flip a coin” and “It’s a head” to console
  2. Create a constant variable to hold the value of the coin flip, but pretend that the value is always “head”
  3. For better style and to reduce duplicate code, create a new file to store the constant variables. Use the constant variables in this new module.
  4. Create a placeholder variable called “random_val”, but set it to “0.50” (pretend it’s always 0.50) . Add code to check if random_val is larger than 0.50, if so, pring HEAD, else print TAIL
  5. Ask user for input for random_val (instead of pretend it is always 0.50)
  6. Instead of getting the random value from the user, get it by calling seed() and random() from the Python random module.
  7. Improve the “randomness” by using the current timestamp as “seed”. The coin flip should now be fair.
  8. Add the for loop, so that the coin is flipped 10 times in a roll
  9. Keep a tally of how many heads and tails are there after 10 coin flips
  10. Ask the user to enter the number of coin flips (instead of hard-coded it to 10)
  11. Beautify the output

Read more

Java Streams Code Snippets

What is a Java Stream?

Java Stream is a sequence of elements supporting the sequential and parallel aggregate operation. This example shows an aggregate operation using Stream and IntStream

int sum = widgets.stream()
                 .filter(w -> w.getColor() == RED)
                 .mapToInt(w -> w.getWeight())
                 .sum();

In this example (from Oracle Stream doc), widgets is a Collection<Widget>. A stream of Widget objects was created via Collection.stream(), filter it to product a stream containing only the red widgets, and then transform it into a stream of int values representing the weight of each red widget. Finally this stream is summed to produce a total weight.

 

This post lists Java Streams code snippets that I find very useful

Read more

Lombok Tips

What is Lombok?

In their own word,

Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java. Never write another getter or equals method again, with one annotation your class has a fully featured builder, Automate your logging variables, and much more

Why Use Lombok

  • Reduce boilerplate code
  • Increase readability
  • Reduce work for unit test code coverage

When to NOT use Lombok?

  • More complex entity classes (non-POJO classes)

Read more