Wednesday, July 21, 2010

Powershell Scripting Book - first thoughts


As part of my endeavour to learn a new language this year (and hopefully every year), I decided to improve my .NET and general Windows development workflow with Powershell. It's not only a great scripting tool, but a complete language, and actually quite handy as a REPL too, when working with .NET types.

In order to maximize my learning time, I turned to Manning and bought the 'early access program' book for Windows Powershell In Action. I am a huge fan of the early access program, and have bought more than 10 books now.. Again I wasn't disappointed, as it is a good entry level book to the syntax and idioms that make Powershell so, well.. powerful.

Once I had mastered the syntax, using the canned examples within the book, I decided to take the plunge and write a few 'real world' scripts. It didn't take me too long until I had started incorporating Powershell into my everyday development cycle.

My 'new work' script looks something like this:

param
(
[string]$name = $(throw "a branch name is required")
)

. .\Scripts\Utilities.ps1

Stop-
Servers

Invoke-Expression .\Create-Branch.ps1 "BUG_$name"
Invoke-Expression .\Setup-Config.ps1
Invoke-Expression .\Build-Source.ps1
Invoke-Expression .\Build-Database.ps1

Start-Servers

The whole process automates a lot of the drudgery of creating a branch, switching to it, patching the many config files (via XPath), doing a full build, rebuilding the database, etc. Fantastic!

What is more surprising is that these processes were done each and every time by each developer manually until I suggested we script them.. What's more, each had their own special way to achieve the end result, which made things difficult when we integrate branches and get a consistent working environment.

I am still trialling these scripts, and the many others that I have written to manage random files and processes on the fly, however I am having lots of fun and have even managed to remove some drudgery from a home-centric file operation ritual I do all the time.. This will have to wait for another post however..

HINT: I'm downloading and transferring podcasts to my phone.. (I use RSS via google reader and DownThemAll currently - it's very manual..)

Thursday, March 25, 2010

Media Center Goes Win 7 - Finally

It's hard to believe that I first built my media center back in 2007. When I initially set it up, my plan was to use Windows XP and run Media Portal. After a few abortive attempts and getting everything running with my hardware, I gave up and moved to Media Center 2005 (XP). After further configuration woes (due to dodgy hardware and/or drivers), it has worked basically flawlessly since.

I was happy with this configuration, and it remained unchanged, until I bought Windows Vista.. MY tuner cards didn't work any more, and the interface ran too slow for my wife to accept. Needless to say, that copy of Vista still sits in a box somewhere, never to see the light of day again.

With the recent release of Windows 7, I knew the time was right to try again - I knew there were lots of good features for MC, and I was keen - only problem was that my hardward (tuner cards) *still* didn't work. This time though, I was feeling a bit more keen on spending some money, so I discarded my tuner card (actually I gave it to my brother-n-law, who has made it work in Win 7!), and I bought two dual-tuner cards and a 1TB hard drive for TV only.

These cards are Hauppauge 2200 and they 'just worked'. Now the only problem was that the interface was a bit sluggish on a busy screen (e.g. Recorded TV - we have a lot of recorded shows).

I looked at everything obvious (or so I thought), and eventually I realised, much to my own embarrassment, that the HTPC only had 1GB of ram! I don't really recall way back there in 2007, but 1GB was probably not too bad.. As my wife pointed out, even her netbook has more ram. Too true.

A quick trip to MSY (great prices, worst web site ever) and 4 GB, for a lousy $105 and now the Win7 Media Center is looking awesome.

One last thing - having visited my place several times and viewed the beast that is my HTPC, my stepfather has decided he wanted one too - despite my encouragement to get a TiVo. I beg you.. But no.. He bought one anyway, and a big screen TV, and a nice new stereo. It will be a good setup, when he gets it working.. :-)

Given that he's not technical, I've committed a few hours to the cause so far, but as of last night, we are not quite there yet.. I think we're close though, with only the channels tuning to be done. Somewhat poorly, I think, the supplier (in a different city), left the channels configured when he shipped it - thus, when we booted it, it listed all the 'correct' channels, but no guide listings, and no reception. It took me a while to realise that these were for Melbourne (or perhaps Brisbane?), but the bub had had enough so we went home with the problem unresolved..

Ahh.. Why didn't he just buy TiVo?

EDIT: After a little tweaking (faulty tuner, wrong city config) it is all working a treat, and the supplier was good about replacing the faulty tuner too

Wednesday, February 17, 2010

Open Source RTS Engine


I had a brief window of opportunity to play a game a few weeks ago - the first I've played on my computer for a few years. I used to be a hard-core real time strategy (RTS) player, but with work, house, wife and child, their is never enough time!

The game itself is called Spring, and is an open source RTS engine. The implementation is inspired from Total Annihilation (1997) and more recently, from it's modern equivalent Supreme Commander (2007). The basic idea is a classic RTS paradigm, with base building, resource collecting and domination being the primary methods of success.

The feature which I enjoy the most is the use of metal as salvageable resource from the remnants of the battle field. A favourite strategy is to allow the enemy near to your base to allow easy access when picking over the carcasses of the dead (it's only robots, no blood!!).

Also, I really appreciated (in the original TA), that the command system is entirely queued. Simply hold down shift, and initiate a sequence of commands. It is essentially fire-n-forget. Back in 97, this concept was revolutionary.. It is still awesome today.

What I particularly like - besides being open source - is that the game play is very similar to my recollections of TA, but with better graphics and sound.

The game is separated into the engine, modifications (mods), and maps, such that there are various mods available, some ostensibly require a licence to the original TA (it uses its units model and rule data), and others are complete fabrications of new rules, units, AIs, and scenarios. There are both open source and paid mods, such as a futuristic (Sci-Fi), WW2, and Star Wars themed mods.

I have been playing the Balanced Annihilation (BA) mod only at this stage, since it has the familiar units and rules of the original Total Annihilation game.

After approx. 20 hours of gaming, I can now give a fair review of the engine, the AIs, the mod, and the lobby:

The lobby is the weakest link in this suite, although it does work, I have found it crashes, has a lot of 'nag' dialogs when failing to connect to a server (even when playing single player), and in general is a bit dull (it appears to be a standard windows form application, nothing special..). It is functional, and provides some good mechanisms for downloading content as required.

The engine is very good, but requires a better graphics card than I have to fully appreciate the feature set it offers. I found the game is responsive with medium unit volumes, but since I prefer high response times to great graphics, I generally played with these settings on low.

Since I needed a lot of practice before I could commit to the multi-player game, I spent all my time with the bundled AIs. Some are definitely better than others, E323AI and RAI I beleive the ones I competed against. One is easy ot beat, as soon as the game's mechanics are mastered, but the other one (I think it was E323AI), is a difficult one to handle, especially early game! I suspect that these AI processes are reducing the performance of the game overall, but still performed admirably.

The BA mod is a faithful recreation of the game I remember, and has been so good that I am yet to entertain the thought of loading up any other mods at this time! I will do this at some time though - Time permitting, of course!

For some screenshots, see here.

Well done to the guys over at Spring RTS, this is a worthwhile project, and I hope to get some time in the future to peruse the source for my self.

Wednesday, October 21, 2009

SQL Formatter Released!

Although, not finished by any stretch, I have released my first draft of the Laan.Sql.Formatter to 'production'.

I have provided 3 deliverables - each providing access to SQL Formatting for different purposes:
  • Sql Server Management Studio 2008 (SSMS) Plugin
  • Ad-hoc Sql Formatter Web Page
  • Sql Formatter Log4Net Appender (for use with NHibernate)
Further, the SSMS plugin provides a second feature - code template expansions. I've 'borrowed' the idea shamelessly from DevExpress' CodeRush (awesome tool), but without all the trappings. In my version, you can only expand a template that you know and remember (no visual clues - sorry, this *may* come some day), Also, the template list can't be edited/added/removed (yet).

For more information, and to obtain an installer for the plugin, go to the project site, or directly to the download page. There is also a download for the NHibernate Appender, with some simple documentation on it's use still to come. To play with the formatter, you can go to my web site as per my last blog entry.

If you find an issue, or have a feature request, you can add it here - but don't bother to log an issue regarding missing formatting options - I know I need to add some, eventually, but my plan is to get the core functionality done first.

Also, I would appreciate it if someone could provide a code review of my work so far. There is no doubt some of it needs more work, especially within the formatter assembly.. All code is available via svn hosted on google code, so it's easy to get access to a read only file set, or on the download page on the above link. If you are interested, let me know, or just send me an email of your review or blog it.

I hope you find these tools useful, I know I have..



Thursday, May 28, 2009

Laan SQL Formatter (alpha) is online!

Finally, after much wailing and nashing of teeth, I've delivered my first draft (alpha) of my SQL code formatter. There's not much too it, simply enter (or copy) your SQL into the top, hit convert, and the bottom will (should!) supply the formatted result!

code.laanfamily.com


Also, I will soon be releasing an NHibernate Appender which raps this functionality into a FormattedSqlFileAppender, once I get the appender subclassing working correctly.

Currently, the formatter (and even the parser, behind the scenes) is quite limited. It only supports SELECT statements, without UNION and SELECT..INTO modifiers. I believe there is full expression syntax parsing, but some aspects of expressions are still not formatted - e.g., bracketed sub expressions.

I will keep modifying it over time, as time permits (baby is now 6 weeks away!), but hopefully I can quickly implement INSERT, UPDATE and DELETE, CREATE TABLE and CREATE VIEW statements fairly rapidly. Then I'll work towards doing batched SQL instead of single statements, which will open the door for stored procedures.


Stay tuned!

P.S. Interested in the code? check it: http://code.google.com/p/sqlformat/

Wednesday, September 03, 2008

NHibernate SQL Logger

As a traditional SQL 'backend' developer, I've always relied on SQL Profiler to let me know what is happening in the back end at any given point, but now that I'm using NHibernate for our persistence layer, I've found that the SQL that is generated is not very readable. If you've used NHibernate you'll know what I mean!

Besides the aliased fields, I don't like the fact that the entire statement is packed onto one line, and is using the sp_exec statement for parameter passing - Not very readable.

In order to remedy this, I configured an appender within log4net that allows the SQL to be pushed to its own file, with the following config:

    <logger name="NHibernate.SQL">
      <appender-ref ref="nh"/>
      <level value="ALL" />
    </logger>


where "nh" is just a standard Log4Net file appender. This works, but still means I have to dissect the SQL and reformat it as I go.

Of course, this is not ideal, so I have decided to write a small log4net appender that formats this output. The only problem is that I will need to write an SQL formatter! Not trivial.





In the interim, I have written a rough 'formatter' which simply uses find and replace to get the SQL slightly readable.  It places each field on its own line, and creates distinct blocks for each join.



SELECT
    FieldA,
    FieldB,
    FieldC
FROM dbo.Table1 AS T1
JOIN dbo.Table2 AS T2
  ON T1.Field1 = T2.Field1
  
JOIN dbo.Table3 AS T3
  ON T2.Field2 = T3.Field2
  
WHERE T3.Field4 = 1
  AND T2.FieldA <> 0


It’s not perfect, and will place new lines in regardless of whether they are necessary, but it does substitute parameters so generally it does the job!



If you happen to read this and think this sounds like something you *must* have, let me know.. It’s quite easy to use, simply reference the assembly, and place this into the log4net config:



    <appender name="sqlFormatter" type="NHibernate.Appender.NHibernateAppender,NHibernate.Appender">
      <param name="FileName" value="C:\Logs\MatrixSQL.log"/>
    </appender>


and then reference it accordingly within the NHibernate.SQL logging level:



    <logger name="NHibernate.SQL">
      <appender-ref ref="sqlFormatter"/>
      <level value="ALL" />
    </logger>


The next step will be to build a reasonable SQL parser, so that I can create a syntax tree of the statements in order to present them neatly. 



To get this happening I will need a tokeniser (lexer), a grammar parser, and a formatter.  Sounds like an interesting project. I’ll make this project available on GoogleCode at some point, assuming that I’m making progress.

Sunday, April 29, 2007

Chào ban! - Greetings from North Vietnam

We lost our luggage in Hanoi. 3 trips to the airport (50 mins away from Hanoi) and 24 hours later, we're ready to start out Vietnam holiday!...

Vietnam is so under-developed and filthy but fantastically cultural!! Life here is like nothing of what we're used to. Communication is really bad here - no one speaks English!! There are people hawking their wares of all sorts all over the streets... our money means so much to them. Amazingly, there are no beggars to be seen! Stray cats and dogs everywhere. No fast food chains. People eat on road side stalls and squat on little stools on the footpaths. Ladies in traditional Ao Dai (Vietnamese get ups) walking the streets with rice paddy cone shaped hats and carrying poles on their shoulders with baskets hanging off them storing fruit or snacks to sell, or balancing baskets of goods on top of their heads in the middle of the city. And the traffic!! Sheez -We have never seen so many motorbikes in all our life!! It's just like on telly! Hardly any traffic lights, no one obeys road rules, everyone drives on the wrong side of the road, playing chicken is standard play and the adrenelin pumps each time you attempt to cross the road! You'll definitely find the famous 25c bowls of noodles here, but they are Lin size, not Ben size! Meals at regular restaurants and cafes are about $1-2, beers are ridiculously cheap between 50c and $1. The only place in the world where cans of iced tea or coke are more expensive than beer. Alcohol in general is dirt cheap. Ben's drink of the trip is Long Island Iced Tea. At $5 a pop, you can just imagine...

Hanoi has such a French influence. The architecture is pretty and lots of French words everywhere. It was FREEZING!! No one told us we had to bring jackets!! It averaged 15-18 degrees during our stay! We had to buy parkas and beanies from the locals just to keep warm! I was chuffed at my $5 purchase that certainly did it's job at keeping me cozy! Ben's parka purchase was not so easy - try looking for a jacket to fit a 6'3" anglo built male in a country where the average male is my height and half Ben's build! Nevertheless, we managed to find a Nike rip-off for $25 (+pants) which was almost too warm for Ben's liking!

Hoi An is a gorgeous town stuck in old school. Roads in the old town are not bitumen and the shops are all like you see in an old Chinese movie - lots of wood and lanterns. We got lots of cool stuff tailored for really cheap - I got a long woolly duffle coat, and some beautiful traditional chinese silk brocade cheongsams and outfits made - The whole lot for under $100! I also took some dresses for them to copy and they did a fantastic job! Ben got 18 shirts, 3 pants and 3 pairs of shoes made (mind you, there ain't no way we were going to find size 13 shoes off the shelf for Mr Big Foot over here). We are very impressed by the workmanship of the tailors - much better than our Thai experience!! Only problem now with our limited wardrobe space, is that we're not sure where we're going to keep the clothes at home! Looks like we're going to have to buy a bigger house! Tomorrow we're off to My Son to check our the remains of the old Champa Kingdom

Everyone keeps asking us if we're married or here on our honeymoon! If I had a dollar for every time I was asked if I am Vietnamese, I'd be rich!! Apparently I look Vietnamese to the locals?? - or they're just trying to get me to buy something...