You are currently browsing kievia’s articles.
I was able to attend DDD South West (www.dddsouthwest.com) over the weekend held in Bristol. The conference is a free one day event open to all but mainly focusing on elements available on the .NET platform. It’s a great way of being able to hear some excellent speakers talk on areas that they are passionate about and who you would not normally be able to see.
Sessions that I attended included:
- .NET Collections Deep Dive by Gary Short (http://garyshortblog.wordpress.com/)
- No More Passwords by Jimmy Skowronski (http://jimmylarkin.net)
- Performance and Scalability, the Stack Exchange Way by Marc Gravell(http://marcgravell.blogspot.co.uk/)
———————————————————————————————-
.Net Collections Deep Dive
A session convincing us that there is more to .NET collections than just lists.
Lists:
- AddRange is better than Add inside a loop as it cuts down on the number of Array.Copys needed to be called when adding new items and expanding the underlying array (this really comes into effect when adding more that 10000 elements to a list).Alternatively you can set the capacity of the list when constructing to reduce this further
- Using a list initiator and specifying the elements within the list eg new list {item1, item2} is the same as calling Add multiple times
- List.Remove performs an IndexOf before calling List.RemoveAt so if you know where in the list your item is just call RemoveAt initially.
- List.Sort uses QuickSort as it’s underlying sort algorithm. This is the fastest sort algorithm for general purpose sorting as it is (nlogn) for best and average case but (n to the power of n) for worst case. What’s the worst case? An already sorted list – better to call List.Randomise before calling sort to remove this problem.
- List disadvantages: Add, Insert, Remove all O(n) operations
Linked List
- Double linked so that each element is linked to the element before and after it
- Add, Insert, Remove all O(1) operations however O(n) on lookups
Dictionary
- Performance depends on the result of Key.GetHashCode. If you are using your own objects for the key you need to implement this method yourself. Also need to override Equals method to prevent hashcode collision as every key in a dictionary must be unique.
Lookup
- Keys do not have to be unique
- Can be created using lists of tuples and converted to lookups
Collection Version Numbers
Every regular collection has a version number, this is the element that prevents you from iterating over a collection that you are changing. This traditionally causes problems in multi threaded environments due to thread locking and updating. Concurrent Collections have been created to solve this.
Concurrent Collections
- New collections in .NET 4.0
- Implements IProducerConsumerCollections which provides the methods TryAdd and TryTake
- TryAdd: attempts to add item to collection and returns boolean result
- TryTake: attempts to remove item from collection and returns item
- Blocking collections: uses Add and Take. TryAdd and TryTake also available with timeouts
Summary
- List: good general purpose collection. Construct to size if possible, prefer AddRange to Add. Be aware of issues with QuickSort (Google QuickSort killers for scernios)
- LinkedList: fast insert/remove
- Dictionary: fast lookup
- Lookup: multi key values
- Concurrent Collections: thread safety
————————————————————————————————-
No More Passwords – or how to use OAuth
Most public access websites that you come across that want you to interact with them all seem to have some sort of account creation area. While it’s probably fine to have a separate account on Google and Amazon it gets really tiresome when you are trying to download a software demo or take part in a forum. Especially when you consider the amount of passwords that you have to remember and the amount of media stories when hackers manage to get lists of account details from insecure sites.
Fortunately OAuth presents an opportunity to hold an account with a provider eg OpenId, Facebook, Twitter, Google, LiveId, and then use those credentials across multiple websites to bring your existing account details with you.
To incorporate this into your own sites .NET provides a series of libraries under WebMatrix.Security that allows you to add providers with only a few lines of code. LiveId, Facebook, Twitter and YahooOpenId all come out of the box but Google can be easily added.
The steps involved are to register your site with the individual provider who will give you a token that you can add to your global.asax page and then the call on your site to perform the login is as simple as OAuthWebSecurity.RequestAuthentication(provider, postbackUrl).
One of the items of data that comes down with the request is a unique id representing the user that can then be stored in the application database allowing for persistence of settings/data etc. For our public facing customers there should no longer be a need to roll our own account management system.
Jimmy has provided a demo of how this can be achieved and as his presentation was a website you will be able to get the full notes at http://jimmylarkin.net/post/2012/05/27/DDD-South-West-OAuth-Session.aspx
————————————————————————————————-
Performance and Scalability, the Stack Exchange Way
Marc started out by explaining that the traditional answer to performance issues of throw another server at it doesn’t work for websites for the vast majority of the time- highlighted by StackOverflow’s own experiences where they serve up seven million page views a month and their servers are only running at 10% CPU capacity.
He also noted that IIS profiling doesn’t always show where the issues lie and for that you need something reporting within the code. This is how MiniProfiler was born- an open source profiler for MVC and ASP.NET websites that allows you to tag regions of code and report on the timings within them. It can even go to the database level and report on the SQL that was actually called- handy for Entity Framework and Linq statements.
It’s also lightweight so unlike other profilers it can be left to run in a production environment and only enabled when needed. The website effectively shows its usage so check out http://miniprofiler.com/ for more details.
The second tool that Marc showed was Dapper (http://code.google.com/p/dapper-dot-net/) which is a lightweight mapping tool that is very effective for sites with large reads. This was created when the StackOverflow team noticed that some Entity Framework calls took 400ms to run instead of the standard 4ms and the issue turned out to be the mapping process between SQL results and custom objects within code.
I believe that both of these tools would provide benefits both to new and existing projects within and should be investigated further.
————————————————————————————————-
Presenters at DDD events are normally very good at making their presentation content available on their blogs so it would be worth checking out the agenda at http://www.dddsouthwest.com/Agenda/tabid/55/Default.aspx and looking up any of the speakers whose sessions catch your interest.
If any of these has captured your interest in attending DDD events, the next one that I know of is DDD Reading on Sat 1st Sept though DDD North is about to announce it’s call for speakers. Keep an eye on the official DDD site at http://developerdeveloperdeveloper.com for more details.
Ingredients
- 1 avocado
- 1/2 lime (juice only)
- few sprigs coriander
- fresh chilli (pretty mild)
- pinch salt and pepper
- 1 deseeded tomato (finely chopped)
- 1/2 small red onion
Method
Add onion, coriander, chilli to either a food processor or pestle and mortar. Grind to rough consistency.
Add flesh of avocado and mix well. Add lime juice, salt and pepper to taste.
Mix to smooth consistency and serve immediately. Works well with chilli and tortilla chips
Ingredients (makes 3 litres)
- 4 peppers (oven roast first for added flavour)
- 3 cartons chopped tomatoes
- 2 onions
- 1 litre of vegetable stock
- 3- 4 garlic cloves
- chilli to taste (2 birds eye + good pinch of chilli flakes works well)
- basil, oregano, to taste (I love loads)
- paprika
Method
- Add onions, peppers to large pot and simmer (use stock as extra liquid when needed)
- add garlic, chilli to pot
- when peppers getting soft add tomatoes
- bring to boil, reduce to simmer and add herbs and spices
- simmer for about 40 mins
- blend to smooth consistency
Warning: The blending will increase the spice level of the soup- don’t rely on the stock for heat indication
Ingredients
1 good knob fresh root ginger, peeled and roughly chopped
1-2 red chillies, seeds removed (optional), roughly chopped
1-2 stalks lemongrass, tough outer layers removed, roughly chopped
2-3 garlic cloves, peeled
1 handful fresh coriander, a few sprigs reserved and chopped
a glug or two vegetable oil
1 tbsp coriander seeds
1-2 pinches ground turmeric
small jug vegetable stock
a couple of handfuls rice noodles
1 x 400ml/14fl oz can coconut milk
1 large handful raw peeled tiger prawns (the shells and heads can be reserved for making stock in another recipe)
a few splashes Thai fish sauce, to taste
Method
Blend the ginger, chilli, lemongrass, garlic and coriander in a food processor until quite finely chopped, adding a little vegetable oil if the paste is too dry.
Add the paste to a large shallow pan and cook for a few minutes to release the aromas, stirring frequently. Roughly crush some coriander seeds with a pestle and mortar and add to the paste with a pinch or two of turmeric and the vegetable stock and simmer for a few minutes.
Meanwhile, pour some boiling water over the rice noodles in a bowl and let them sit until they have softened, about 4-5 minutes, then drain and set aside.
To soften the heat of the sauce, add the coconut milk to the pan and bring back to the boil. Reduce the heat and simmer for a few minutes while you devein the prawns by cutting along the back of the prawn with a small sharp knife and removing the black ‘thread’ using the point of the knife. Add the prawns to the pan and cook for 2-3 minutes, or until pink and tender, finishing off with splashes of Thai fish sauce, to taste, and more chopped fresh coriander, to your taste.
To serve, divide the drained noodles between two bowls and ladle over the aromatic soup with the prawns and serve straightaway.
Chicken, or mushrooms are a great alternative to the prawns.
This recipe takes my Tomato and Pepper soup and kicks it up a gear. Not sure if it would have worked at the beginning but it was so yummy.
Ingredients
- 1 pack of cooking bacon (roughly 200-300g)
- 2 cartons of sieved tomatoes
- 2 tins mixed beans
- 3 peppers
- 2 red onions
- 1 stock cube (made up with 500ml water)
- To Taste (I use lots): Basil, Oregano, Marjoram, Garlic, Chilli, Pepper, Paprika
Method
- Cook off the bacon and set aside
- To a couple of tablespoons of olive oil add the peppers and onions.
- Allow to soften and add the veg stock
- Add the garlic, chilli and pepper
- Cook down and add the tomatoes
- Cook for about 20 mins and add the beans
- Add the bacon to the pot
- Add the basil, oregano and marjoram
- Cook until you can’t wait any longer and tuck in.
We were trying to figure out a way of having a dynamically encoded database name in our sql queries for a series of reports working off two databases. We needed to have the second database on a different server and we wanted to replicate this on our development environment as well as making deployment easier.
After spending a while looking into dynamic sql queries (not a great idea) and report parameters I decided to have another look at linked servers.
Linked servers are a means in SQL Server (probably exist in other db worlds- haven’t researched) of connecting two servers so that you can access database objects from one server within queries hosted in another.
To set them up:
- Go to “Server Objects” of the database server where the linked server will be added and right click on “Linked Servers”. Select “Add New Linked Server”.
- In the “General” tab, add a name for the new linked server in the “Linked Server” field.
- Select “Other data source”and for “Provider” select “Microsoft OLE DB for SQL Server”
- For “Product Name” type in “SQLOLEDB”
- In the “Data Source” field, enter the IP address of the server to be linked (this can be local)
- “Catalog” is the name of the database on the linked server and is optional (db2 in my case)
- Go to the “Security” tab and select “Be made using this security context”. Type in the remote login and credentials. Naturally set this to be a user with only the necessary permissions and not all.
Credit to http://www.jensbits.com/2010/11/10/create-linked-server-sql-server-2008/ on the creation of linked servers
Where this becomes powerful is that you can set the datasource to be the local machine name or ip so in effect you can link a server to itself. This works brilliantly for development as we can set our sql query using the linked server name and have it configured to multiple environments without touching the code.
To use a linked server in code you prefix the tablename with the name of the linked server so
select * from database.dbo.table becomes
select * from linkedservername.database.dbo.table
This works out to be quite a tidy implementation. Hope it helps someone else out there.
Mencap: Working Together for Change Conference – Friday 23rd March
I’ve been to many conferences, both youth work based and IT, and I’ve yet to sense the buzz on entering a room as I did today coming into the registration hall of the Mencap conference.
Mencap put a lot of work into welcoming people into the conference, from the front door right up to the conference hall itself. The room was well laid out with exhibitors around the outside edges of the main room and round tables for delegates to sit and discuss the points raised over the course of the day.
Technology was in evidence yet not overpowering so- I was delighted to see that Twitter was actively encouraged with the tag #wt4c set aside (lots of relevant comments added throughout the day) and people on hand to explain technology to new converts or people just wanting to have a go.
The conference opened with several big names introducing people to the conference including Paul Clark (UTV presenter) who was to be our conference chair for the day as well as Edwin Poots (Minister for Health and Social Services), with Mencap NI well represented by Maureen Piggot (Mencap NI Director), Brian Ambrose and Annette Crawford (Mencap NI Committee Co-chairs).
The conference then turned to three keynote speakers who discussed their chosen subject before the floor turned to a roundtable discussion to allow the delegates to speak their mind before the next speaker took their turn. I thought that this was a brilliant way to allow everyone to feed their thoughts on the subject matter to the organisers without going into a drawn out Q&A session that would only allow a few to speak.
The first speaker was Dr Cliona Cummings who spoke about educating people on environmental factors as early in a child’s life as possible- we need to educate people before the child has even started to grow in the womb and to carry the messages on throughout the child’s life. Early intervention really is key. The picture she showed of a brain scan of a child aged three who had suffered extreme neglect compared to a ‘normal’ child will stay with me for a long time
The second speaker was Gerry Conway speaking on supporting and strengthen families. He introduced the new family support framework that is being put in place to talk and support families at a local level to build up to trust level thinking. One of the members in my discussion group rightly raised the point of rural planning and provision and the danger that if everyone is talking the signal to noise ratio might be too low to actually benefit anyone. Another point was that of money following targets rather than the child being at the centre of any provision.
The final speaker was Dr Noel Purdy who spoke on teaching the teachers of tomorrow at Stranmillis and that every trainee teacher passing through the college is now taught about Special Education Needs and how to support children. He also highlighted an exercise carried out in Australia were parents of children with SENs came into the teaching colleges and spoke to students to explain exactly what the needs and difficulties actually are. He is wanting to speak to any parents here who would like to do the same. It’s all about teachers and parents working together and keeping communication lines open – something that can only get harder as teacher workloads continue to increase.
After lunch (food was excellent) the interactive theme of the conference continued with a panel session that was opened to the floor for questions. The theme of the discussion quickly became the provision for speech and language theory which I discovered wasn’t seen as a basic educational right of the child. There is also some dispute over where provision lies (either with health or education boards) and that there is no legal requirement for a replacement therapist to be assigned if a therapist leaves their post. The quote of the day for the floor came from John, a Mencap trustee, when he said that one year loss of speech therapy was actually like losing four years given the amount of progress and learning lost.
The conference then broke into workshops and I ended up in the session entitled Planning for my Future. This covered two topics: personal relationships and education transition.
The section on personal relationships was covered by two parents from Mencap Wales whose children had fallen in love and discussed the problems that they faced- mainly from other people, and the discussions that needed to happen with both young people to ensure that they were aware of everything that a serious relationship entails. I wish the couple the best of luck for the future and can see wedding bells on the horizon.
The second part of the workshop was taken by the North West Regional College and explained the partnership that they had put in place with Mencap to support young people with learning disabilities into further education and into work placements. Since I have quite a few parents going through this at the moment I was delighted to hear that there are transition officers available to guide families through this and that both the schools and Mencap can signpost parents to get the help they need.
After the workshop it was back to the main room for a performance by the very talented Something Special, a musical group from the North West who performed Over the Rainbow to a standing ovation.
The day’s conference was then reviewed by Maureen who covered a few highlights of the day. One of the most impressive figures was that the twitter feed had reached approximately 43,000 people worldwide- pretty good going for a conference in Northern Ireland.
Jim Glover (National Mencap Chairman) then drew the conference to close thanking presenters, attendees and organisers for such a great day. He is visiting both days of the conference to find out what Mencap NI is like on the ground from the people that make up the various organisations.
There were over 200 people attending today’s conference and the day absolutely flew by in a mixture of brilliant speakers and discussions. I’m really looking forward to tomorrow’s session (190 registered) as it has a community focus and I feel that it will be another excellent day.
Site is fixed and registration is now open ![]()
http://developerdeveloperdeveloper.com/dddie11/Register.aspx
Well the waiting is over and I can announce the schedule for DDD Belfast happening on 1st October in the University of Ulster’s Belfast campus.
Schedule as follows:
| Time | Track 1 | Track 2 | Track 3 |
| 8:30-9:00 | Registration | Registration | Registration |
| 9:00-9:30 | Housekeeping | Housekeeping | Housekeeping |
| 9:30-10:30 | Taking REST beyond the pretty URL
Jacob Reimers |
Code Contracts – Design by Contract for Mainstream .NET
Ashic Mahtab |
refORM – Death to ORMs in .NET
James Hughes |
| 10:30-10:45 | Break | Break | Break |
| 10:45-11:45 | Internationalizing ASP.NET MVC 3
Guy Smith-Ferrier |
HTML5 for developers
Mark Allan |
Behavioural Driven Development (BDD) with F#
Phillip Trelford |
| 11:45-12:00 | Break | Break | Break |
| 12:00-1:00 | CoffeeScript The Awesome
James Hughes |
Parallelisation: Doing stuff at the same time in .NET 4.0
Colin Mackay |
Asynchronous programming with F# and C#
Tomas Petricek |
| 1:00-2:30 | Lunch | Lunch | Lunch |
| 2:30-3:30 | CQRS – Bringing Elegance to “Normal” Applications
Ashic Mahtab |
Aha! Unit Testing Richard Dalton | Defensive Programming 101
Niall Merrigan |
| 3:30-3:45 | Break | Break | Break |
| 3:45-4:45 | (clojure (you get used to the parenthesis (eventually)))
Rob Lally |
TBC | Developing F# Mobile Applications with WebSharper
Adam Granicz |
| 4:45-5:00 | Finish and Prizes | Finish and Prizes | Finish and Prizes |
Registration opening really soon
Twitter hash: #dddBelfast
To find all the user tables that contain a particular column name run the following command on the relevant database:
SELECT name FROM sysobjects WHERE xtype='U' and id IN( SELECT id FROM syscolumns
WHERE name like '%COLUMN NAME%' )
