These are some of my favorite tweets by Kent Beck.
A blog about creating valuable software
March 20, 2017
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
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
March 17, 2017
March 3, 2017
programming c#, clock, dotnet, time, time pattern 2 Comments
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; } } }
February 25, 2017
programming automated testing 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.
February 2, 2017
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.
January 26, 2017
programming git 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