Skip to content

Instantly share code, notes, and snippets.

@kevinhooke
kevinhooke / gist:0cbcd835699b1308ff40fe66e108a114
Created July 10, 2025 08:22
bash command line navigation shortcuts
Ctrl-a : jump to start of line
Ctrl-e : jump to end of line
@kevinhooke
kevinhooke / gist:d65deb6c6f212b70826d34b8d83552ef
Created June 24, 2025 12:45
git: Show diff for staged changes
If you've already staged changes ready to commit but want to view the diff, use:
git diff --cached
@kevinhooke
kevinhooke / gist:e20d29015932e7d481055c49bb09ac36
Last active June 24, 2025 12:37
Reviewing git stash changes without applying, and selective checkout from stash
To review changes stashed (git stash push) without retrieving from stash:
What files have changed:
- git stash show
View diffs on stashed changes (patch):
- git stash show -p
To checkout a single file from the latest {0} stash (change number to reference other stashes if not latest)
\dt # describe all tables
\d tablename # describe table tablename
@kevinhooke
kevinhooke / gist:9726a97ff69d7eca8ddb428896fb559d
Created May 30, 2025 10:27
Terraform local provider local_file using a template
terraform {
required_providers {
local = {
source = "hashicorp/local"
}
}
# Provider functions require Terraform 1.8 and later.
required_version = ">= 1.8.0"
}
//Last H2 version compatible with Java 8
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.0.206</version>
<scope>test</scope>
</dependency>
//Setup server to interact with in-mem db
@BeforeClass
@kevinhooke
kevinhooke / gist:4b1fd20783e9b9cb3967e960145278ed
Created May 6, 2025 10:57
find files owned / not owned by a user
#find files from here owned by root:root
find . -user root -group root
#find files from here not owned by tomcat
find . -not -user tomcat
@kevinhooke
kevinhooke / gist:da53ba36f9e3755a664097236c96b74b
Last active April 24, 2025 10:42
Mocking static methods with Mockito
# No longer need to use Powermock to mock statics, this is now supported in Mockito with .mockStatic()
# Alternative approach to https://gist.github.com/kevinhooke/b4035faa5f2c215e8166936a44db4fa3
# Requires mockito-inline dependency instead of mockito-core
try (MockedStatic<ClassToMock> mock = Mockito.mockStatic(ClassToMock.class)) {
mock.when(ClassToMock::staticMethod).thenReturn(mockedReturn);
}
@kevinhooke
kevinhooke / gist:3244c4827ec66c27ffc699312eb3f509
Created April 4, 2025 09:31
Maven multi-module projects and version properties - flatten-maven-plugin
If building multi-module projects and publishing/installing to a repo, version properties like ${revision} are not
consistently replaced at install time. This results in errors when attempting to refer to one of these modules
as a dependency from another project, and instead of library:1.0.0 resolving, you'll see an error where
it's attempting to reference library:${revision} instead.
See discussion here:
https://stackoverflow.com/questions/41086512/maven-issue-to-build-one-module-using-revision-property
To fix, to need to add the flatten-maven-plugin:
https://maven.apache.org/guides/mini/guide-maven-ci-friendly.html#install-deploy
#To squash previous commits to a single commit
git rebase -i HEAD~[number of previous commits to squash]
#From the interactive list, each of the commits will be listed as 'pick'. Choose one of the commits into which
#the others should be merged, leave that as 'pick', and change all the others to 's' or 'squash'