Skip to content

Instantly share code, notes, and snippets.

View msrose's full-sized avatar

Michael Rose msrose

View GitHub Profile
@msrose
msrose / docker-cheatsheet.md
Last active June 27, 2023 10:33
Docker cheatsheet

Docker cheatsheet

This gist might help you answer the following questions:

  • How do I run a command inside a docker container?
  • Why isn't my docker container running?
  • Why is my docker container stopping right after I start it?

Most of the time when using docker, I want to get a shell inside a running container, either to see what's installed inside an image, or debug failing commands, or something else similar. I don't think this is the primary use case for the docker CLI, because it always takes a few different commands with flags that I always forget; before long, I find myself confused all over again as to how containers work and how to manipulate them with the CLI.

Here's the easiest CLI-only way I've found to pull an image, create a container from it, and run a terminal in that container. I've done my best to explain every command and flag so I'll never have to wonder again why my container seemed to stop immediately, or stop suddenly, or vanish off the face of the Earth.

@msrose
msrose / babel.config.js
Created June 6, 2020 02:17
Mock function as prop
module.exports = {
presets: ['@babel/preset-react', '@babel/preset-env']
}
@msrose
msrose / del.sh
Created October 11, 2019 21:04
Delete greenkeeper branches
for branch in $(git for-each-ref --format="%(refname)" | grep "greenkeeper/"); do
git push origin :${branch#refs/remotes/origin/}
done
@msrose
msrose / make_package.sh
Last active December 13, 2016 09:46
Creates an NPM package project
set -e
PACKAGE_NAME=$1
GIT_REMOTE=$2
DESCRIPTION=$3
TEST_DIR=__tests__
if [[ -z $PACKAGE_NAME ]]; then
echo "No package name provided"
@msrose
msrose / ruby-block-example.rb
Last active November 8, 2016 22:55
Using ruby blocks to write a map function
# built-in map
squares = [1,2,3].map do |n|
n * n
end
puts squares
# if you wanted to write your own
@msrose
msrose / combining-git-repositories.md
Last active May 4, 2024 15:58
How to combine two git repositories.

Combining two git repositories

Use case: You have repository A with remote location rA, and repository B (which may or may not have remote location rB). You want to do one of two things:

  • preserve all commits of both repositories, but replace everything from A with the contents of B, and use rA as your remote location
  • actually combine the two repositories, as if they are two branches that you want to merge, using rA as the remote location

NB: Check out git subtree/git submodule and this Stack Overflow question before going through the steps below. This gist is just a record of how I solved this problem on my own one day.

Before starting, make sure your local and remote repositories are up-to-date with all changes you need. The following steps use the general idea of changing the remote origin and renaming the local master branch of one of the repos in order to combine the two master branches.