måndag 3 september 2012

GitHub powershell prompt

Tired of the GitHub powershell prompt printing the whole path of the working directory, instead of just the name of it? I.e.:
C:\Users\Christian\Documents\GitHub\Wint [master]>
I don't want to change the window/buffer size of my console window just so that the prompt fits into it. Turns out it's relatively simple to fix. Just open up profile.example.ps1 which is located in a folder such as c:\Users\Christian\AppData\Local\GitHub\PoshGit_<some_hash>\, and change the Write-Host line into this:
Write-Host(split-path -path $pwd -leaf) -nonewline
Now you've got a nice prompt saying:
Wint [master]>
Nice and easy! :)

(Not sure if this is going to last for ever though, I guess GitHub will change the name of profile.example.ps1 into something better in the future...)

söndag 2 september 2012

Using scrum? Try kanban!

(Thanks to @gustaf_nk for recommending kanban!)

I had never before heard of kanban, but when I was introduced to it I got interested and had to buy a book in the subject. So I went ahead and bought Kanban and Scrum - making the most of both, and read it page to page in only a few days. Back to work I started to implement the kanban strategy in our current project, and it didn't take long before I started loving it!



Kanban is perfect for teams looking for quicker deployments and tighter feedback loops. Scrum limits you because of the sprints - you may only release after a completed sprint - but with kanban you can release as soon as you've completed a story, even if you've got other incomplete stories going on at the same time. You don't have to plan every sprit in details, don't have to allocate sprint time for a release, don't have to wait for the next sprint until you can start working on a new story and you don't have to split larger stories into sprint lengths. 

The only downside as I've seen with kanban is that it's a bit complicated to implement. In scrum all you need is your development branch, and when you release you simply release directly from it (or merge everything to a release branch). In kanban you need a separate branch for each story, since you don't know which stories will be included in the next sprint. Luckily all you need is Git and some basic knowledge in branching, and you are set to go!

I'll write another blog post covering the details of how we used Git to implement kanban. Until then, go check out that book!




måndag 27 augusti 2012

Windows Azure!

(First of all, thank to Scott Hanselman for motivating me into blogging again!)

Windows Azure - finally an easy way to deploy MVC projects, and cheap! At least what it looks like, I'm still waiting for my 3 months free subscription to run out, then we'll see what the price tag ends with.

During this summer I've deployed 3 projects to Windows Azure just because it's so easy. The first project was an old project I converted from running on my own virtual server (with IIS and MSSQL setup manually). It's called SebKul, and can be used to analyze your private economy by automatically logging in to SEB (Swedish bank) and running some measurements. For example, it will calculate the amount of money you may spend per day before running out of cache in the end of the month. If you spend too much money one day, it will mail you letting you know you need to be more careful in the rest of the month. You may also group different expenses to see what you spend the most money on. It is really beta, but if you have SEB it might be fun to try out: http://sebkul.azurewebsites.net (in swedish)




The second project was a simple mailing application - Mail Me When. Let's say you are interested in knowing when a new episode of a serie is available for download, but don't want to check the piratebay every now and then. This site will automatically check the piratebay rss, and scan for the serie you are interested in. If a new episode appears, it will send you a mail.


The third project is a project I'm currently working on - Inköpslista (shopping list). I was tired of always forgetting what to buy when in the grocery store, and never having the (paper) shopping list nearby when I needed something. I browsed the web for a digital shopping list alternative, but couldn't find anyone fitting my (simple) needs (the text within parenthesis is how I solved it):
  • Easy access from any device (a simple web page)
  • Easy login (a technique based on IP and cookies)
  • Easy sharing (just send a link to your friend)
  • Mobile friendly (using jQuery Mobile)
On top off that I made it a bit clever by:
  • Knowing what store you are in (using GPS coordinates), and presenting the products to buy in the same order you selected then in when shopping in this store the last time
  • Recommending products you buy frequently (i.e. milk every week, cheese every third week)

It actually turned out to be something I'm really pleased with, and now uses on a daily basis! Try it out an let me know what you think.

So if you haven't tried Windows Azure yet (you don't even have to be a .net developer), give it a try. Three months for free, it's worth it!

söndag 13 december 2009

Python and doctest

I've just recently got to learn Python, and after a bit of struggling with the new syntax, I found the language to be very appealing. It's well structured, and has been around for a long time so if you can't find the library you are looking for in pythons standard libraries (which is very unlikely), there are a bunch of other libraries to install (for example lxml, which is a great xml/xpath wrapper for libxml2). The only issue I've had so far is with some libraries not being compatible with python 3.1 (which differs a lot from 2.x), but this is probably a transition period soon being over.

And as with all languages, sooner or later you would like to know how to setup your tests. And when googling "python test framework", I stumbled upon doctest:

The doctest module searches for pieces of text that look like interactive Python sessions, and then executes those sessions to verify that they work exactly as shown.
This is something I've never seen before, but yet strikes me as very powerful. To write your tests, you simply include an example execution of the function you want to test in the comment, i.e.:

'''
This function prints the string "Hello World!".

For example:
>>> say_hello_world()
Hello World!
'''
def say_hello_world():
print("Hello World!")
To run the tests, you can either include the test execution in the main method of the script file, which to me is wrong if you would like to have another default main method. Another way to do it (if you have python 2.6 or later) is to execute like this:
python -m doctest -v helloworld.py
This will load the doctest module, and then execute the tests in helloworld.py, which will call the function say_hello_world(), and make sure it's output equals "Hello World!", as written in the comment. You then extend the tests by simply including more examples in your comment.

IMO, the real power of this is that you don't need to write separate test functions, plus you get the documentation for free. I.e., with xunit the same test would look something like this:

def test_say_hello_world():
mocked_print = create_print_mock_function()
say_hello_world()
xunit.assert_equal("Hello World!", mocked_print.get())

And I'm not even sure if create_print_mock_function is possible to do. Even if it would, the tests becomes much larger, and harder to maintain.

The main downside I see to using doctest is that it depends on the expected output being formatted exactly as python would have formatted it. For example, the following function will fail, just because python will include extra spaces in the array:

'''
>>> get_array()
[1,2]
'''
def get_array():
return [1,2]
will fail with
Failed example:
get_array()
Expected:
[1,2]
Got:
[1, 2]
In this case it's easy to fix, but how will it scale when you have hundreds of tests? What happens when you update your tostring methods? Instead of inspecting the returned data, you inspect the data formatted to a string, which can very well mean something quite different if you are writing your own tostring methods.

Anyway, at the latest coding dojo (Majorna Coding Dojo!), we decided to give python and doctest a try, and it worked very well. Even though most of us didn't know Python from before, we didn't have any problems using doctest.

I will definitely use doctest more in the future, and will even see if I can find similar testing frameworks (Document Driven Development, DDD) for other languages such as Ruby, C# and C++. So if you are into Python programming, I definitely recommend you trying this out.

torsdag 27 augusti 2009

My first piano sheet successfully created!



Just recently finished my first piano sheet based on an improvisation I made some years ago. Not that I was planning to do anything serious with it, just to learn and to some day be able to say: "I've produced my own piano sheet". Well, now I can :) There are some things I know I could make better, but it takes too much time figuring out how to do it in Cubase (which I used to produce the sheet), so I'll just let it be as it is now. It was really fun producing it, so I'll definitely continue doing so. And hopefully it won't take so much time in the future!

Update: My server isn't up and running anymore, but you may actually find my music on spotify!

tisdag 18 augusti 2009

Podcasts at 2x speed

On a morning walk to work for a few days ago, when I, as usual, listened to a podcast on my iPhone, I happened to accidentally click on an icon I've never noticed earlier - "2x". Suddenly my podcast started playing at two times the speed (at least what it felt like), but without making it difficult listening. It was actually quite easy to keep up with the podcast-dialogue, and after 15 minutes I had completed half an hour long podcast. It feels a bit like skimming through a book, you may miss the details, but get the big picture. And when they suddenly start talking about something that is very interesting you can always return to the "standard speed".

So if you have an iPhone or iPod Touch with OS 3.0, start a podcast and click the 2x-icon in the upper right corner, and you may be able to start optimizing your time!

tisdag 2 juni 2009

Objective-C... yet another programming language?

Just recently installed XCode on my mac in order to develop applications for my iPhone. The first thing I realized was that I needed to learn yet another programming language. Just another syntax, or does Objective-C actually bring something new?

It turns out Objective-C (which is a language derived from C, similar to C++, but still very different) has one feature I haven't seen before. First of, instead of calling a method on an object, your send a message to it. It's almost the same, but also requires you to pass along named parameters (which means more code to write, but easier to read). The new and cool feature appears when you want to send a message to an object, which should return a value, when the object turns out to be nil.

MyClass* myObject = nil;
if ([myObject getValue] == 0.0) {
// myObject getValue retuned 0, OR myObject is nil
}

So when executing this code, as opposed to how normal programming languages handles it, it doesn't crash. It simply returns 0.0 if the expected return type is a number, or nil if the expected return type is a pointer to an object. This also works for functions returning nothing (i.e. void), sending a void returning message to a nil object will simpy do nothing.

In for example C# you always have to do null checks all over the code, in order to verify your object isn't nil.

I'm not sure I like it or not, but if you learn to think "pure Objective-C" then perhaps this can be used as an advantage! I'm looking forward to learning Objective-C further, and to adapt these new concepts!

I'll let you know when I've published my first iPhone app :)