Skip to content

Instantly share code, notes, and snippets.

View pford68's full-sized avatar

Philip Ford pford68

  • ex-IBM Watson
  • New York City and DC
View GitHub Profile
@pford68
pford68 / snippet.md
Last active May 15, 2025 04:32
How to delete containers #docker

To delete a Docker container, you first need to stop it, then remove it using the docker rm command. You can use the container ID or name to identify the container you want to remove. For example, if you want to remove the container with the ID "abcdef123", you can use the command docker rm abcdef123.

  1. Stop the container If the container is running, you need to stop it first using the docker stop command.
  • For example: docker stop abcdef123.
  1. Remove the container Once the container is stopped, you can remove it using the docker rm command.
@pford68
pford68 / snippet.md
Created September 5, 2024 01:48
Logging JPA queries in Spring Boot #springboot

In order to inspect queries in the console, add the following property in the application.properties file:

spring.jpa.show-sql=true
@pford68
pford68 / snippet.md
Last active August 18, 2024 16:52
How to use FormData to loop through form values #javascript

Below I am using FormData within a React component to print all element names:

    useEffect(() => {
        const el = formRef.current;
        if (el == null) return;
        // @ts-expect-error: keys() is not recognized.
        const iter =  new FormData(el).keys();
        let result = iter.next();
 while (!result.done) {
@pford68
pford68 / snippet.md
Created August 3, 2023 03:01
Add changes to your last commit #git

We have all been in a situation where we have forgotten one little change, for which we have to make a new commit. When this change is not so huge, we can add it into our last commit using the -—amend flag.

git add .
git commit --amend --no-edit

Using the —-no-edit flag allows us to apply changes to our last commit without modifying the commit message.

@pford68
pford68 / snippet.md
Created August 3, 2023 02:59
Remove file from a commit #git

If we would like to remove a certain file that has been committed to a branch, we can use git reset command.

git reset --soft HEAD^

This will bring the committed files to the staging area and then we can specify exactly which file to remove.

git reset HEAD 
@pford68
pford68 / snippet.md
Created August 3, 2023 02:57
Get difference between branches #git

If we want to see what are the differences between two branches, we can use git diff command.

git diff master

If we don’t want to see the exact differences, but only the file names, we can add the --name-only flag.

@pford68
pford68 / snippet.md
Created August 3, 2023 02:56
Copy changes from another branch #git

There are some scenarios where we have to add changes to more than one branches, for example if there are two versions and we support both of them, we should commit changes to both branches.

Let’s have two branches, branchA and branchB. Instead of committing in both branches manually, we can use git rebase command.

git checkout branchA
git rebase branchB

Then branchA will look like it was branched from branchB.

@pford68
pford68 / snippet.md
Created August 3, 2023 02:53
Add and commit in one command #git

One of the most used command in git is git add, followed by git commit.

git add .
git commit -m "commit message"

Most of the time will want to add all changed files. Instead of writing both commands, we can combine them in one using the -am flag..

@pford68
pford68 / snippet.md
Created August 3, 2023 02:45
Remove untracked files or directories #git

Use:

git clean -f or git clean -fd
@pford68
pford68 / snippet.md
Last active August 3, 2023 02:46
Revert all local changes #git

There are different ways to remove local changes depending the scenario you have.

If you want to revert the changes to your working copy use:

git restore .

If you want to remove all unpushed commits to master use: