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).

Posted

paperclip, has_attached_file, generated accessor

I've lost count of how many times I've been caught out, coding
if obj.image ...
(which always passes) when I really mean:
if obj.image? ...
(which genuinely tests whether "image" contains an uploaded file).

Maybe this will remind me!

Posted

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

Posted

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

Posted

Two things to know when upgrading to Ubuntu 11.10.

Most importantly:
  1. sudo apt-get install gnome-shell
because I still don't get on with Unity. Also:
  2. To edit gnome panels, you need to ALT-RightClick (thanks to: http://askubuntu.com/questions/65873/how-do-i-move-the-clock-in-gnome-classic)
 

Posted

Small Skype font size on Ubuntu 11.04 (linux)

Skype on Ubuntu 11.04 comes with pitifully small default font size.
I still haven't gotten my head around why it's so tricky to resize the standard Desktop fonts in this version of Ubuntu, but that's one for another day.
It turns out that Skype uses the Qt C++ libraries and thus font sizes can be amended using "qt4-qtconfig".
So:
 1. Download/install qt4-qtconfig (using apt-get or Ubuntu Software Center)
 2. Run qtconfig (either from the console, or via  System->Preferences->Qt 4 Settings)
 3. Amend the font size BUT!!! it turns out that there's a bug. If you just use the default GUI Style, "Desktop Settings (Default)", then your custom font size WON'T get saved. You need to select one of the other styles. Not sure if this is version dependent but I'm running Qt 4.7.2.

Posted

jEdit, ssh-keygen & passphrases

Trying to get jEdit to work on Ubuntu 11.04.
Trying to use FTP (/SFTP) plugin to connect to ssh server.
BUT jEdit never gets beyond the passphrase dialog. It doesn't like the key I generated with ssh-keygen on 11.04.
My /guess/ at this stage is that the version of ssh-keygen shipped with 11.04 uses a new algorithm to lock the key (using the passphrase).
It appears to be: AES-128-CBC
However, jEdit's FTP plugin doesn't appear to be able to unlock keys encrypted in such a fashion. It works with "DES-EDE3-CBC"-encrypted keys.
There doesn't seem to be a way to specify the passphrase encryption algorithm so ... the approach I'm adopting now is to use an OLD version of ssh-keygen (running on another o/s) to generate my key, and then copy it to my Ubuntu 11.04 box.
Two things would fix this neatly:
 1) The ability to specify the passphrase encryption algorithm when running ssh-keygen.
 2) An update to whatever-java-encryption-library-jedit-ftp-uses (will look for this, and update this post with findings!)

=====UPDATE=====

The following suggests that JSch (which jEdit/FTP uses) contains a recent update to cater for the above cipher (and one other). http://www.jcraft.com/jsch/ChangeLog 

  - feature: support for private keys ciphered with aes192-cbc and aes128-cbc.

So...when I next log in to Ubuntu 11.04, I'll try copying the newer jar file into wherever-jedit-stores-jars-for-its-plugins. http://sourceforge.net/projects/jsch/files/jsch.jar/0.1.44/jsch-0.1.44.jar/do... ...and cross my fingers!

=====UPDATE 2=====

Ok, new viersion of jsch.,jar didn't work (0.1.44). BUT a key created an another machine, running an earlier version of ssh-keygen DOES work.

Posted

dcu firewall ssh proxy

I was at DCU the other day. The campus is (free, password-less) wifi-enabled, which is great! But, I was trying to access an ssh server via linux/ssh and it turns out that the firewall blocks outgoing port-22 connections.

However, there's a helpful article on their internet:
 http://www4.dcu.ie/iss/networks/proxy/ssh.shtml
which explains that you should use a proxy for making ssh connections, along with instructions for Windows users, but not much help for linux users.

After plenty of googling, and attempting to install "corkscrew" (only works with http proxies) and "proxychains" (couldn't get it to work!) I stumbled upon the following article:  
  http://blog.paulbetts.org/index.php/2008/04/08/getting-ssh-to-connect-through-a-socks-proxy/

So, I installed "connect-proxy"
  sudo apt-get install connect-proxy
and then tried again:
  laptop:~$ ssh -vv -o "ProxyCommand connect-proxy -R both -5 -S proxy.dcu.ie:1080 %h %p" my.destination.server

This SHOULD have been enough BUT my ssh server listens on a port other than the default (port 22), and so dcu's proxy refuses to proxy such connections!

So ... my one last step is going to be to ssh to another server (this time one which has sshd listening on port 22) and then forward localhost:$LOCALPORT to my.destination.server:$SECRETPORT. Aka tunneling.
  laptop:~$ ssh -vv -o "ProxyCommand connect-proxy -R both -5 -S proxy.dcu.ie:1080 %h %p" -p 22 -f -l $ANOTHER-SSH-SERVER-USERNAME -N -L $LOCALPORT:my.destination.server:$SECRETPORT $ANOTHER-SSH-SERVER

Followed by:

  laptop:~$ ssh -p $LOCALPORT localhost

or if you don't want to get warnings about man-in-the-middle attacks, add the following to /etc/hosts:

  127.0.0.1 my.destination.server

and then ssh as follows:

  laptop:~$ ssh -p $LOCALPORT my.destination.server

Posted

refreshing DOM in (you guessed it) IE

I was seeing a bizarre error in IE7.
Not even quite sure how to describe it. Basically, the DOM seemed to be getting itself into a stale state.
If I put an
  alert("hello");
line in my script it fixed the problem.
However, adding a 1 sec delay (using e.g. jQuery) did not fix it. i.e. it wasn't a timing problem.
I kind-of guessed that alert() was somehow forcing IE to render teh DOM and thus refresh (in some way).
But ... how can you force a re-render in IE?
Answer: as follows (with thanks to:
  http://stackoverflow.com/questions/1397478/forcing-a-dom-refresh-in-internet-explorer-after-javascript-dom-manipulation/4271996#4271996)
 

Posted