Kian Ryan discusses code, photography and the web. Bob makes a guest appearance.
Kian Ryan - a .NET web
developer, photographer and fencing coach writes on almost anything and
everything. You can find out more about Kian on
the about page.
Just a quick note to say we’re back from the Tweetup hosted by Sweet Mandarin. An absolute damn fine way to spend an evening: good food, good weather and good company. Lisa and co provided dim sum, a half dozen of us decided to stay for a full meal.
This is a brilliant example of how to use social media to promote your business and get it right. A few messages in the right place, and a genuine interest in people. No high and mighty pretentions, but simple ideas promoted well. I applaud you girls.
One trick they have missed… Sweet Mandarin does a £10 all you can eat Dim Sum at the weekends. I think they should be pushing this more, If the rest of their menu is anything to go by, this is superb value for money. If you’re in Manchester this weekend, drop by and give them a try, you won’t regret it.
I occasionally make insightful, if somewhat obvious posts to the GeekUp community. One of my most linked to and pointed posts was in response to a common thread: “how to set up a freelancing business”. I formed “Kian’s Rules For Freelancing”, and present them here for your consideration. The old footnotes are recorded with numbers, the new footnotes are recorded with roman numerals.
Kian’s Rules of Freelancing
Try and hit the ground running.
The customer is not always right. They are, in many cases wrong.
The customer is rarely right. Often they’re very wrong.
The customer is never right. They are always wrong.[i]
There are approximately 9 usable business hours in a day. Any more, and you’ll kill yourself.
Those are 9 business hours. Not necessarily 9 hours coding. Some days, you will do bugger all coding.
That is an average. There may be the occasional “oh shit” race condition which means that there becomes 26 business hours in a day. Remember to balance it out.[ii]
If you’re working less than nine hours a day, make sure the money is still coming into the pot.
As Paul Robinson has observed, GeekUp, open-source projects and community are often “business”. Remember to factor that in. [iii]
Try not to bite off more than you can chew. [iv]
You are a developer, not a designer. If you need designs, hire a designer.
You are a developer, not a network engineer. If you need network support, hire a monkey.
You are a developer, not a 24-hour on-call support service[1]. If you need a 24-hour on-call support service, hire a minion.
You are a developer, not a one-man army of God. You are not going to single-handedly end poverty, restore world peace and produce cool music[2].As such, if the project looks like it needs an army, consider hiring an army.[v]
Footnotes
[1] Unless you’re stupid enough to sign up for that.
[2] Unless you’re Bono.[3]
[3] Or me.
New Footnotes and Annotations
[i] Usually this boils down to “the customer does not know what they want”. The sign of a good freelancer is the ability to beat the client’s real requirements out of them. A stick is a tax-deductible tool.[vi]
[ii] See the past three weeks of my life for a good example of this.
[iii] When you attend these events as a regular “Joe Blogs”, an employee for something-corp, you treat these events as learning experiences, possibly networking, but generally for fun. When attending these events as a freelancer, yes you’re doing all of the above, but you’re keeping an ear/eye open for new opportunities. That takes energy. Factor it in.
[iv] Refer to One Another As I Have Referred You (refer work to others, and hopefully they will refer back to you)
[v] Projects have costs. A business has to spend money. Spend money to make money. Learn. This. Lesson.
[vi] This is not a slight on businesses. Requirements capture is by its very nature hard.
I admit that I have been somewhat absent from community offerings for the past few months. The projects that I am currently working on have been a little hectic, with some appropriate last minute deadlines changes.
But
I’m hoping that July is going to be a free month. Completely free to do with as I please. As such, I am planning on taking it easy, pimping for some new work to start in August and catch up with those community events I managed to miss since Christmas.
So the question to you lot is - where would you like to see me over the next month. I can turn up and talk on a topic, or just turn up and be generally awesome. Tell me where you would like to see me over July, and I’ll try and book it in.
Oh and whilst were here, please take a look at this post by The Hodge. He could do with your support.
Now my new larger easel has finally arrived, I can announce one of my new projects. “Northern Geeks” will be a series of portraits of geeks in the north, showing them in their natural habitat and “at play”. I want to show geeks are people too.
The final images will be put into an exhibition, put online and be made available as a book.
So I need volunteers. If you would like to be part of this project, please send an e-mail to kian@kianryan.co.uk with the subject “Northern Geeks” or comment on this post. Please enclose a small “geek bio”, and what you do for kicks (this can be something tech related or completely different). Sport, gaming, gardening, gerbil farming, anything. I’m looking to shoot and print in July with an aim to exhibition in August/September. If your natural habitat is a company office, please ensure you can gain permission to be photographed there before applying. All volunteers will be given a copy of the book as thanks.
Last night Cat took me to the Geek Girl Dinner in Manchester. What’s a Geek Girl Dinner? Well most tech events have a heavy male ratio and bias. Geek Girl Dinners (GGDs) aim to change that balance by only allowing boys to attend that are invited by the girls as dates. In a non-poly recognising environment, each girl is allowed to invite one boy.
Discussion was varied last night, ranging from female attitudes in the workplace, to what women bring to the workplace, why on earth does it all matter anyway to problems with the education system and nurturing the geek spirit. The evening was kicked off with a talk by Lesley Allger from BAE Systems. Although I thought the conversation was positive, not everyone agrees.
Food was excellent from the “Old Abbey Inn”, paid for in part by BAE. We were all sent home with “breakfast bags” of tea and marmalade, currently being consumed while I’m writing this post.
Many thanks to Gemma Cameron for organising the evening.
(Apologies for the quality of the photos, Cat will be posting better ones later.)
If you do one thing tomorrow make sure it’s that you go to vote. I don’t care who you vote for, that’s your choice, I don’t care if you take the ballot paper home to use as loo paper. What I do care is that people turn out, that they register that they’ve turned up to vote and that if they don’t vote for a candidate it’s an active choice rather than
“Don’t trust any of them, can’t be bothered going to the polling station”
Make it an active choice, show these weasels that you’re not disconnected, that you do care, and if you’re anything like me it’s that you don’t care for any of the current bunch of self-serving w*kers.
Those who have to dip their toes into the life of a designer once every so often understand the importance of typography. One of the hard parts of typography is finding the right typeface that isn’t going to break your piggy bank (or your client’s piggy bank).
” We know how hard it is to find quality freeware that is licensed for commercial work. We’ve done the hard work, hand-selecting these typefaces and presenting them in an easy-to-use format.
It’s a simple directory of excellent, high quality, free fonts. Well done guys and keep up the good work.
“It is a truth universally acknowledged, that an ASP.NET page in possession of a component, must be in want of a form.”
I’ve just come across this sticky little scenario in one of my projects:
ASP.NET components need to be wrapped in a form tag for their post-back magic to happen. As such, the form tag is usually as high level as it can possibly go (usually just inside the body tag). Some mailing list (sorry - mail marketing) companies provide you with a HTML form to integrate into your site so users can subscribe to the site’s mailing list. Sometimes these forms also come with a little chunk of Javascript to perform some page validation before performing the post.
So what we’ve got looks like this:
<script src="somethirdpartyvalidator.js"></script></p>
<form id="Form1" method="post" runat="server">
<form id="MailingForm" method="post" action="somethingremote.pl" onSubmit="validate(this);">
<!-- Insert some form components here -->
<input type="submit" value="Submit" />
</form>
</form>
<p>
And here’s the fun. When you click the submit button, it doesn’t perform the expected behaviour and perform a post to somethingremote.pl. Instead it performs a regular post-back to your site and (most likely) will do diddly squat. The culprit is __doPostBack, injected by ASP.NET at runtime, which hijacks the onSubmit event of the parent form to provide the post-back functionality. Your poor little mailing form doesn’t even get a look in.
The answer is to provide a little roll your own javascript for your own submit functionality. This article demonstrates a version of this technique. My version of the is shown below:
<script language="javascript" src="somethirdpartyvalidator.js"></script></p>
<script language="javascript">
function submitForm() {
var theForm = document.getElementById('signupForm');
if (validateForm(theForm) != false) {
theForm.encoding = 'application/x-www-form-urlencoded';
theForm.action = 'somethingremote.pl';
theForm.submit();
}
}
</script>
<form id="Form1" method="post" runat="server">
<form id="MailingForm">
<!-- Insert some form components here -->
<a href="javascript: submitForm();">Submit;</a>
</form>
</form>
<p>
The variation from James Byrd’s original article comes from which form we submit. In the original, James posts the global form (in our example Form1) and instructs the reader to simply blank out any values they may not want to communicate to the third party. This seems overly permissive to me, especially in a potentially dynamic environment where you may have hundreds of components and as such my version simply selects the target form from the page before passing it through the validator and performing the submit action. The postback event is avoided, the third party only gets the data they need and the world is a happier place.
I’m currently working on a small project working with Microsoft ASP.NET MVC. I admit I’m rather enjoying the experience, it’s nice to get back to proper bare metal GETs and POSTs with non of the fluff of normal ASP.NET getting in the way. Since this is a relatively simple project I’m using Linq to SQL rather than the Entity framework. Whilst putting some boilerplate code together (after following the excellent NerdDinner tutorial) I realised there was a lack of a simple generic repository for common object operations. So I present to you my basic, generic repository:
using System.Data.Linq.Mapping;
using System.Linq;
using System.Linq.Expressions;
using BrandingScience.Models;
using System;</p>
<p>public abstract class Repository<T, C> where T : class where C : System.Data.Linq.DataContext, new()
{
private C db = new C();</p>
<pre><code>// Query Methods
public IQueryable<T> FindAll()
{
return db.GetTable<T>();
}
public T Get(int id)
{
MetaTable mapping = db.Mapping.GetTable(typeof(T));
MetaDataMember pkfield = mapping.RowType.DataMembers.SingleOrDefault(d => d.IsPrimaryKey);
ParameterExpression param = Expression.Parameter(typeof(T), "e");
var p = Expression.Lambda<Func<T, bool>>(
Expression.Equal(Expression.Property(param, pkfield.Name),
Expression.Constant(id)),
new ParameterExpression[] { param });
return db.GetTable<T>().SingleOrDefault(p);
}
// Insert/Delete
public void Add(T t)
{
db.GetTable<T>().InsertOnSubmit(t);
}
public void Delete(T t)
{
db.GetTable<T>().DeleteOnSubmit(t);
}
// Persistence
public void Save()
{
db.SubmitChanges();
}
</code></pre>
<p>}
T is the table class you want to create the repository for, C is the DataContext created by Linq to SQL. Pretty straightforward. A typical implementation looks like this:
public class JobRepository : Repository<Job, MyDataContext>
{
}</p>
<p>public static void Main(string[] args)
{
JobRepository jobRepository = new JobRepository();
List<Job> allJobs = jobRepository.FindAll();</p>
<pre><code>// Return a single item and change the title.
Job job = jobRepository.Get(1);
job.Title = "Mutated Gerkhin Production";
// Create a new item.
Job newJob = new Job();
newJob.Title = "Mutated Gerkhin Anti-Coagulant Production";
jobRepository.Add(newJob);
// Delete an old item.
Job removeJob = jobRepository.Get(2);
Console.WriteLine(removeJob.Title); // Output: Survival of human race.
jobRepository.Delete(removeJob);
// Save all changes to the repository.
jobRepository.Save();
</code></pre>
<p>}
This version currently does not support dependancy injection, which is something I’ll be looking into shortly. But for now, it saves a heck of a lot of time to just get the simple stuff done. I’m surprised MS didn’t actually ship Linq to SQL with something similar.
I’ll make no bones about it, VS08 SP1’s Javascript Intellisense saves me from having to dive into the docs every five seconds. Not having that fingertip intelligence to my hand would probably cost me quite a bit of time each day. However, since I often end up using multiple frameworks in one project, I tend to use the jQuery.noConflict(); to avoid it conflicting with the other frameworks. Unfortunately, the moment you stick var $j = jQuery.noConflict(); into the top of your javascript file, your intellisense will break for the rest of your script. I’ve currently got two methods for handling this:
1 - Create a “preload” file
This is a small script that sits in between loading jQuery and loading your page scripts. All it contains is the following statement:
var $j = jQuery.noConflict();
Save it as preload.js and you can then sandwich this in between loading the jQuery framework and loading the page scripts as so:
Visual studio will have sorted out it’s type resolution for $j meaning that so long as you also have the jQuery .vsdoc file in the same folder as jQuery you get this glorious view:
The pros of this technique are that you can drop in new versions of jQuery at a whim and not have to worry too much about having to update preload.js. Of course the downside is that preload.js then needs to be sent to the client, with all the associated overhead of a get request.
2 - Append noConflict onto jQuery
There are those that will believe that the jQuery file is sanctimonious and should never be tainted by a developer’s touch. As it is I’m already using ASP.NET and cursed for all eternity, so how much worse could it be? So path two is pretty straightforward, open up the jQuery and jQuery.vsdoc files and add var $j = jQuery.noConflict(); to the bottom of the file. Again, this will sort out all the resolution gubbins while you’re working away in your own scripts.
Just remember that if/when you update your original jQuery files to also replace the noConflict statement at the bottom.