Latest published articles

Becoming a Professional Software Developer

Becoming a Professional Software Developer

“Everybody wants to be a bodybuilder, but nobody wants to lift heavy ass weight”

Ronnie Coleman, 8x Mr. Olympia winner

Being a programmer is a lot like being a bodybuilder. Regular training, incremental progress, over and over again.

Over time this transforms the person from a beginner to a profesional.

Adopt this mindset in being a programmer. Plan to consistently train and improve your software engineering skills.

Axios Promise - Request and Response from the Client

Axios Promise - Request and Response From the Client

Simple example on how to send a post request from the client and handle the response.

Example

axios.post('/login', { firstName: 'Jack', lastName: 'Johnston' })
.then((response) => {
    // Success
  console.log(response);

}, (error) => {
    // Failure
  console.log(error);
});

Further Documentation

// Send a POST request
axios({
  method: 'post',
  url: '/user/new',
  data: {
    firstName: 'Joe',
    lastName: 'Smith'
  }
});

Install instructions

# NPM
npm install axios
-- or --
# Include Script Tag in JS file
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

Git: Add Date to Git Commit

Git: Add Date to Git Commit

To add a date to a git commit message from the command line:

git commit -m "blog update on `date +'%Y-%m-%d'`"

will result in

* e81bc5d - (25 minutes ago) blog update on 2023-04-20 - Mark S

Spring: Enable Components and Job Schedulers with Spring Profiles

Spring: Enable Components and Job Schedulers With Spring Profiles

In Spring you can enable a component using a profile:

@Profile("prod")
@Component
public class ProductionService() {
    // This will only be created with Spring_Profile: prod enable
}

Another use case is enabling/disabling schedulers:

@Profile("nightly-job")
@Component
public class NighlyJobScheduler() {
    // This will only be created with Spring_Profile: nightly-job
}

It can get cumbersome adding all the various profiles when you run the application. Spring now offer profile groups:

spring:
  profiles:
      active: development
      group:
        prod: prodJob1, prodJob2
        development: dev-scheduler-1, dev-notification

In the example above, running the profile “development” will automatically bring in the other profiles “dev-scheduler-1, dev-notification”

YAGNI

YAGNI

YAGNI is an acronym for “You Aren’t Gonna Need It”.

It’s an important principle in software development. Often it’s tempting to add code that could have useful utility down the road. In the end, it never ends up being used and creates overhead and code bloat.

So to follow YAGNI, don’t implement code until it actually needs to be utilized.

It’s a principle that comes from XP - Extreme Programming.

Kubernetes: Restarting Pods

Kubernetes: Restarting Pods

When making changes to config maps or other things - it’s tempting to restart all the pods for a particular service (select them all, delete, and let them come back up). This may work in the majority of cases, but if something goes wrong, it’ll be hard to tell if the recent change caused it or if it’s unrelated.

Recommendation:

  • First check the logs in the pods to restart for any abnormal behavior
  • Second restart a single pod before making any changes, make sure it comes up properly
  • If the pod cannot restart without making any changes, debug the issue
  • If the pod can restart, make the config change.
  • Now restart (or kill) pods one at a time, ensuring each one enforces the new change.

The point here isn’t the specific process, but rather having checkpoints when changes are made. Ideally, by making only one change at a time and testing, it’s evident when something is broken which change caused it.

Access Command Line in Kubernetes Rancher

Access Command Line in Kubernetes Rancher

To access a shell in a particular pod:

  • Workload-> Pods -> Find pod -> Click Three dots -> Execute Shell

To access a terminal to run kubectl commands in the environment:

  • Click the >_ symbol to open a terminal.

Example command: kubectl describe thingToDescribe -n NameSpace

Spring Batch: Running A Batch Job Explained

Spring Batch: Running a Batch Job Explained

To run a batch job, a JobLauncher needs a batch JobConfiguration and JobParameters. This creates a JobInstance.

A JobInstance creates a JobExecution. If the job fails and is restarted it retains the same JobInstance but creates a new JobExecution.

A JobExecution runs one or more steps in the Batch_Step_Execution table.

So each new run of a batch job creates a new batch job instance, and each restart creates a new job execution.

Spring Batch: Creating A Custom Job Builder

Spring Batch: Creating a Custom Job Builder

Batch jobs are created in Spring Batch using the JobBuilderFactory. A custom job builder factory can be created and re-used to allow common job configurations to be shared across all batch jobs in a project.

Example

@Configuration
public class CustomJobBuilderFactory extends JobBuilderFactory {

    @Override
    public JobBuilder get(final String name) {
        final JobBuilder jobBuilder = super.get(name);
	// register common to all jobs things here
        jobBuilder.listener(commonListener);
	return jobBuilder;
    }
}

Implementation


    @Bean
    public Job exampleJob(final CustomJobBuilderFactory jbf) {
	// This job now has the common listener 
	return jbf.get("myJob").start(myStep).build();
    }
}