Minimum and Maximum Values of an Array

This method will take in an array of type double and return the minimum and maximum values. I wrote it to deal with temperature readings and to find the min/max for a week.

It will work with any number of array elements as it uses a foreach loop to iterate through the values and assign the smallest and largest values to a new array to be returned.

You might think it odd that I did not use an if-else block, but not using one is important because It allows the min and max to be the same value which would be required if all of the array elements are the same, with an if-else statement the second if statement would be passed over if the first evaluates to true.




Workflowy - Make Lists not War

In my constant quest for great productivity apps, either mobile or for the web, I often come across some pretty mediocre ones. On the other hand, sometimes I come across some absolutely outstanding ones. every now and again, an app will really grab me and it becomes my new favourite toy; So it was with WorkFlowy.

The tag line is Organise Your Brain, and this is very apt. I have found it a great way to organise my thoughts and focus on what I'm doing, and what I want to get done. it’s one of those tabs that’s always open as a reference. The clean simple interface makes it seem like a single document, but with everything in one place.

Your Life in Lists

This app is all about lists, many, many nested lists. Where it succeeds and others have failed is that the lists on WorkFlowy are as complex or as simple as you choose. There are no imposed limits on the lists you create. A wonderful feature is that each list member can be a heading for the next level in the hierarchy, essentially a document in its own right. What this means is that the headings start to act like a folder system, with each successive heading getting more and more refined and more specific to your needs.

Navigation and Keyboard Shortcuts

One of the features that really sealed the deal for me was the inclusion of comprehensive keyboard shortcuts. I love this partly because it is faster than moving my hand off the keyboard to get the mouse and move the cursor a couple of inches and then click, and partly because it makes me feel cool as I zip about the document!

As I mentioned earlier one of the great features is that each heading can be seen as its own document and the best way to view it on its own is to zoom in to the heading. The smoothest way to navigate around the nodes is to use the keyboard shortcuts of alt and left or right, left to zoom in further, right to zoom out.

To enter a new item, simply press enter and a new item will appear at the same level. If you want to indent the item hit tab, and to outdent, hit shift tab.

you can expand the current node without zooming into it by pressing ctrl space. this is a great way to view parts of the document while referring to other expanded lists too. There are other shortcuts as well, but I’ll leave you to check those out.

Adding Notes

Each list item can also have a note attached to it. The note, again ,is a long as you need it to be. The notes are stored as plain text, which makes for a very simple interface, a nice change in current trend of having as many options as possible visible at any one time. When you stop editing a note it auto collapses, hiding all but the top line. This adds to the general feeling of simplicity that the user interface exudes.

Bag it & Tag it (Then Search it)

Most apps that are designed to hold data have a way to tag what you enter to make it easier to search for, and easier to link to other relevant pieces of data. WorkFlowy is no different; it supports tags, searching and clickable tags too. This allows you to tag an item that is related to another item that may be in a separate part of your WorkFlowy, creating a relationship between them. So if you search from the home screen you will be able to easily see the related items on the same screen, and edit them too. To add a tag simply add the ‘#’ symbol to the beginning of the word you want turned into a tag.

If you want to search for a something you can do so easily, either by clicking on a tag that you have or by starting to type in the search box (which you can jump to by hitting the escape key). When you type the ‘#’ symbol a drop down list of potential tags appears, allowing you to choose one. The search is also instantaneous, so the results will be filtered as you type, but only for the node that you are zoomed into.

Completed Items

WorkFlowy can be used as a to do list as well as an information repository. All you need is a #todo tag and you can aggregate all of your to dos from all parts of your WorkFlowy in one place. A future feature is to have due dates and reminders too, which will make WorkFlowy even more useful for getting things done.

When you complete an item you can strike it though by hitting ctrl enter. Having all of the completed items on show can get rather messy, so you can choose to hide or display all completed items right from the top bar for a quick check of what you have done. If you have hide completed items checked and strike through a task, it will disappear right before your eyes, which can be very satisfying indeed.

So, I suggest you try WorkFlowy.com out, it’s a really great app, I'm sure you'll find a use for it, and best of all, it is free! For now anyway it is still being developed, so I’m sure there will be a paid version some time soon.

Update

Since I wrote this blog post, WorkFlowy is no longer free! Well, there is a limited free version, and a paid version for $4.99 a month or $49 per year. This has extra features such as styles and fonts and also unlimited items. When the reminders and due dates are implemented, along with new features such as offline access, they will be pro user only features




Mind Mapping Your Way to Organisational Bliss

Ever since I purchased my first Android phone, i have had a small but persistent obsession with productivity apps. I have so many ideas and thoughts flying around my head that to be able to easily and logically organise and review them is both useful and cathartic.

One of my favourite ways to do this is Thinking Space, a mind mapping app available for the Android platform.

Mind Mapping

You may or may not be aware of mind mapping; if you are, that's great, you already know the power of it. If not, then consider this your initiation! Mind mapping is by no means a new phenomenon, people have been mapping their thoughts and ideas in this manner for decades under the title of 'mind maps', and no doubt hundreds of years under other guises. Mind maps have become known as a tool to use to clearly note down your thoughts in a logical manner.

A great example of this is a brainstorming session. To start, place the main idea in the middle of the map. From this main starting point each of your thoughts or suggestions becomes a new 'node' or junction on the map. You can then add to this node further by adding more nodes to dig down into the idea and note your thoughts, until you have a map that is as simple as you like, or as complex as you need. That really is the key thing to remember about mind maps, whilst they might seem a little overwhelming at first glance, they are only as complicated as you need them to be.

It can be used to organise projects too, below is a map that I have made for this website, as an example of how the mechanisms work, and you can see the way that different parts can be expanded and closed to drill down into the information, or to get a great overview

An Example Thinking Space Mindmap

Making a mind map is a great way to clarify your thoughts, and organise your ideas in a visual way.

Thinking Space

Now we've given mind maps a little intro, let's move onto the app itself; it is very well thought out from many points of view. The menus are consistent and logical, with the main functions exactly where you would expect them to be. That's not to say there is nothing new here, far from it, one of the most useful features is the addition of a gesture pad, reached by pressing the yellow star in the quick menu. This allows the main functions of the app to be controlled by drawing gestures on the gesture pad. the pad can be resized to take up more of the screen if you are using the app on a tablet for example, vs a phone.

Amalgamated images to show the menu system in Thinking Space

The compatibility of the format is another great feature, it can be compatible with the open source mind mapping software Freemind on your desktop, you can 'cloud' your maps and edit them online with Mindmeister, or use XMind to manage them on your desktop as well.

The app allows you to set your own storage folder which whilst not sounding that useful allows you to put the maps into a synced folder, say in your Dropbox or SugarSync folder. This means that whenever you want to use your maps on your desktop computer they are there, ready to go.

To surmise, I love this app! It has made me more organised, it's galvanised ideas that otherwise would be less clear, and has made it easy to manage my side projects, like this site.

Get It

You can download Thinking Space from the Android Market, or visit the developer's page directly here. Let me know what you think: Do you use this app? Do you find it as useful as me? Hit the comments box and post your thoughts.

Update

Since i wrote this piece the Thinking Space developer has been employed by Mindjet and the app has been appropriated by them too. The app still remains on the market, but has lost the cloud functionality. MindJet has also released their own app which is a re-branded version of Thinking Space




Count Instances of a Value in an Array

This method checks to see if the given value is within the array that it is passed. For every occurrence of the value in the array, the counter increases. The method will return an int with the count of the given value in an int[].

In each loop the next item in the array is compared against the value that is being searched for. if the value matches the search term, then the counter increases by one. The count is then returned at the end of the method.

This method obviously uses ints, but it would be jsut as easy to use doubles or any other value type including chars in a char array.




Programmr.com - Code It Online

Every now and again we all need to take a break; to freshen our minds, and refocus our thoughts. it can get really tiring getting bogged down in bug hunting, specification documenting, working on the same project day in and day out or any other long term activity. So when I feel like I’m not getting anywhere I’ll stop what I'm doing and jump over to Programmr.com and have a go at a 'code challenge' to exercise my brain on something completely different, it gives me a mental break whilst still keeping my brain active.

Programmr.com is a relatively new, free website that is targeted at programmers with the aim of allowing students or professionals to practice programming online. You can make & run command-line programs, web applications, database applications as well as rich media apps right in the browser. Supported languages include C#, Java, SQL, Javascript, C++ and Ajax, amongst others. So not only can you jump across and hit up some code challenges, you can change the language that you are using to really take a mental break. The challenges are only available in Java C++ and C# at the moment.

The website seems to be supported by their offerings of programming courses for a very reasonable $30. I have not partaken of any of the courses, so cannot comment on their quality, but would think that they will be great considering the communications I have had with some of the guys. The support on the website is great, the responses I have received when reporting bugs or asking questions have been swift, friendly and informative, and obviously written by knowledgeable people, not just some monkeys drafted in to respond to emails.

There is much more to the site than the code challenges, you can create projects in your own workspace and edit them right there in the browser. The projects can be made public as well to allow others to see your work, and hopefully to learn from it. This is actively encouraged and points are awarded for making your projects public. The points push you up the leader board and are also redeemable against programming courses. so the more you program and the more you release to the public, the more you can cash in your points and continue learning.

Monthly contests with prizes ranging from course vouchers to Amazon vouchers are open to all, from beginner level up to professional. The contests have themes such as a game, or most recently, any educational application, be it educational in terms of programming, or educational in terms of teaching you something else. The competitions are monthly.

A really cool feature of the site is that any project can be copied to your own project folder, and altered to meet your needs or interests. See a neat project that has a couple of features you're interested in, but misses one you would like? No problem, just copy the project to your own workspace and you can edit it to your heart's content. This allows you to view the code that someone else has written, and often leads you to change your thinking slightly, as they will have approached their project differently to how you have.

All this leads to a socially-orientated, learning-driven environment, which is great to be part of.
I suggest you go and check it out, it really is a very useful resource. i like to use it to write quick programs or complete the code challenges when I'm away from my dev machine, just to keep my brain going. you can check the site out Programmr.com, or check out my Programmr profile




Programr.com - Code It Online

Every now and again we all need to take a break; to freshen our minds, and refocus our thoughts. it can get really tiring getting bogged down in bug hunting, specification documenting, working on the same project day in and day out or any other long term activity. So when I feel like I’m not getting anywhere I’ll stop what I'm doing and jump over to Programr.com and have a go at a 'code challenge' to exercise my brain on something completely different, it gives me a mental break whilst still keeping my brain active.

Programr.com is a relatively new, free website that is targeted at programmers with the aim of allowing students or professionals to practice programming online. You can make & run command-line programs, web applications, database applications as well as rich media apps right in the browser. Supported languages include C#, Java, SQL, Javascript, C++ and Ajax, amongst others. So not only can you jump across and hit up some code challenges, you can change the language that you are using to really take a mental break. The challenges are only available in Java C++ and C# at the moment.

The website seems to be supported by their offerings of programming courses for a very reasonable $30. I have not partaken of any of the courses, so cannot comment on their quality, but would think that they will be great considering the communications I have had with some of the guys. The support on the website is great, the responses I have received when reporting bugs or asking questions have been swift, friendly and informative, and obviously written by knowledgeable people, not just some monkeys drafted in to respond to emails.

There is much more to the site than the code challenges, you can create projects in your own workspace and edit them right there in the browser. The projects can be made public as well to allow others to see your work, and hopefully to learn from it. This is actively encouraged and points are awarded for making your projects public. The points push you up the leader board and are also redeemable against programming courses. so the more you program and the more you release to the public, the more you can cash in your points and continue learning.

Monthly contests with prizes ranging from course vouchers to Amazon vouchers are open to all, from beginner level up to professional. The contests have themes such as a game, or most recently, any educational application, be it educational in terms of programming, or educational in terms of teaching you something else. The competitions are monthly.

A really cool feature of the site is that any project can be copied to your own project folder, and altered to meet your needs or interests. See a neat project that has a couple of features you're interested in, but misses one you would like? No problem, just copy the project to your own workspace and you can edit it to your heart's content. This allows you to view the code that someone else has written, and often leads you to change your thinking slightly, as they will have approached their project differently to how you have.

All this leads to a socially-orientated, learning-driven environment, which is great to be part of.
I suggest you go and check it out, it really is a very useful resource. i like to use it to write quick programs or complete the code challenges when I'm away from my dev machine, just to keep my brain going. you can check the site out Programr.com, or check out my Programr profile




Smallest Number Divisible by 1-20

This algorithm will calculate the lowest number that is evenly divisible by all of the numbers from 1-20. This is one of the Project Euler problems (ProjectEuler.net), which i have recently taken to playing with. I really enjoy thinking in a completely different way to my day job, and this is a great place to do that. Check it out below.

The code uses a do-while loop to increase the number to be tested from 1 to as high as is needed to allow the number to be divisable by 20 and all numbers below.

The for loop iterates through each number up to 20, and the if statement checks to see if the remainder is 0 or not. if it is not, then the number being tested cannot be right, so the for loop breaks and the do-while loop iterates again, having incremented the counter.

Update:
After a bit of thinking followed by some optimisation and refactoring, the code below is a considerably faster way to compute the result.

The method above takes about 10seconds to complete, depending on your system; the new method, below, takes about 200ms on the systems I have tested it on.

The counter int q jumps up 20 with each iteration as we know that the result has to be divisible by 20. The for loop starts counting backwards, counting from 20-1, but stops at 10, this is because if a number is divisible by the numbers 11-20, it is divisible by the numbers 1-10, so there is no need to test them. Also, counting backwards means that the higher numbers are reached first, and these are the ones that are harder to divide evenly by.

I'll keep looking for further optimisations, I'm sure there are some somewhere...




Using the Stopwatch Class as a Tool

There are some really cool tools available to help you test and improve your programs in the.Net Framework.

One of the most simple is the Stopwatch class, situated in the System.Diagnostics namespace. As the name suggests it allows you to create a stopwatch object, and use it to time processes, operations or any other part of your program.

It might sound lke a waste of time to see how fast a small part of your program is, but making all of the smaller parts work better can have a great impact on the overall speed of the program so don't discount it as a method of improving your code.

The code to instantiate the stopwatch is just the same as most other objects, and to start and stop the stopwatch is also very straight forward:

Once you have used the stopwatch to time the running of your code, you can use the Elapsed property to access the time that has elapsed while the stopwatch has been running. It is displayed in the format of HH:MM:SS.0000000. (the first three 0’s represent milliseconds) The time stored in the stopwatch can also be accessed using the ElapsedMilliseconds property, which displays only the milliseconds that have elapsed.

The stopwatch can be read without being stopped, so you can access the Elapsed property and leave the stopwatch running, and then check the elapsed time again later to see the total time. If you want to use the intermittent timings later you can use a TimeSpan object to store the time and perform operations on it such as comparing two times.

Alternatively you can stop the stopwatch using Stop(), and then start the stopwatch again by calling Start(). This will cause the stopwatch to continue where it left off when it was stopped. You can clear the contents of  the stopwatch with the Reset() method, or to clear the stopwatch and start it again with only one method call you can call Restart(). This is preferable to using a new stopwatch as you then don’t need to create another stopwatch object.

Using the stopwatch has been really useful for assessing the speed of my programs, or algorithms. It has often made me refactor and optimise my code to make it run faster, and therefore make the whole application more snappy and responsive.

A prime example of this is in the Smallest Number Divisible by 1 - 20 where my original program took about 10 seconds to find the answer and I thought there must be a faster way. So using the timers to test various theories i came up with an altered algorithm that ran significantly faster than the original.




Printing a Binary Triangle

This little code snippet comes directly from a 'code challenge' I completed on Programr.com and I found it really interesting so decided to put it up here.

The challenge was to create a binary triangle of a size determined by the user. So the program collected user input for the number of rows and then printed a binary triangle to the console output in the format given in the challenge spec below. The method shown here does not include gathering the user input.

If user gives input 5 then the binary triangle should be as is shown at the top of the code below:

The first loop counts the number of lines that are being printed, up to the value of the input.

The second loop uses the count from the first loop to dictate the number of writes required for that given line. ie, as the counter for the first loop increases, the number of characters printed on each line increases proportionally.

The if-else block prints 1 if the last int was 0, and 0 if the last int was 1, then sets the lastInt value to the appropriate value for the next loop.




Convert Days, Hours and Minutes into Seconds

The code below will convert the given number of days, hours, minutes and seconds into seconds.

The value used is an int, which is an alias of System.Int32. What this means is that the maximum number of seconds that can be stored is 2,147,483,647, which is the equivalent of ~68 years' worth of seconds. If a larger number is needed then the method must be changed to use a larger value type, eg long.

After I had written this method, I realised that it would be cleaner if it accepted an int array of the times, I have also implemented this below:

This change tidies up the number of parameters significantly, and works in the exact same way.




Convert String to Title Case

This code snippet converts any string that it is passed into 'Title Case', ie capitalising the first letter of every word. Very useful for titles (unsurprisingly given the name!) It will work with strings that are all lower case, all upper case, or any other mix of case.

Note the using statement to bring in the System.Globalisation namespace, the program will not compile without this.

As an example, the input the quick brown fox jumped over the lazy dog will be converted to The Quick Brown Fox Jumped Over The Lazy Dog