Kent Beck Tweets

Leave a comment

These are some of my favorite tweets by Kent Beck.

Screen Shot 2017-07-05 at 11.19.35 AM.png

 

Advertisements

How to create a pull request against branch on master

1 Comment

Say someone has created a branch for you off of master, and they want to create Pull Requests (PRs) against it. Here’s how you do it.

Get on your fork (make sure sync’d and clean) and then do

git fetch remote branch
git checkout branch

So for example

git fetch upstream imessage
git checkout imessage

Screen Shot 2017-03-20 at 2.56.48 PM.png

This grabs the upstream branch, pulls it local, and then when you checkout a branch of the same name, it automatically sets it to the upstream branch you just checked out.

Now you can create a new branch off this one, do your work, and merge it back by creating a PR via GHE.

git checkout -b foo`

You are now ready to work

Screen Shot 2017-03-20 at 2.58.33 PM.png

IMG_1637.JPG

How to write a git commit message

Leave a comment

Screen Shot 2017-03-17 at 8.22.42 AMScreen Shot 2017-03-17 at 8.23.13 AMScreen Shot 2017-03-17 at 8.23.29 AMhttps://chris.beams.io/posts/git-commit/

Clock Pattern

1 Comment

Here is an old pattern I used to use in C# whenever I wanted to freeze time in a test, and then verify that something happened after.

You define a Clock object where you can freeze and set the time. Then whenever you want a time in your system or in tests you simply ask it for it’s time.

DateTime now = Clock.CurrentTime();

Or in a test you can do something like this.

  [Fact]
        public void When_updating_a_user()
        {
            using(Clock.Freeze())
            {
                // Add user at this time
                DateTime currentTime = Clock.CurrentTime();
                fixture.Add(randomUserName);

                // Update user 5 minutes later
                Clock.Add(new TimeSpan(0, 5, 0));
                DateTime newCurrentTime = Clock.CurrentTime();
                repository.UpdateUser(new User(randomUserName, true));

                User user = repository.FindBy(randomUserName);
                Assert.Equal(principalUserName, user.CreatedBy);
                Assert.Equal(currentTime, user.CreatedDate);
                Assert.Equal(principalUserName, user.ModifiedBy);
                Assert.Equal(newCurrentTime, user.ModifiedDate);
            }
        }

Clock

using System;

namespace src.utils
{
    public class Clock
    {
        private static bool timeFrozen;
        private static DateTime currentTime;

        public static UnFreezeClock Freeze()
        {
            DateTime now = DateTime.Now;
            return Freeze(new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second));
        }

        public static UnFreezeClock Freeze(DateTime time)
        {
            timeFrozen = true;
            currentTime = time;

            return new UnFreezeClock();
        }

        public static DateTime CurrentTime()
        {
            if (timeFrozen)
                return currentTime;
            else
                return DateTime.Now;
        }

        public static void Add(TimeSpan timeSpan)
        {
            if (timeFrozen)
                currentTime = currentTime.Add(timeSpan);
        }

        public static void Unfreeze()
        {
            timeFrozen = false;
            currentTime = DateTime.Now;
        }
    }
}

Why I write automated tests

Leave a comment

Why I write automated tests.

I write automated tests for a variety of reasons. For one they tell me when I break things. Secondly, having automated tests enables me to go fast. I can make changes with confidence. I am free to aggressively refactor my design. And I don’t stress about breaking the important stuff because I know the automated tests are there to back me up. They are like my shield and my armour.

But really, to me, automated tests are about leverage. They allow me to leverage myself in greater ways that wouldn’t be possible if they weren’t there. I can spend less time regression testing. More time adding new features, improving the testing while doing the one other kind of testing that’s really important – exploratory. These are things things the computer can’t do. Only I can.

So for me automated tests are about leverage. They give us a way to leverage ourselves and our teams further, while giving us all back the one thing we crave. Time.

Beautiful code is good method composition

Leave a comment

Was listening to a podcast with DHH on Tim Ferris show and I really like his definition of beautiful code.

Basically said it’s code where all the methods and abstractions in a class are at the same level. Some methods aren’t doing really low level things. Others aren’t too high. They are all at the same level of abstraction.

Good way to describe any nice API.

For example you can do this:

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupDelegates];
    [self setupLayouts];
    [self setupSearchBar];
    [self setupReachability];
    [self displayTracks];
}

Or you can do this

- (void)viewDidLoad {
    [super viewDidLoad];
    self.searchBar.delegate = self;
    self.collectionView.delegate = self;
    self.collectionView.collectionViewLayout = self.collectionFlowLayout;
    [self setupSearchBar];
    [self setupReachability];
    [self displayTracks];
}

See the difference? The methods are not all at the same level of abstraction. Which makes the code harder to read.

Permission denied (publickey)

Leave a comment

If you suddenly see this it’s because your the keys you use for ssh are either gone or not know to ssh. If you have them, but they just aren’t registered:

$ ssh-add -l (The agent has no identities.)
$ cd ~/.ssh (to see your keys)
$ ssh-add ~/.ssh/id_rsa (or whatever your key is called)

Also, make sure macOS (10.12+) uses your SSH key’s passphrase from the Keychain automatically

$ chmod 600 ~/.ssh/config # temporarily grant write access to the config
$ echo "Host *\n  UseKeychain yes\n  AddKeysToAgent yes" >> ~/.ssh/config
$ chmod 400 ~/.ssh/config

http://stackoverflow.com/questions/26505980/github-permission-denied-ssh-add-agent-has-no-identities

Older Entries

%d bloggers like this: