Skip to content

Instantly share code, notes, and snippets.

@jonjack
jonjack / install-java-om-mac-with-brew-&-jenv.md
Last active May 23, 2021 08:38
Install Java on Mac OSX via Home-brew

Notes on installing multiple versions Java on Mac OSX using Homebrew and Jenv.

Install Homebrew

Homebrew is a superb tool for Mac for managing the installation of software. It's core command is brew and it calls packages of software formula. If you are intrigued then you can check out the list of Formula in the brew Github repository.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
@jonjack
jonjack / java-chaining-optional-checks.md
Last active March 23, 2021 01:26
Example of how to check multiple Optional values in a chain and return a default value if none contain a value.

The following scenario has multiple Optionals, a real example could be where you are calling multiple validation checks where each check returns an Optional<T>. You then want to check if each Optional contains a value or is empty - returning the first one that has a value. If none contain a value (ie. are instances of Optional.empty) then you return a default value.

In this example we are using Optional<Single> where Single is an RxJava Observer that returns a single value.

import com.google.common.collect.ImmutableList;

Assumes you have brew installed.

Install pyenv.

brew install pyenv

Check what versions of python are available.

Mac Setup

Fonts

Check out Adobe Fonts.

brew tap caskroom/fonts &amp;&amp; brew cask install font-source-code-pro
@jonjack
jonjack / osx-brew-install-not-symlinked-chown-user-local.md
Last active November 24, 2020 12:43
cannot complete brew install, not symlinked into /usr/local, requires me to chown /usr/local

While installing some formula I get:-

The formula built, but is not symlinked into /usr/local

Running brew as root is not allowed.

sudo brew install awscli

Check whats available

brew search maven
==> Formulae
maven                maven-completion     maven-shell          maven@3.0            maven@3.1            maven@3.2            maven@3.3
if (tweeted || facebooked) {
gratitude += 1;
}
if (githubStarred) {
karmaBalance = true;
} else {
$('we').say('ok');
}
import java.time.LocalTime;
import java.util.concurrent.TimeUnit;
public class Timer {
public static void main(String[] args) {
LocalTime start = LocalTime.now();
// some event to be timed
LocalTime end = LocalTime.now();
long delta = TimeUnit.NANOSECONDS.toMillis(end.toNanoOfDay() - start.toNanoOfDay());
System.out.println("Time took: " + Double.valueOf(delta)/1000 + " seconds");
import org.joda.time.LocalTime;
public class Timer {
public static void main(String[] args) {
LocalTime start = LocalTime.now();
// some event to be timed
LocalTime end = LocalTime.now();
int delta = end.getMillisOfDay() - start.getMillisOfDay();
System.out.println("Time took: " + Double.valueOf(delta)/1000 + " seconds");
}

We have a method to test which iterates over some List. The example is a validator service which iterates over a List of validators applying each one and returning when one fails ie. it returns an Optional containing an error message (this is just a concrete example to demonstrate Mockito and is not important to understand).

public class SomeValidationService implements ValidationService {

    /* List of validators which all encapsulate some different business validation logic */
    /* This gets injected say via Spring */
    private List<Validator> validators;
 
    public Optional<ErrorMessage> validateAction(final ObjectToValidate obj) {