Author: francis

Running your Rails apps on a Mac

I keep making the obviously false assumption that people know how to run Rails apps on a Mac.

If you’re starting from scratch have a look here: http://railsinstaller.org/#osx – I haven’t looked at it, but it looks like it will take a lot of pain away. This post is for people who have an existing app running on an old version.

The following assumes that you have some kind of Ruby installed and some kind of Ruby gems that came with it.

Also, you’ve already got some Rails code, that may be running an old version of everything.

Install XCode if you need to

Start up a terminal and type

cc

If it gives you a command not found error then you need to download XCode from the App Store, fire it up, and then ask it to install the command line utilities. This can take a while, and google is your friend if you don’t know where to find things.

If you already have XCode then you just need to install the command line utilities, which are off on a menu somewhere.

Install RVM

gem install rvm

when it gets to the end of the install it will tell you what to do to your shell environment to run rvm properly. DO IT. 🙂 For reference see https://rvm.io/ If you are unfamiliar with getting things to run in the active shell after altering the shell startup commands, just close the terminal and start a new one, life’s too short.

Install the Ruby you need

In this exercise we want Ruby 1.8.7, so …

rvm install 1.8.7

Eventually it will finish and tell you the version it installed, e.g. ruby-1.8.7-p352

You may encounter some errors, where Apple have kindly set the default C compiler not to be the old GNU ‘C’ compiler but their llvm one. Cut the error message out and paste it into Google, then do what it says. 

These instructions might say that it can’t find the command that you put into the environment variable, in which case use whereis cc to tell you where the cc command is.

Any other problems, use the more command or an editor to browse the log file it says

Create a .rvmrc file in your Rails root

Let’s assume the Rails app is called brightstuff. In the root of your Rails app type

ls .rvmrc

If it finds something, have a look and see what it says, for the purposes of this exercise I’m assuming the file isn’t there. Type the command

cat “rvm use ruby-1.8.7-p334@brightstuff” > .rvmrc

Change brightstuff to the name of your app.

Now

cd ..

cd –

This takes you up and then back to the directory you just added the rvmrc to. If you have installed RVM correctly it will ask you if you want to use the .rvmrc. Say yes.

Now

gem install bundler

bundle install

This will set all the gems up for you in this version of Ruby, in a group named after your app.

Some people don’t use the gemset (which we have named brightstuff) and rely on bundle exec, but I’ve found this to be pretty bomb proof.

You can also install gems independently of the Gemfile used by bundler, I typically install things like powder (see below) like this, because they aren’t needed in any context other than development.

Start the Rails app

As is standard, you can start a development version of the app with:

bundle exec script/server

This will start the app on http://localhost:3000, you can use /etc/hosts and various tools (go look for them) to alias them, and start things on different ports.

Other things

I use the pow utility and it’s friend the powder gem to run my apps. http://pow.cx/

Review of “Dancing with Dragons”

George R.R. Martin, A Song of Ice and Fire, 5 Book Set Series, A Game of Thrones, A Clash of Kings, A Storm of Swords, A Feast for Crows, A Dance with DragonsGeorge R.R. Martin, A Song of Ice and Fire, 5 Book Set Series, A Game of Thrones, A Clash of Kings, A Storm of Swords, A Feast for Crows, A Dance with Dragons by George R.R. Martin
My rating: 3 of 5 stars

I have enjoyed the Game of Thrones series right from the beginning, but this book was very disappointing. The writing was very laboured in places, with characters repeating themselves, and there weren’t enough dragons in it for me. It also seemed to take far too long for anything interesting to happen, and when something happened it took a long time to actually effect anything.

The title is a reference to the various bits of royalty that have connections with the original Dragon Throne, but the dragons that Dany is bringing up don’t do much for 90% of the book.

I was also really interested in what was going to happen to Arya, but the answer was – “not much”.

And we finally meet the three eyed raven but again what happens? “not much”.

The book could have been 25% shorter and not lost anything, it needed an edit. Rather like the Harry Potter “Order of the Phoenix” it felt like it had been rushed and then left.

The cliff hanger ending was really laboured, and I’m not sure I can be bothered reading book 6. I also thought it was possibly the last book in the series and was irritated that a good number of plot lines are still dangling.

Not sure I care enough to read the last book, assuming there aren’t books 7 and 8 after it.

View all my reviews

Review of Better: A surgeons notes on performance

Better: A Surgeon's Notes on PerformanceBetter: A Surgeon’s Notes on Performance by Atul Gawande
My rating: 5 of 5 stars

This book is an easy read but very thought provoking.

One of the most interesting bits was where he examines the difference between the average Cystic Fibrosis centres and the best ones. All human activity has a bell curve attached to it, but CF treatment is very well understood and systematic. So why does one centre have startlingly better results than another?

In essence the better centre didn’t compromise, they didn’t think that (for example) 80% lung function was good enough, the patients under their care were expected to have 100% or better.

It’s the difference between 99.99% and 99.5% – we’d all be happy with 99.5, but excellence is in the remaining fraction of a percent, because when you add this up over several years this tiny difference means a lot. The sums are simple 99.5 over 5 years will give 97%, 99.99 will still be 99.99 or thereabouts. If you take this up over a patient’s life of 30 or 50 years the difference would be even more apparent.

I’ve hit this in other walks of life, for example project management, where you maybe have a 0.9 chance of finishing on time every iteration. This means that the chances of still being on track are as low as 0.6 after 5 iterations – it’s just mathematics. When building software having a fire break every so often to deal down the technical debt and reset the projects is perfectly doable, but if you’re looking for excellence in medical care or some other industry that could kill people then you have to become fanatical about getting higher scores

There are plenty of other excellent articles in the book, the fight to eradicate polio and the crazy situation faced by doctors in India are really great articles, and I learned a lot about how we could really help the people in poor countries. I admire Gawande’s honesty about his own shortcomings, this gives the writing a validity that it would otherwise lack. And the nutty unjust system that is the law based compensation for medical errors, that wrecks the chances of the poor to get help and helps no-one but the lawyers.

View all my reviews

Nearly midnight, again

So here we are again, it’s the middle of the night and I should be asleep. Instead I sit here waiting for the evening to be over. It’s dark outside but for the street lights. I wonder which of the endless layers of me is writing this, what obscure trophism is pretending to be me right now, creating the narrative force that pretends to be I.

I could be angry or frustrated, or so many things at once. The mind is an endless running brook split by rocks. The streams join together and I emerges out of the wreckage of all of the conflicting pieces, a pretence of a coherent whole. One never sees this sleight of hand except when you do bad things. The doing and the justification rarely hold up when you place them firmly under the microscope. So few people ever do, they just stumble from one moment to the next, thinking they are thinking and deciding things. But it’s all the dance of chemical chimera.

Longer ago than you can count stars exploded and made the matter you are made of. You sit at the bottom of a gravity well, perfectly adapted to what is in front of you, the chain of circumstances, of causes and conditions goes back beyond even those stars.

They died for love, for love could never have existed without them. But they had no mind, no awareness to die for it. Just like sand accumulating on the beach, it is ineluctable and happens without a master plan. So too, this whirling of circumstances that manufactures I will be gone and never seen again. The Buddhist masters say that the lives connected with you are like bricks on top of one another, the wall would not stand without that connection: but I begin to feel that the bricks are just bricks, the connection is the connection behind everything – the fragile I just makes itself and leaves enough traces to allow another one to stand in its place with some of the same attributes.

So let it go, now, and embrace it too. 

It’s not a bug. It’s a feature.

I like Android development. But you go off the beaten path and, well …

I’ve written some custom ListView objects that get rendered depending on what kind of device is needed for a home automation app I’m working on.

So far so bad.

Now you need to be able to turn that device on or off.

Tricky.

On the phone’s screen there is a button for every item displayed, each showing the correct value. 

BUT … inside it reuses the object that has been created. I have attached listeners to the button that mean when you toggle it off or on it sends a message to the underlying device.

It does. But then it sends messages to ALL the devices of the same type, because I’ve attached the listeners to what is basically the same GUI over and over again. So it looks right on the screen, but underneath all that happened was things were set in the right order so they display correctly. Right at the end of the call chain it sets the value back just for fun.

OK – let’s get it to tell me the ID of whichever row was tapped and only allow commands to be sent to that device. Nope. The button has the focus and won’t tell it’s container there was a tap and I’ve tried all the suggestions google could find for me. So the listener doesn’t ever get fired.

I think I’m going to have to short circuit the views and create them by hand, so each is a separate object with its own button etc. defined with its own listeners.

List View is designed to work with thousands of elements of homogenous data that can be tapped on and treated as a unit. But actually, for the case where there’s only a few that might have other things on them, it just doesn’t work.

I’ll have another look on line tomorrow.

By the way – I’d lay money that iOS Table View has similar problems, before people start doing the fanboi thing.

Take what the defence gives you – coding

I’ve recently listened to Steven Pressfield’s Turning Pro about 10 times driving up and down the motorways. I can’t recommend it highly enough. One of the things he talks about are the things that get in the way of getting things done, of pursing your art and doing what you have to do when you turn pro.

So, some days you just can’t get your mojo on. The pro doesn’t let this stop the work happening. So you take whatever you can get today and work with it. In sporting terms you’re having a day where you can’t make progress against your opponent. So you take what the defence gives you and push on. 

So when you look at what you need to get written today and don’t know how to start do the little things you can do and let the ideas percolate through your head. This is similar to the technique where writers just start writing anything that comes into their heads. When you do this it gets you moving and when you are moving you are not stuck any more.

So take what the defence gives you, take the steps you can take. You can’t do the big stuff all the time. But keep moving, that’s what works.

Android and mobile, purity, who cares?

Been doing Android dev full time for a few weeks now. I have to say I’m enjoying it. I also put myself through iOS training and have been doing some of that. Really enjoying that too.

I think I’m fed up with web apps, and all the arsing about you have to do to get things going and stoping useless bastards breaking your site. I can just fire up an IDE, and I’m there with mobile.

Beginning to think that the web will become the cloud (ha ha) sooner or later and most things will generally run as native mobile apps talking to servers (that used to be web servers). This will also take web apps away from the current Jesus-it’s-JavaScript-with-bouncy-shit car crash, the (web) interfaces will become simple again, because most of the time you’ll only go onto a site where a phone screen is too small to do something complicated.

I have to confess that I’m not missing Scottish Ruby either. I’d like to be there, but I’m enjoying writing apps in Objective-C and Java. I like the feel of this. Rails is becoming an over-complicated PITA to install and run. I mean, WTF, we replace JavaScript with something we can’t even debug? Please!

I’ve also discovered that my hatred of Java is really a hatred of J2EE and all that shoot yourself in the head dependency injection crap. For putting GUI components together in a coherent way it’s fine. But this makes sense, as it was originally designed to run set top boxes, and build desk top GUIs with Swing. It was only because it was the new kid in town and the web was new at the same time that it ever got popular, i.e. it was the only place to go for corporates who didn’t want to go the Microsoft route. But it was designed by a committee of computer scientists who’d didn’t understand what real people need, so it was always going to suck as much as the MS stuff. Sigh.

I’m not missing Ruby. I’m not missing BDD. I’m writing simple apps with a much faster turn around. Fuck me. I’m having FUN. Who’d a thunk it? Ruby was fun, it was radical. Rails made the web much easier and quicker. But now? I’m just bored by it, dunno why. I like to get things in the hands of folk who need them. Don’t care about the pedantic stuff. In fact the computer science types have taken over again. Sigh.

If you want to create a ListView adapter that searches on the string arbitrarily I’ve created a gist here, by the way. Enjoy.

error: Permission denied sending UDP broadcast packets

Sorry, gentle reader, this one’s a bit technical.

I was reusing some of the code Apple supply for sending UDP packets between servers, but the system I’m working with listens for broadcast packets. I set it up to use the address 255.255.255.255, but got the EACCESS error: Permission denied

I found an example that did work (without using Apple’s CFSocket class) and did a line by line what’s different. You need this to do broadcast

int broadcastEnable=1;

int ret=setsockopt(sd, SOL_SOCKET, SO_BROADCAST, &broadcastEnable, sizeof(broadcastEnable));

if (ret) {
    NSLog(@”Error: Could not open set socket to broadcast mode”);
    close(sd);
    return;
}
If you edit this into Apple’s UDP echo project then it will allow broadcast. Give thanks and praise at http://splinter.com.au/sending-a-udp-broadcast-packet-in-c-objective