Skip to content

Instantly share code, notes, and snippets.

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) {
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");
}
if (tweeted || facebooked) {
gratitude += 1;
}
if (githubStarred) {
karmaBalance = true;
} else {
$('we').say('ok');
}
@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
@jonjack
jonjack / git-scraps.md
Last active April 25, 2024 19:12
Git scraps

Comparing commits

To compare last two commits.

git diff HEAD^ HEAD

Since comparison with HEAD is the default you can omit it for even shorter syntax.

Assumes you have brew installed.

Install pyenv.

brew install pyenv

Check what versions of python are available.

@jonjack
jonjack / mysqlworkbench-8.0.25.rb
Last active June 22, 2021 12:10
Homebrew mysqlworkbench 8.0.25 cask formula for Big Sur
cask "mysqlworkbench-8.0.25" do
version "8.0.25"
sha256 "8da15d32d0c3cc8d43e49f8d3580ddec0d8dcd718153da7c934acf26f83ea0c5"
url "https://cdn.mysql.com/Downloads/MySQLGUITools/mysql-workbench-community-#{version}-macos-x86_64.dmg"
livecheck do
url "https://dev.mysql.com/downloads/workbench/"
strategy :page_match
regex(/MySQL\s*Workbench\s*(\d+(?:\.\d+)*)/i)
end
@jonjack
jonjack / mysqlworkbench-8.0.22.rb
Last active June 22, 2021 12:12
Homebrew mysqlworkbench 8.0.22 cask formula for Big Sur
cask "mysqlworkbench-8.0.22" do
version "8.0.22"
sha256 "4e27de82d869043cf80e803f1a57cc041a91cabddf0aa6a6c054d68af1837d48"
url "https://downloads.mysql.com/archives/get/p/#{version.major}/file/mysql-workbench-community-#{version}-macos-x86_64.dmg"
name "MySQL Workbench"
desc "Visual tool to design, develop and administer MySQL servers"
homepage "https://www.mysql.com/products/workbench/"
app "MySQLWorkbench.app"
@jonjack
jonjack / vs-code-command-code-runner-run-not-found-fix.md
Last active September 26, 2021 21:17
Visual Studio code - command 'code-runner.run' not found fix for formulahendry.code-runner-0.9.10

Program: Visual Studio Code
Extension: Code Runner 0.9.10 (code-runner-0.9.10)
Problem: When attempting to run a script/program, VS Code reports error: "command 'code-runner.run'"
Fix: Manually edit extension code.

Edit extension file codeManager.js
On macOS this is usually at ~/.vscode/extensions/formulahendry.code-runner-0.9.10/out/src/codeManager.js

Comment out line 12.