Mick Walker http://blog.mick-walker.co.uk a 'so called' developer posterous.com Mon, 26 Mar 2012 12:08:41 -0700 Never Forget http://blog.mick-walker.co.uk/never-forget http://blog.mick-walker.co.uk/never-forget

Those we love don't go away,

They walk beside us every day,

Unseen, unheard, but always near,

Still loved, still missed, and very dear.


Peacefully sleeping, resting at last,

His weary trials and troubles past,

In silence he suffered, in patience he bore,

Till God called him home to suffer no more.


Although we smile and make no fuss,

No one misses him more than us;

And when old times we often recall,

That's when we miss him most of all.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Tue, 13 Mar 2012 17:25:02 -0700 Recognition http://blog.mick-walker.co.uk/recognition http://blog.mick-walker.co.uk/recognition

P112

Received this yesterday :)

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Tue, 29 Nov 2011 06:45:00 -0800 How to Increase or Decrease the Size of Your BOOTCAMP Partition in Lion. http://blog.mick-walker.co.uk/how-to-increase-or-decrease-the-size-of-your http://blog.mick-walker.co.uk/how-to-increase-or-decrease-the-size-of-your

If you want to increase or decrease the HD space on your Boot Camp partition of Windows, this is how you do it for Mac OS X Lion for free. Below is a an overview of the steps that need to be taken.

  • Clone (Copy) your Window's BOOTCAMP to an external Hard Drive (HD) or to your computer if you have enough space.
  • Delete the Window's partition on your computer.
  • Repartition your computer to have the new size that you want.
  • Restore your old Window's BOOTCAMP data.

In more detail, I walk through the steps here:

1. Download the free software Winclone from Roaring Apps Website (yes Winclone still works for Lion).

http://roaringapps.com/app:904

2. Now you are ready to copy your partition. Install and open Winclone. Under the Image tab, choose the Source BOOTCAMP in the drop down menu. Then click Image… Save your BOOTCAMP Clone to an external HD or your computer if you have enough space.

This will take some time so be patient (between 1-3hrs). You can see your progress percentage by pressing Command-L. 

You should now see a .winclone file in your external HD that is about the same size as your BOOTCAMP HD. If you are confident that you didn't interrupt the copying process turned off your computer halfway through then you can move onto the next step. 

 

3. This step is only applicable if you wish to decrease the size of your bootcamp partition.

Open Winclone, and select Tools -> Shrink Windows (NTFS) Filesystem or image and select the image which you just created in Step 2. This will enable you to downsize the image of your Windows partition.

4. To delete the partition on your computer open Disk Utility (you can search for it in Spotlight). Click the top HD on the left hand side, then click the Partition tab, and highlight the BOOTCAMP partition. 

Click the minus sign and click ok.

5. Download the Free Trial of Paragon NTFS 9.5 (It is for 10 days, but you delete it after you are done) http://www.paragon-software.com/home.../download.html

This will allow you to create NTSF partitions. Before in Snow Leopard, you could get the Boot Camp Assistant app to do this for you. However in Lion the Boot Camp Assistant now does not let you partition your drive without having a Window's disk inserted. So that is why I found this workaround. 

Install the Paragon application. Then go back to Disk Utility. This time click the plus button, and name your partition BOOTCAMP. Resize the partition to be the new size that you want it to be.

5. After the partitioning is completed. Open back up Winclone, click the restore tab. Beside Restore Image: select the .winclone file that you backed up previously, and click restore. This should also take a while (between 1-3hrs). Then you are done!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Mon, 17 Oct 2011 04:53:13 -0700 iPhone 4S - My first thoughts http://blog.mick-walker.co.uk/iphone-4s-my-first-thoughts http://blog.mick-walker.co.uk/iphone-4s-my-first-thoughts So, on Sunday I decided it was time to upgrade my contract with O2. I had been on a month to month rolling contract since June 2011. I decided to go for the new iPhone 4S.

I am probably one of the few people that is upgrading from the iPhone 4, I purchased the iPhone 4 when it was first released, replacing my iPhone 3GS which was issued with my contract.

My first impressions are simply Wow! The speed on this thing is unbelievable, and the iPhone 4 wasn't sloppy either, but the 4S blows it out of the water; add to that the all new Siri feature which allows you to control your phone entirely via voice (naughty, but great for sending text messages while driving) and this phone is in a class of its own.

As I said these are my first thoughts, I only got the phone yesterday, I'll post a dedicated write up shortly :)

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Thu, 22 Sep 2011 07:29:00 -0700 Using GData API with protected YouTube streams http://blog.mick-walker.co.uk/using-gdata-api-with-protected-youtube-stream http://blog.mick-walker.co.uk/using-gdata-api-with-protected-youtube-stream

I am using the GData libraries provided by Google for accessing various Google data sources; in particular in this instance I am attempting to access a number of private YouTube videos from a cooperate account.

I am coming across a problem, whereby I login to YouTube with an authenticated account, and can retrieve the stream, however when I attempt to play one of the video items, I am presented with the error message "This video is private" (Yes, I know it is private, I made it private!).

I am just wondering if anyone has came up against this before, or has any pointers for me when using GData.

A stripped down version of the code is shown below. I have changed the stream URL to the generic 'most watched' stream in order to protect copyright content.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Linq;
using System.Net;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Google.GData.Client;
using Google.GData.YouTube;
using Google.YouTube;

/// <summary>
/// Mick Walker
/// 22 September 2011
/// </summary>
public partial class _Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var service = new YouTubeService("YouTubeAPITest");
        service.setUserCredentials("username", "password");

        try
        {
            service.QueryClientLoginToken();
        }
        catch (WebException ex)
        {
            throw ex;
        }
        var settings = new YouTubeRequestSettings("YouTubeAPITest",
                                                  "Developer Key",
                                                  "username", "password");
        var request = new YouTubeRequest(settings);

        Feed<Video> videoFeed =
            request.Get<Video>(new Uri("https://gdata.youtube.com/feeds/api/standardfeeds/most_viewed?max-results=4"));
        BindInformation(videoFeed);
    }

    private void BindInformation(Feed<Video> feed)
    {
        Control parentControl = Page.FindControl("rightVideoContainer");
        using (parentControl)
        {
            // Dont bother if we have no videos
            if ((from f in feed.Entries select f).Count() <= 0) return;
            foreach (Video entry in feed.Entries)
            {
                if (entry.Thumbnails.Count > 0)
                {
                    // Create the parent
                    var videoContainer = new HtmlGenericControl("div");
                    videoContainer.Attributes.Add("class", "videoItem");

                    // Create the control which contains the default image
                    var imgButton = new ImageButton {ImageUrl = entry.Thumbnails[0].Url};
                    imgButton.Attributes.Add("Height", "90");
                    imgButton.Attributes.Add("Width", "120");
                    imgButton.CommandArgument = entry.VideoId;
                    imgButton.Click += imageClicked;
                    // Add the controls
                    videoContainer.Controls.Add(imgButton);
                    parentControl.Controls.Add(videoContainer);
                }
            }
        }
    }

    protected void imageClicked(object sender, ImageClickEventArgs e)
    {
        string videoString = string.Format("http://www.youtube.com/v/{0}?version=3&autohide=1&autoplay=1&controls=0",
                                           ((ImageButton) sender).CommandArgument);

        string chromeString =
            string.Format(
                "<object style=\"height: 390px; width: 640px\"><param name=\"movie\" value=\"{0}\"><param name=\"allowFullScreen\" value=\"flase\"><param name=\"allowScriptAccess\" value=\"always\"><embed src=\"{1}\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowScriptAccess=\"always\" width=\"640\" height=\"390\"></object>",
                videoString, videoString);
        var playerObject = new Literal {Text = chromeString};
        Control parentControl = Page.FindControl("leftVideoContainer");
        parentControl.Controls.Add(playerObject);
    }
}

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Sat, 06 Aug 2011 05:33:28 -0700 Your Sex Life In Terms Of Angry Birds http://blog.mick-walker.co.uk/your-sex-life-in-terms-of-angry-birds http://blog.mick-walker.co.uk/your-sex-life-in-terms-of-angry-birds
Image

Courtesy of http://www.mmarley.com/

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Wed, 01 Jun 2011 05:16:43 -0700 Super Injunctions http://blog.mick-walker.co.uk/super-injunctions http://blog.mick-walker.co.uk/super-injunctions If anyone doesn't want to know about the latest super injunction gossip, it may be worthwhile not to look at @legal_aids twitter feed ;-)

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Tue, 24 May 2011 06:07:15 -0700 Standard iPhone Element Sizes (Width x Height) http://blog.mick-walker.co.uk/standard-iphone-element-sizes-width-x-height http://blog.mick-walker.co.uk/standard-iphone-element-sizes-width-x-height

Core Elements:

Carrier Status bar - 320x20
UIView - 320x460
UINavigationBar - 320x44
UITabBar - 320x49
UISearchBar - 320x44
UIToolBar - 320x44

Data Input:

UIPickerView - 320x216
UIDatePicker - 320x216
UIKeyboard - 320x216

Buttons:

UISegmentedControl - 320x44
UIButton xx37

Fields:

UITextField - xx37
UISwitch 94x27
UISlider - xx23

Indicators:

UIProgressView -xx9
UIActivityIndicatorView - 37x37
UIPageControl - 38x36

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Fri, 20 May 2011 03:27:00 -0700 Northern Ireland Tattoo Convention http://blog.mick-walker.co.uk/northern-ireland-tattoo-convention http://blog.mick-walker.co.uk/northern-ireland-tattoo-convention

Just a quick note, the Northern Ireland Tattoo Convention is happening on the 4th/5th of June, some of the regions best 'inkers' will be there. Tickets are only £10 on the door; I know I will be there :)

 

http://www.nitattoo.com

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Fri, 13 May 2011 09:03:33 -0700 Full Steam Ahead http://blog.mick-walker.co.uk/full-steam-ahead http://blog.mick-walker.co.uk/full-steam-ahead

A day out on the Bushmills to Giants Causeway railway

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Fri, 13 May 2011 08:58:23 -0700 What do you listen to as you code? http://blog.mick-walker.co.uk/what-do-you-listen-to-as-you-code http://blog.mick-walker.co.uk/what-do-you-listen-to-as-you-code My question to you is what do you like to listen to as you code?

I have lately started to listen to audio books as I write code, currently I am listening to The Lord of the Rings which I am sure needs no introduction. The reason I have started to listen to audio books instead of music, is I find audio books less invasive; when listening to music, I often find myself skipping tracks which I don't particularly like; which leads to a break in my concentration, and means that I am less productive.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Mon, 02 May 2011 06:21:27 -0700 Osama Bin Laden http://blog.mick-walker.co.uk/osama-bin-laden http://blog.mick-walker.co.uk/osama-bin-laden So I wake up this morning to the news that Osama Bin Laden is dead and his body has been disposed of at sea. I also see a lot of US citizens on the news cheering about the fact a man is dead. Personally I would find it hard to be happy about the death of anyone; no matter what atrocities he/she had committed. A life is a life.

But personal feelings aside, am I the only person who thinks the death of this man is a waste? Surely the intelligence he could have provided alive would have saved many more lives in the years to come. By allowing him to be murdered; yes I use the 'M' word as I believe no one has the right to act as judge, jury and executioner as the US have done, they have created exactly what the Jihadist movement needed the most, a martyr, a focal point for other potential militants to rally towards. I believe that instead he should have faced trial, publicly, to be judged by a committee of international representatives.

Of course now the conspiracy theories will start; he is still living, he was killed to be silenced etc etc. I actually partly believe the second, I believe he was in possession of information the US government would not want to be made public; could it be regarding the 'aeroplane strike' on the pentagon? Or the CIA's involvement in Muslim states?

One thing I am sure about is that we will now never know the truth.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Wed, 27 Apr 2011 14:07:00 -0700 UILabel Vertical / Bottom Align http://blog.mick-walker.co.uk/uilabel-vertical-bottom-align http://blog.mick-walker.co.uk/uilabel-vertical-bottom-align

I find it hard to believe that Apple when developing the iOS SDK, did not take into account that users may wish to align label text, either to the top or the bottom of a label. Instead they simply give the option of aligning it to the center, as shown below:

20090628-jkf727u2wsbsrgfhep3ja

This code allows you to align text either to the top or the bottom of a UILabel

I hope this helps someone else struggling with this issue, maybe it will be fixed in iOS 5.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Sun, 17 Apr 2011 02:46:53 -0700 Shameless Plug http://blog.mick-walker.co.uk/shameless-plug http://blog.mick-walker.co.uk/shameless-plug

I just wanted to take a second to let everyone know about Countdown, an application developed by myself which is available in the Apple App Store.

The purpose of countdown is simple, you enter a date and it shows you a countdown to that date and notifies you when the date is imminent. It supports multiple dates, local notifications and advanced user interface customisation.

What's more it is totally free and available now! Grab your copy today!!!

http://itunes.apple.com/gb/app/countdown/id343020892?mt=8

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Fri, 15 Apr 2011 15:26:53 -0700 Twitter have disabled posting from Countdown http://blog.mick-walker.co.uk/twitter-have-disabled-posting-from-countdown http://blog.mick-walker.co.uk/twitter-have-disabled-posting-from-countdown Those of you who may be wondering why you can no longer post your countdowns to Twitter should be aware that Twitter have disabled the application and banned it from their servers.

This is due to the fact that I decided to use a URL shortening service to shorten the applications links. Twitter see's this as URL obfuscation and as such is a potential security risk - quite logical when you see it from their point of view.

I have now updated the links to use the fully qualified URL, and emailed Twitter to let them know. I hope for a speedy resolution to the issue.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Thu, 14 Apr 2011 11:30:00 -0700 A picture tells a thousand words http://blog.mick-walker.co.uk/a-picture-tells-a-thousand-words-tags-persona http://blog.mick-walker.co.uk/a-picture-tells-a-thousand-words-tags-persona

I am not an emotional person, those who know me will testify to that. I find it hard to express the way I am feeling most of the time, and have a habit of bottling things up inside rather than speaking my mind. This is why this post is truly unique; I wouldn't generally be one to blog about the way I feel.

Today while reading an article on Mental Floss, I actually found myself with a tear in my eye. The article in question is here http://www.mentalfloss.com/blogs/archives/15131, and while I will give a little synopsis of the content here, I can never truly do the original article the justice it deserves.

The original article, tells us a story of a man, Jamie Livingston. Jamie was a photographer who led a normal life, but did an extraordinary thing: every day from when he started his project in 1979 until his untimely death in 1997, Jamie took a photo each day with his Polaroid SX-70 camera. If you wish to know more about Jamie, I would suggest you read the article above; it really moved me.

Looking through the pictures had a profound emotional affect on me, I felt as if I was there, actively participating in Jamie's life. The photos which are set over nearly 20 years, chart the artists life, from being young and care free, to his eventual marriage, through to his battle with cancer and his untimely death aged 41. Someones the picture has a subject, other times, to those looking from the outside they may seem totally random.

You can access the photos directly here http://photooftheday.hughcrawford.com/, but I strongly recommend you read the above mentioned article first as it really sets the context.

This is an incredible story, not only to a man who has sadly departed this world, but to the legacy of a man. Jamie Livingston will never be forgotten by his friends, but now thanks to these photos being shared with the world, he will never be forgotten, his legacy and his work through this project are now immortal.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Thu, 14 Apr 2011 10:32:00 -0700 Learning to drive http://blog.mick-walker.co.uk/learning-to-drive http://blog.mick-walker.co.uk/learning-to-drive

IMG_0485.MOV Watch on Posterous

Something tells me that he is going to share my love of fast cars.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Tue, 12 Apr 2011 08:34:00 -0700 Custom Event Receiver http://blog.mick-walker.co.uk/custom-event-receiver http://blog.mick-walker.co.uk/custom-event-receiver

I was faced with the challenge of writing a proof of concept today. The scenario was the following:

Client is using SharePoint 2010 as a EDRMS
Client will be performing bulk scanning of historic paper based records into the EDRMS
Client is using third party software, to add necessary meta data to items scanned into the system, this software uses OCR and coversheets.
Documents scanned will be automatically added to document library; then based on document meta data, the file should be automatically moved to a folder contained in another document library.
If the folder mentioned above does not currently exist, it should be created based on the meta data of the document.
The folder mentioned above, also contains subfolders, which will also need to be generated.

The first major hurdle I had to overcome was the fact that while writing the proof of concept, the documents I would be dealing with while developing would have no meta data. The would be sample documents that I would upload from my development machine. I pondered on this for a while, how could I uniquely name the generated folder which would be automatically generated (if it doesn't already exist) when a new document is added to the library. I decided for testing purposes, I would generate the folder based upon the current date and time, later when a UAT environment is setup, I can refine the process and add the meta data consumption which is required.

The basic flow of the project is shown below (please forgive my terrible Visio skills):

File_plan_flow

Because in the final solution I will be dealing with custom content types, I decided that I would use a customized event receiver on the document library which scanned files were routed to, rather than the Content Organizer.

My code is shown below (minus error checking and sanity checking which I have omitted for the sake of clarity), I hope that it helps someone else in a similar situation, and if not, then should I ever be faced with a similar situation in the future, I know where I can find it.

If you find this useful or have any comments, let me know below.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Mon, 11 Apr 2011 15:09:00 -0700 Human Readable Dates http://blog.mick-walker.co.uk/human-readable-dates http://blog.mick-walker.co.uk/human-readable-dates

Humans (thats you and I) don't think mathematically. Sometimes it is necessary to present them values in a natural format. This is especially relevant to date values, if I were to say to you "My birthday is on the 24th of April" (which it actually is!), it would take you time to compute how far in the future (or the past as the case may be) this is. If I were to say to you "My birthday is in 13 days" (at the time of writing this), it would aid your comprehension of when this event occurs.

As developers we have a responsibility to the users of our products to make their life as easy as possible; however many developers insist on displaying dates and times in rigid formats. Of course, rigid formats do have their uses, if I were developing a transactional based system for use in the banking industry, and I were displaying a large list of transactions to the user, then it is necessary to display the exact date and time on which a particular transaction occurred.

However, if I am writing a comment system for a blog, then I don't need to give the same level of detail, why display the date and time an item was posted to a user and make them calculate how long ago the post was made relevant to the current date and time? This is where human readable dates come in, as humans our brains process time spans a lot better than we do dates; if I were to state "A comment was posted on my blog 18 minutes ago" the human brain can digest this information readily, as it involves no calculations. The below class allows us to process DateTime values into human readable values. I would like to state this is not my code, I downloaded it from the internet some time ago, unfortunately I can't remember where it was downloaded from and thus cannot give credit to the original author; I have simply modified the code to make use of Generic's and make it compatible with version 4 of the .NET framework.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 
public class HumanReadableTimeDescription
 {
 private static readonly string[] VALUES = {
 "day",
 "hour",
 "minute",
 "second"
 };
 
 public object Convert(
 object value,
 Type targetType,
 object parameter,
 CultureInfo culture)
 {
 DateTime time = System.Convert.ToDateTime(value);
 return Describe(DateTime.Now - time);
 }
 
 public static string Describe(TimeSpan t)
 {
 int[] ints = {
 t.Days,
 t.Hours,
 t.Minutes,
 t.Seconds
 };
 
 double[] doubles = {
 t.TotalDays,
 t.TotalHours,
 t.TotalMinutes,
 t.TotalSeconds
 };
 
 var firstNonZero = ints
 .Select((value, index) => new {value, index})
 .FirstOrDefault(x => x.value != 0);
 if (firstNonZero == null)
 {
 return "now";
 }
 int i = firstNonZero.index;
 string prefix = (i >= 3) ? "" : "about ";
 var quantity = (int) Math.Round(doubles[i]);
 return prefix + Tense(quantity, VALUES[i]) + " ago";
 }
 
 public static string Tense(int quantity, string noun)
 {
 return quantity == 1
 ? "1 " + noun
 : string.Format("{0} {1}s", quantity, noun);
 }
 }

We can now use this class in our application:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
private static void Main(string[] args)
{

DateTime dateInPast = DateTime.Now.AddMinutes(-7); // Actually subtracts 7 minutes from the current date
DateTime dateNow = DateTime.Now;
TimeSpan t = dateNow.Subtract(dateInPast);
string dateDescription = HumanReadableTimeDescription.Describe(t);
Console.WriteLine(string.Format("{0} happened {1}", dateInPast.ToString(), dateDescription));

// Another example
dateInPast = DateTime.Now.AddDays(-20);
t = dateNow.Subtract(dateInPast);
dateDescription = HumanReadableTimeDescription.Describe(t);
Console.WriteLine(string.Format("{0} happened {1}", dateInPast.ToString(), dateDescription));
Console.ReadKey();
}

I have attached an image showing the output from this example application.

Screen_shot_2011-04-11_at_23

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker
Mon, 11 Apr 2011 13:40:00 -0700 NSDate - Zero Out Seconds http://blog.mick-walker.co.uk/nsdate-zero-out-seconds http://blog.mick-walker.co.uk/nsdate-zero-out-seconds

I recently had a scenario where I was getting the current date using:

1
NSDate *dateNow = [NSDate date];

Now in many scenarios, this code will work perfectly, but the issue I had was I was performing some quite advanced calculations on the date, and the date contained a value for seconds, which threw my calculations off a little, because I hadn't factored seconds into my equations.

The following code, when passed a NSDate object will 'zero' out the second value, leaving you with an absolute value;

1
2
3
4
5
6
 
- (NSDate *)dateWithZeroSeconds:(NSDate *)date
{
 NSTimeInterval time = floor([date timeIntervalSinceReferenceDate] / 60.0) * 60.0;
 return [NSDate dateWithTimeIntervalSinceReferenceDate:time];
}

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1142767/IMG_0175.JPG http://posterous.com/users/heNYfRulHOPIm Mick Walker Mick Walker Mick Walker