| Subscribe via RSS

MicroBlog Update

August 2nd, 2008 | Comments Off | Posted in MicroBlog

Make a positive number a negative number in 1 line of C# code – A code quiz!

July 16th, 2008 | 10 Comments | Posted in C#

Here are 4 methods, each one is meant to turn a positive number into a negative.

public int ReturnMinusVersion1(int i)
{
    return -i;
}

public int ReturnMinusVersion2(int i)
{
    return --i -i +i;
}

public int ReturnMinusVersion3(int i)
{
    return ~i + 1;
}

public int ReturnMinusVersion4(int i)
{
    return i * -1;
}

The questions are:

Which methods compile?

Which methods produce the correct result?

Explain why the working methods work.

Which is best and why?

Any other cool ways of making a positive number a negative? Have fun!

kick it on DotNetKicks.com

Microsoft Remix UK 08

July 3rd, 2008 | Comments Off | Posted in Remix08

remmix08uk "ReMix UK 08 is a 48 hr conversation; join us from the 18 – 19 September 2008 at the Brighton Centre, Kings Road, Brighton. ReMix UK 08 is all about the ‘Next Web’, what it means today and the potential impact of technologies, tools and techniques for the future. "

If you want to attend, you better get a hustle on and register as tickets are selling fast by all accounts. Last years event was fantastic and this time around it’s set to be bigger and better than ever. See you there!

Super Lambda Bananas

June 29th, 2008 | Comments Off | Posted in C#, LINQ

302279198_06564a7141_m I’m a big generic collection user and I can’t express how much the C# 3 Linq expressions have improved my coding experience, especially in the form of lambda syntax. I used to spend a lot of time trying to bend predicates to my will in order to pull the good stuff out of my collections, and some of the new expressions make this a thing of the past.

Some of the expressions do need a bit of extra thought to understand what is going on though. For example, what is the difference between .Where, .TakeWhile and .SkipWhile? They all return a subset of your collection, but what exactly do you get? Let’s investigate!

So say we start with this:

string[] names = {"dave", "dee", "dozy", "beaky",
"mick", "titch", "darius"};

names.Where(name => name.StartsWith("d"));

 .Where will return “dave”, “dee”, “dozy” and “darius”, matching everything that starts with ‘d’. TakeWhile and SkipWhile are different though, working on your sequence only until a specified condition is deemed false. So…..

names.TakeWhile(name => name.StartsWith("d"));

will return “dave”, “dee” and “dozy”: the search is called off when StartsWith(”d”) becomes false. Conversely

names.SkipWhile(name => name.StartsWith("d"));

 

will get you “beaky”, “mick”, “titch” and “darius”, skipping the items in the sequence until StartsWith(”d”) becomes false.

Try doing that with predicates!

Entity Framework Under Fire

June 27th, 2008 | 2 Comments | Posted in EntityFramework

If like me you spend some of your spare time keeping tabs on what is going on in the .Net blogosphere you wont have failed to notice the current drama surrounding the new Microsoft Entity Framework.

To cut a long story short: a bunch of know-it-alls have got their knickers in a twist over some of the features excluded from version 1 ( VERSION 1!!!) of the framework. I think, knowing the nature in which Microsoft evolves their products nowadays ( look at how different the Ajax Framework is now compared to the first release ) this really is a storm in a teacup. The most common sense, pragmatic, real world view of the state of play is this one by Ward Bell. For me, he hits the nail on the head.

In my opinion there is a real attitude problem on display from the petitioners, who I suspect have a vested interest in seeing EF fail or look half thought out. I’ve had a long term disregard for 99% of ORM tool vendors ( the excellent Subsonic framework excluded ) because of the ‘I-know-best-don’t-even-try-to-question-or-understand’ tactics they use to retain a foothold in the marketplace.

I’m a big fan of this quote from the highly recommended book – The Pragmatic Programmer by Andrew Hunt & David Thomas:

“Critically Analyse What You Read and Hear. Don’t be swayed by vendors, media hype, or dogma. Analyse information in terms of you and your project.”

Bottom line: Make your own mind up about Entity Framework, about if it’s right for you and your projects.

SQL Injection – Script kid method du jour

June 25th, 2008 | 2 Comments | Posted in Uncategorized

SQL Injection is back on the rise again it seems. Remember kids, make sure your forms are well scrubbed before doing anything with user data.

sql

ADO.NET Entity Framework Quickstart Tutorial

June 3rd, 2008 | 3 Comments | Posted in ASP.NET, C#, EntityFramework, LINQ

The ADO.NET Entity framework received another update last week as part of the Visual Studio 2008 and .NET Framework 3.5 Service Pack 1 Beta, so to coincide with this I give you a quick run through to get you started. Being honest, if you have used an OR mapper in the past this will be familiar territory. If not, this new implementation is a good place to start.

screenshot1 So to begin, create a new ASP.NET website, Add New item, and then choose ADO.NET Entity Data Model. Name it EntityModel.edmx and click Add to create a new model.

The Entity Data Model Wizard will pop up and give you a chance to configure your new model. For the purposes of this walk through, choose Generate from database and click Next.

screenshot4 Set up your data connection, I won’t go into this as it’s simple enough to figure out if you’ve never done it before. Click the checkbox to save entity connection settings into your web.config and name it MyEntities.

screenshot6The wizard will then tootle off and retrieve the names of all the tables, views and stored procedures in your database. Choose a table ( I’ve chosen a table from my DB called ‘Log’ ) and name the Model Namespace MyModel.

Click Finish and the designer for your model will open. As a side note have a look at the Model Browser on the right hand side – it looks a bit ‘rendered’ for want of a better description, as though it’s drawn via GDI+ compared to the Solution Explorer….strange!

Now add a new web page and go into the code behind to start the real work. It’s just a simple bit of code to CRUD the Log entities in my database.


// instantiate a new Log entity
MyModel.Log log = new MyModel.Log();

// populate it’s properties
log.Date = DateTime.Now;
log.Exception = “Test Exception”;
log.Level = “Test Level”;
log.Logger = “Test Logger”;
log.Message = “Test Message”;
log.Thread = “Test Thread”;

//instantiate the entity ‘context’ – the object used
//as a ‘gateway’ to the DB
MyModel.MyEntities entities = new MyModel.MyEntities();

// Save the new log entity to the DB
entities.AddToLog(log);
entities.SaveChanges();

// Load it back via a little LINQ query
// ( funny how you must use .First instead of .Single )
MyModel.Log loadedLog = entities.Log .Where(ent => ent.Level == “Test Level”).First();

// make a change and save it back to the DB
loadedLog.Message = “Message has changed!”;
entities.SaveChanges();

// Finally delete the object from the DB
entities.DeleteObject(loadedLog);
entities.SaveChanges();

Notice how you have to call .SaveChanges() to persist back to the DB. That’s it! A super fast run through of CRUD with the ADO.NET Entity Framework! Enjoy!

kick it on DotNetKicks.com

Come and work for Qire in Liverpool

June 3rd, 2008 | Comments Off | Posted in ASP.NET, C#

Qire LogoFancy coming to work in Liverpool – European Capitol of Culture 2008 – to build the next generation of voice driven applications?
Qire is the acknowledged leader in intelligent voice messaging systems with many top notch public and private sector clients.
We create applications that manage security, business process and call centre automation via the power of ASP.NET and C# ( plus some other exciting technologies that you can learn on the job ). We are looking for a permanent mid/high level developer to join our small team of happy coders to help shape the future of telephony. You will be adept at asp.net c# sql, have good soft skills and want to work in a friendly and creative coding environment. If you are interested, send me note ( or even better a link to your CV) via the contact form on this site.

Blabnote.com – Vocal Social Network

May 16th, 2008 | 4 Comments | Posted in Blabnote, Telecommunications, Web 2.0


I’ve got 5 invites to the brand new voice powered social network Blabnote to give away. This new application, currently in private beta, promises to give users access to advanced communication tools, ad-hoc creation of contact conference groups and industrial strength feature rich voice mail and messaging. To win an invite, drop me an email and the first 5 to land will get one.

Edit: Too late! All gone! Leave a comment and i’ll get back to you if I get any more invites to distribute.

Thinking Digital: 21-23 May 2008

May 15th, 2008 | Comments Off | Posted in Mesh, Telecommunications, VOIP, Web 2.0

thinking digital I’m off to the Thinking Digital conference at The Sage Gateshead this time next week. Billed as an ‘event where outstanding individuals gather to take part in an exclusive conversation about technology, ideas and our future’ it’s a great chance to see some of the best speakers the planet has to offer in action. Highlights on offer include:

Steve Clayton, Microsoft’s Software plus Services Lead and all round top bloke, demonstrating some of the coolest new technologies to come out of Redmond, including what’s expected to be a first UK demo of Live Mesh.

The Fake Steve Jobs (a.k.a. Dan Lyons, Senior Editor at Forbes), author of Internet sensation The Secret Diary of Steve Jobs, giving his unique, hilarious take on the world of technology, the people who drive it, and the future of media.

Greg Dyke, Chairman of the British Film being interviewed live on stage by Andy Allan, the former CEO of Carlton Television, about management and leadership challenges, as well as his views on the future of media.

World-renowned inventor and futurist Ray Kurzweil speaking via stunning Teleportec technology about his groundbreaking work on The Singularity and the point at which computer intelligence will surpass our own, in every form.

Hopefully it should be clear to you that with such a lineup set to appear, I’m more than a little excited to be one of the lucky 400 who gets to attend!

  • Cloud

    Ajax AmpliFeeder ASP.NET Blabnote C# Cloud Design EntityFramework Framework JavaScript JQuery LINQ Live Mesh MicroBlog Mix07 Mobile Productivity Rails Remix08 SDS Silverlight2 SQL SSDS TDD Telecommunications Uncategorized VOIP WCF Web 2.0 Webcast

  • @jonpauldavies