Posterous theme by Cory Watilo

Some interesting issues building an HTML5 offline app

I've been building an app which is essentially a downloadable brochure. Specifically it's a movie brochure but the key point is that it's a brochure containing a 10-20 images and 10-20 snippets of text (up to 1K). The app is part of an existing web application that already features login, with fine-grained access control. Brochures are customizable per-user – i.e. each user sees a different (or potentially) different brochure. When online the app needs to check for updates to the brochure, and to download them. It is critical that the app carries on working – i.e. that the brochure be readable – when offline.

The app's target is the iPad, although it would be nice if it also worked on other platforms.

I'm using the word “app” in its broader sense, rather than just meaning “iOS app, downloadable from the App store”.

Read the rest of this post »

and my dislike of Wordpress grows...

...having naively managed to cause the problem described in this post:
http://www.blakeimeson.com/accidentally-changed-wordpress-site-address/
on somebody else's website, without admin/ftp/any-other-kind-of access.
What sort of web interface gives you the ability to (permanently) lock
yourself out (with no "WARNING!" or "are you sure?")?
Very cross. As is "somebody else". Not unreasonably.

(Wordpress.com, I can live with; it has been semi-sanitised for
humans. Installable Wordpress is [clearly] another matter...)

git: pulling and pushing branches

Note for future reference:

git push origin branchname
Pushes the local branch "branchname" to the remote branch "branchname"
This makes sense, and I can remember it.

git pull origin branchname
Pulls the branch named "branchname" and merges it into the currently
checked-out branch.
That's not what I want at all! Unless I say otherwise, I want it to
merge with the /local/ branch named "branchname".

git reset, temporarily reverting to previous commit

Just did something really dumb, and typed:

git push heroku master

When what I really meant was:

git push origin master
("origin", in my case, is a github repo)

Meaning that I mistakenly pushed changes to my production instance!

So ... how did I revert to my previous git commit?

(1) Logged into GitHub and looked for the last safe commit (i.e. the
last commit that had been pushed to production).
NB This could also have been done locally (e.g. using "git log"). Note
the SHA-1 of this commit, and also of the most recent commit. E.g.
SAFE: "3a710d2a84f856bc4e1c0bbb93ca517893c48691"
MOSTRECENT: "9063a9f0e032b6239403b719cbbba56ac4e4e45f"

(2) Locally, run:
git reset --hard 3a710d2a84f856bc4e1c0bbb93ca517893c48691
This resets the HEAD to the named commit, and also updates the
working-tree accordingly.

(3) Locally, run:
git push -f heroku master
This (forcibly) pushes the old commit to heroku (you need "-f" because
otherwise git-push will complain that it's non-fast-forward).

(4) Phew. Fixed. Finally, to carry on my work, I need to reset the
HEAD /back/ to the most recent commit, as follows:
git reset --hard 9063a9f0e032b6239403b719cbbba56ac4e4e45f

posterous, markdown, code-formatters

I’m experimenting with a few code formatters. Although Posterous claims support for markdown, I’ve had a lot of trouble using it. For example, the following snippet (please ignore the backslashes, and pretend there are four spaces before each line!):

\#\!ruby
def func
  blah :x => "Value"
end

Gets marked up as follows:

def func
  blah :x => "Value"
end

Like… where’s the ruby syntax highlighting? And why is “Value” not where it should be?

Gist is an alternative. It generates pretty code but … I’m not sure whether the code will be indexed my Google (I kinda doubt it because it’s written by javascript – I don’t know about this though).

fields_for undefined method 'xxxxxx' for #

I encountered a rails gotcha yesterday that I thought it worth detailing for my own sanity.

So, I have a model named "Event" which can have a nuumber of EventOption's attached to it. In my model I have the following:

The problem arises when, in my view, I try to generate some form code to allow the user to add or modify an event's options. (The issue, incidentally, may well be evident to any astute readers: I've forgotten to add "accept_nested_attributes_for" to my Event class but I'm going to carry on here because the error that gets reported is hugely unhelpful) My view looks as follows:

Nothing too unreasonable-looking there, But ... when I try to preview it, I get a horrible-looking stacktrace, containing:

undefined method `name' for #<Array:0x7f1f32188b40>

The "fix" as I mentioned above, is to add "accept_nested_attributes_for" to the "Event" class, as follows

Clearly, it's my own dumb fault for forgetting to add "accept_nested_attributes_for" but it appears that "fields_for" didn't fail entirely, instead it does something that you probably don't expect. It runs the block once, with f2.object being the entire Array that you passed as your second parameter to "fields_for". This caused my code to break (not unreasonably) but the error message didn't really suggest what the problem was. Hence this blog post!

fwiw, it's rails 3.0.5

Rant 1. The health insurance levy.

Re. "risk equalisation" (aka "community rating"):
http://www.irishtimes.com/newspaper/ireland/2012/0105/1224309833632.html

So, younger customers have a levy heaped onto their health insurance
premiums in order to subsidize older (less healthy) customers.

Sounds fair. Of course older customers should have good access to
quality healthcare. This is an advanced, Western democracy with a
strong belief in state-provided welfare. In the absence of a
properly-funded public health system, I am in favour of state
assistance for older people's insurance premiums.

I do, however, have a problem with the state assistance being funded
by a levy on less risky customers' premiums. Why are the customers of
health insurance companies being singled out, rather than the general
taxpayer? Imagine if that's how other policies worked:

1. A levy on coal and logs in order to pay for the winter fuel allowance.
(COMPLETE NONSENSE: the winter fuel allowance should be paid "by
everyone" from the public purse).

2. A levy on "safe" drivers to pay for "unsafe" drivers. (Actually, we
already have this: female drivers pay higher premiums in order to pay
for the antics of less safe male drivers, as insurers are - IMO
misguidedly - forbidden from discriminating on the grounds of gender)
(COMPLETE NONSENSE: unsafe drivers have a way of bringing their
premiums down: drive more safely!)

3. A levy on bus and train fares to pay for free transport for pensioners.
(COMPLETE NONSENSE: if pensioners are entitled to free transport, why
should that be funded by solely by other passengers? It should be paid
"by everyone" from the public purse)

So why is health insurance so different?

The main claim by the government is that it is trying to bring
competition into the market and that the incumbent provider (VHI)
faces unfair competition, on account of its older customer base.
Without "risk equalization" newcomers into the market would simply be
able to cherry-pick younger, healthier customers. In my view this
overlooks what "insurance" is - a premium. based on risk. Why
shouldn't newcomers cherry-pick customers? That's what competition IS.
Why shouldn't they provide them with the product they're demanding (a
risk-based premium that will pay for various health services in the
event of illness)?

I don't mind (in fact I ADVOCATE) premiums for older people
(especially those who - in many cases - have dutifully paid their
insurance premiums for the past 40 years) being subsidized by the
state. Provision of assistance to those in need is the duty of the
state, but NOT of private companies or their customers.

The quality of healthcare in Ireland is very good BUT the way that it
is funded is completely messed up. The government is desperate for
older people to be able to afford private health insurance, as
otherwise their healthcare requirements will need to be met by the
state (which the state can't afford to do!). Claiming that they're
guided by some principle of "fairness", they've decided to make health
insurance significantly more expensive for ALL customers, instead of
trying to provide a quality public health system for all.

The result is going to be a spiral of younger, healthier people
canceling their health insurance policies, leading to even higher
premiums, leading to more cancellations, etc. Net result: possibly one
or more insurance companies abandoning the market. Maybe this will be
a good thing if it leads to voting-class pressure for the improvement
of the public health system (arguably the reason why the UK's NHS,
despite its faults, is so good).


(Side-swipe: Where did all the money go during the boom years? Drug
companies and consultants have had it far too good for far too long.)

 

Useful links:

http://www.irishtimes.com/newspaper/pricewatch/2012/0109/1224310002571.html

http://www.irishtimes.com/newspaper/pricewatch/2011/0124/1224288161882.html