Operator precendence is the order in which operators are evaluated within an expression. For example, take this:
var leftStart = 5,
width = 2;
var left = leftStart - width / 2;
Now, what are we actually doing here? Is it:
var left = (leftStart - width) / 2;
var left = leftStart - (width / 2);
The remaining question is – why bother? By being explicit with brackets, you remove any ambiguity, despite having to type a little more. But I’d argue that not understanding precedence means you’re leaving yourself open to bugs, and in more complicated examples the character noise will obscure the meaning of the code you’re writing.
While there’s commonality between browser Date() implementations, there are edge cases where certain browsers fail when others pass. This is particularly frustrating when working with Mobile Safari because its debugging support is limited to say the least. Take this example:
var date = new Date('Sun Oct 10 10:41:43 UTC 2010');
This works just fine for me in Chrome, Safari, and even my current version of the iOS Simulator’s Mobile Safari. However on my iPhone 4 with the iOS 5 beta, this code:
Will simply give “Invalid Date”. Because of Mobile Safari’s poor error reporting for things like this it can be extremely difficult to notice that Date() is the ultimate issue. The solution is to use a fixed implementation of Date – I used Date.parseDate within Sencha Touch, but if you’re not using a framework you could look at DateJS.
There are certain things that should set alarm bells going from the beginning. A client being grumpy about costs before anything’s agreed. Integrating with someone else’s opaque code. Someone non-technical telling you how long it takes to code something. Trust your gut; if something worries you and you can’t tie down the details, listen to the alarm bells.
We just wrote some words on Facebook’s interesting new approach to messaging here:
Go Tripod is the company we formed last year to provide awesome software solutions based on best-of-breed technologies.
In order to resolve this, first follow the Bundler troubleshooting instructions:
Next, if you’re using rvm then it might make sense to delete and recreate your gemset, just in case. However, neither of these actions fixed my problem alone. What I needed to do was look at my Gemfile and make it a bit more sensible to help bundler resolve all of my dependencies. From this:
# common gems here
group :development, :test, :cucumber do
group :test, :cucumber do
group :test do
group :cucumber do
# common gems here
group :development, :test, :cucumber do
group :test, :cucumber do
By using less group combinations, bundler has less work to do and doesn’t get stuck sorting out what gems you want to install.
The second edition of the book written by Shea Frederick, Steve “Cutter” Blades, Nigel White and myself is now available for purchase. Learning Ext JS 3.2 covers version 3.x of the Ext JS library and offers updated content and extra chapters since the first edition of the book. For new Ext JS developers, it’ll give you a great starting point for working with the framework and enable you to create high-quality rich applications.
May 9th 2010, 11:54 am in Personal.
I’ve written a few times in the past about software like SABNZBd for downloading episodic content, and also about using my PS3 to play that content. For the past few months, I’ve been using an old PC with SABNZBd and PS3 Media Server to watch HD content on my TV, and it’s worked a treat. Unfortunately, the PSU on the PC died and that made me begin my search for a yet-better solution.
Having switched to a MacBook Pro full time for my work, after becoming heartily sick of having to fiddle around inside yet another broken PC, I’d hoped to come up with a way of avoiding having to have a “proper” PC as a media center. Commodity PC’s are noisy and unreliable. Something like AppleTV was suggested, but it’s expensive and would need hacking around with to do what I wanted. A Mac Mini would fit the bill, but it’s even more expensive.
A few days ago I stumbled on the WD TV Live from Western Digital. I’d seen media player devices like this before – dedicated hardware to play a variety of media types, but the trouble was that most don’t support additional software on the box and so wouldn’t let me use NZB downloaders like SABNZBd. And indeed, the WD TV Live doesn’t do that either.
Or so I thought. Turns out the firmware for the WD TV Live is GPL – the code for it is open source. Some enterprising coders have taken this and formed custom firmware, and the one I’ve installed is WDLXTV-Live. Out of the box, this gives the WD TV Live an ssh server, a bittorrent client, an NZB downloader, a web server, an FTP server, Python, Perl and PHP, a load of stuff for network sharing, and a bunch of other stuff like customisation of graphics and the interface of the WD TV Live. You can also add in application bundles, a few of which are already provided by the community.
The WD TV Live has two USB ports, so I bought a hard drive caddy, pulled the disk out of my broken PC, and hooked it up to the WD TV Live for 1 terabytes of storage. The media player attaches direct to my 42″ LCD TV, and plays movies, TV shows, music and shows photos, but also now pulls down NZB files automatically on a schedule. It’s tiny, fanless, and looks good next to my PS3 and TV, and it was £95.
What more could I want?
April 22nd 2010, 1:39 pm in Mono, NHibernate.
When trying to use Mono on OSX to run an existing website, I was getting the above error thrown by NHibernate. Thanks to this post by “sta.blockhead” I was able to understand that switching my NHibernate adonet.batch_size configuration to zero will bypass the issue.
I’m a Ruby noobie, I admit it. Coming from a .NET background, Ruby has been a learning experience for sure, but I certainly feel lke I’ve learned something along the way. One aspect of the Rails framework I really like is the relaxed attitude to working with the database – I really rarely have to worry about it.
That said, I’ve been puzzling over the use of inheritance with Active Record. In .NET land and with NHibernate, I’d quite happily have this:
class AbstractUser class AdminUser : AbstractUser class StandardUser : AbstractUser
All the *User subtypes have their own extra properties, and the AbstractUser provides some common ones like email, password, username.
Ruby doesn’t actually provide for abstract classes, so that’s one issue. But another issue is the way in which ActiveRecord deals with inheritance. Only single table inheritance is supported via the user of a discriminator column. My issue with this is that there’s no good way to support extra properties on a subclass – the properties would have to be added to the Users table and therefore without some trickery would be available to all User subtypes.
One possible solution for this is as follows:
class AbstractUser < ActiveRecord::Base end class AdminUser < AbstractUser has_one :admin_details end
In this case, we have another model - and therefore another table - which provides the AdminUser's extra properties. This can then be used as follows:
admin = AdminUser.new admin.admin_details.direct_line = '+44 567 7890'
This works fine, the values are off in a separate table and everything's separated out as I'd like. But the syntax is clunky. I don't really want to have to do admin.admin_details.direct_line, I want to do admin.direct_line. So I wrote a little extra method to do this:
class AdminUser < AbstractUser incorporates :admin_details end
All this does is set up a has_one as normal, but then provide extra methods for getting and setting all of the attributes of admin_details, meaning that admin.direct_line will work as expected. The code for incorporates has_one is up on github now - it's the minimum that was required to get this to work, so please feel free to fork it. I do wonder if I'm missing something that's already built into Rails, but if I am, it's damn hard to find.
This approach makes me pretty happy overall - in the scenario I've got right now, I never actually need a base User, which is why I'm referring to it as AbstractUser, and it would really be better if that could never be instantiated. But it's a minor niggle, and the whole setup plays well with Rails' polymorphic routing and suchlike, and works with Authlogic too. I can already see some improvements, so I hope someone forks the gist and I can learn something from Rubyists!
September 24th 2009, 9:57 am in IIS, OSX, virtualbox, VMWare Fusion.
A longwinded title, but this is mostly as a note for me. Assuming your Mac’s IP address is 192.168.1.101:
- You need matching users with matching passwords on both Windows and OSX. So, your main user on OSX is u:colin/p:password. You need a user on Windows u:colin/p:password. Casing is important!
- Enable SMB on OSX from File Sharing
- Share the OSX folder you want to serve up (let’s say it’s named “mysite”)
- Create a new site in IIS with the physical path as \\192.168.0.101\mysite
The first point is key, as is using the UNC path in the last point, rather than a mapped drive. I used this Stack Overflow question to get this up and running.
Update: I just tried to run some unit tests via the Resharper test runner and received a security exception. The following fixed the issue:
caspol -m -ag 1 -url “file://\\192.168.0.101\mysite\*” FullTrust -exclusive on
Update 2: In a new VMWare VM, I came across two additional problems. Using ” around the URL caused caspol to throw an error, and having spaces in the URL doesn’t work – replace them with %20.
Update 3: In some cases, such as writing across the UNC share to the virtual directory your site is running in, you may need to set up Impersonation in the web.config with your matching user. You may additionally need to set the AppPool identity to that shared user. Note that I now have this system working in VMWare Fusion.