Delete to beginning of current word in Bash
Instead of pressing backspace repeatedly, press ESC
then Backspace
.
Instead of pressing backspace repeatedly, press ESC
then Backspace
.
docker network ls
then
docker network rm networkname
Muscle Memory Makeover
Docker just streamlined Docker Compose by integrating it as a plugin. Great news, but it means us old hats need to retrain our fingers. Here's a quick fix for your .bashrc
to keep things smooth:
alias docker-compose='docker compose'
MySQL in a Flash
As a programmer and Linux admin, I juggle multiple MySQL servers with different group suffixes. Typing --defaults-group-suffix
every time was a drag. This handy bash function saves the day:
m() {
mysql --defaults-group-suffix=$1
}
Now, connecting to a database is as easy as:
m specific-suffix
This keeps your workflow concise and saves you precious keystrokes.
Put them into you .bashrc
or .zshrc
now and let our life easier!
In the context of using a mocking framework like Moq in C# for unit testing, the choice between mockObject.Reset()
and mockObject.Invocations.Clear()
depends on what you want to achieve.
mockObject.Reset()
:
Reset()
.Example:
var mock = new Mock<MyClass>();
mock.Setup(x => x.MyMethod()).Returns("Original");
// ... code using the mock ...
// Reset the mock, removing setups
mock.Reset();
// Now, if you call the method, it won't use the previous setup
var result = mock.Object.MyMethod();
mockObject.Invocations.Clear()
:
Example:
var mock = new Mock<MyClass>();
mock.Setup(x => x.MyMethod()).Returns("Original");
// ... code using the mock ...
// Clear recorded invocations
mock.Invocations.Clear();
// Now, if you verify invocations, it won't consider previous calls
mock.Verify(x => x.MyMethod(), Times.Never());
In summary:
mockObject.Reset()
when you want to clear setups and start fresh with the mock.mockObject.Invocations.Clear()
when you want to clear the history of invocations, but keep the existing setups and behaviors.In most mocking frameworks, including Moq for C#, the answer is YES. Each new setup for the same method and parameters overrides any previous setups.
Here's an example using Moq:
// Setting up the method with the same parameters but different returns
mock.Setup(x => x.MyMethod()).Returns("FirstSetup");
mock.Setup(x => x.MyMethod()).Returns("SecondSetup");
// Now, if you call the method, it will return "SecondSetup"
var result = mock.Object.MyMethod();