In this article, we will create a minimal Spring Boot application that uses GitHub for authentication.

Image for post
Image for post
Photo by Park Troopers on Unsplash

OAuth is an open-source standard for access delegation. It grants applications access to users' protected resources via an authorization server.

For example, let’s suppose you’re developing a code scanning application, and you want to get access to users’ code on GitHub. Asking users for their credentials is not a realistic solution — no one will ever share sensitive data with you. This where OAuth comes in. Using the OAuth authorization mechanism, services can authorize against each other on the user’s behalf:

  1. Your application asks GitHub for the user’s…


Problem: Given a positive integer, write a code to find if it is a power of two or not.

“A number is a power of two” means that it can be written as 2^x where x is an integer. For example:

  • 8 is a power of two = 2³
  • 12 is not a power of two since there exists no x such that 2^x = 8
  • 32 is a power of two = 2⁵
Image for post
Image for post
Image by Matt Artz on Unsplash

The immediate solution: Take the log of the given number on base 2 and if you get an integer then the number is the power of two. …


The simplest container setup imaginable. Start here

Building’s foundation
Building’s foundation
Photo by Mirko Blicke on Unsplash.

Let’s begin by creating a minimal Flask application:

Simple Flask application

Next, let’s write the command that will run the Gunicorn server:

The parameters are pretty much self-explanatory: We are telling Gunicorn that we want to spawn two worker processes running two threads each. We are also accepting connections from the outside and overriding Gunicorn’s default port (8000).

Our basic Dockerfile:

Dockerfile

Let’s build our image:

docker build -t flask/hello-world .

And run:

docker run -p 8003:8003 flask/hello-world

The application is now accessible since we published the port:

$ curl localhost:8003
Hello world!

Running With Local K8s via Minikube

Assuming you already have Minikube running on your machine, follow the steps below. …


Figure out which commit introduced that new bug

Binoculars facing a lake
Binoculars facing a lake
Image By Shane Hauser on Unsplash.

“git-bisect — Use binary search to find the commit that introduced a bug” — Git’s official docs

It’s best to go through a real example in order to understand this command and demonstrate how it works.

Let’s create an empty Git project and add the following commits:

git commit --allow-empty -m 'good commit 1'
git commit --allow-empty -m 'good commit 2'
git commit --allow-empty -m 'good commit 3'
git commit --allow-empty -m 'good commit 4'
git commit --allow-empty -m 'good commit 5'
git commit --allow-empty -m 'good commit 6'
git commit --allow-empty -m 'BAD COMMIT'
git commit --allow-empty -m 'good commit 7'
git commit --allow-empty -m 'good commit 8'
git commit --allow-empty -m 'good commit 9'
git commit --allow-empty -m 'good commit…


A brief overview of the Unicode system, UTF, ASCII, and encoding

stuffed toys in the shape of emojis
stuffed toys in the shape of emojis
Photo By Kelvin Yan on Unsplash

Computers have their own language. They don’t understand human languages (maybe they do if you speak binary), and they don’t know anything but binary. How do we communicate with them?

As I’m typing now, the computer is not aware of any of the characters you’re seeing. Let’s consider the M character. At the lowest level, M is stored using a sequence of 0s and 1s: 01001101. Before we proceed, let’s recall two fundamental definitions:

Bit — smallest unit of storage, can only store 0 or 1
Byte — one byte = eight bits. That’s it.

Unicode

The Unicode Standard:

“The Unicode Standard is a character coding system designed to support the worldwide interchange, processing, and display of the written texts of the diverse languages and technical disciplines of the modern world. In addition, it supports classical and historical texts of many written languages.”


It is literally true that you can succeed best and quickest by helping others to succeed — Napoleon Hill

Image for post
Image for post
Photo By Glen Noble on Unsplash

If you’ve ever been interested in programming or anything related to and been around the net long enough, you’ve come across Stack Overflow, accidentally or on purpose.

What is Stack Overflow?

Stack Overflow is a question and answer site for professional and enthusiast programmers. It’s built and run by you as part of the Stack Exchange network of Q&A sites. With your help, we’re working together to build a library of detailed answers to every question about programming.

It was in 2013 when I asked my first question in Stack Overflow, got heavily down-voted and my question was closed. Back then, I didn’t know why was that 🤷‍♂️. All that I asked for was a solution for my homework, and by saying “solution” I mean a full solution. I didn’t expect comments…


Reduce the time you spend typing full-length commands and prevent annoying typos when using the kubectl command

Info on kubectl with the Kubernetes logo.
Info on kubectl with the Kubernetes logo.
Photo by the author.

If you’re using the command line to interact with your Kubernetes cluster, you’re probably familiar with the kubectl command.

There are many cheatsheets available for kubectl that attempt to cover all of its available commands. While it’s very powerful, this command can be a bit cumbersome for some of the operations that you use on a daily basis. For example, the following command list contains only a small portion of the available commands of kubectl:


Let’s build the simplest Java Spring Boot application that runs as a pod in a Kubernetes cluster

Image of Kubernetes logo.
Image of Kubernetes logo.
Image credit: Sandro Giacomozzi

The Project’s Structure:

├── Dockerfile
├── build.gradle
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── k8s
│ └── depl.yaml
├── settings.gradle
└── src
└── main
└── java
└── hello
├── App.java
└── HelloWorldCtrl.java

Our App.java is the entry point of the application:

The code above contains the minimal lines needed to create a Spring Boot application.

The HelloWorldCtrl.java contains a simple controller that maps the root path (“/”) and returns a greeting String:

Building the Application

I’m using Gradle as my build tool. The build.gradle file is also minimal and consists of the following lines:

plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}

group = 'com.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web' …


A common point of confusion

Image for post
Image for post
Photo by Frank Mckenna on Unsplash

If you look at the Dockerfile reference, some instructions might seem overlapping at first glance, or sometimes even redundant. For example, both ADD and COPY copy new files or directories to the filesystem of the container.

In this article, I’ll explain the difference between the even more confusing instructions CMD and ENTRYPOINT.

Let’s suppose we want to create an Ubuntu image whose only purpose is to run a sleep command when it starts. We’ll create our own image and specify a new command:

FROM ubuntu
CMD sleep 10

Now, we build and run the image:

docker build -t custom_sleep .
docker run custom_sleep
# sleep for 10 seconds and…


A look at Git internals and understanding what happens when you add, commit, push, and more

Futuristic wooden tunnel
Futuristic wooden tunnel
Photo By Note Thanun On Unsplash.

In this article, we’ll dive into Git internals by going through a real example. If you don’t have your terminal open already, do so, fasten your seatbelts, and let’s go!

Initializing a Git Repository

You have probably already initialized an empty Git project using git init, but have you ever wondered what this command does?

Let’s create an empty folder and initialize an empty Git project. This is how the official Git documentation describes git init:

“This command creates an empty Git repository — basically a .git directory with subdirectories for objects, refs/heads, refs/tags, and template files. …

About

Maroun Maroun

Software engineer | Music geek | Beer lover

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