gem install merb-manage Apr 20 2008
So I’ve put merb-manage up on RubyForge, and uploaded the latest gem release, 0.4. This now means that you can do “gem install merb-manage” and have it installed to your machine, ready for use! For more information on how to use it and setup your apps, see the README over in the source at GitHub.
Any questions or comments, let me know!
CommentsManage Your Merb Apr 16 2008
So in getting this blog up and running on a server of mine, I needed a simple way to control and configure the Merb application, preferably with the ability to quickly alter the amount of servers, the logging, or indeed the adapter being used, amongst other things. I also wanted it so that much like Nginx, the Merb application itself would automatically restart if the server got bounced for whatever reason.
Introducing… merb-manage! Hosted over at GitHub, and open source, this is a simple tool that allows you to quickly and easily manage your Merb configurations on a server, and start/stop/restart your Merb applications as per your configuration. It also includes a bash script that can be installed to act as a startup script (such as in /etc/init.d) so that when your server restarts, your Merb applications spring back to life too! You can store the configuration within your application, and simply symlink it to a central configuration directory for merb-manage to go to work on (defaults to /etc/merb-manage), and you can change the adapter, amount of servers, port, user, group, and logging level straight from the configuration! It’ll handle multiple applications and their configurations so you have a one-stop shop for configuring and managing your Merb instances!
It’s fairly simple at the minute and I’m sure there’s some more useful features to be added, so if you have any ideas then simply fork it, add them in, and send me a pull request! Likewise any bugs, issues, either let me know, or even better, fix them and I’ll add them back in to the main tree!
CommentsDrop It Like It's Hot Apr 13 2008
So anyone that isn’t reading this in a feed reader will see that my blog has had a serious overhaul - and I’m now running on Feather. Me and Mike spent quite a bit of time last week or so expanding the Feather feature set, and it now more than copes with my existing blog. I was able to import all my old posts, customize the default theme to something a little bit different, and add in a few custom snippets (Analytics, FeedFlare etc). I was also able to add redirects for old links to ensure that (hopefully) there isn’t too much broken by the move. All old posts will have the same permalink too, handled as part of the import process.
Currently I’m running without caching, but I see my partner in crime Mike has gotten caching up and running on Feather, so I’ll get that setup and running shortly too, to improve the performance of the blog still further.
As far as I can see the blog should be running ok, but any issues - let me know with a comment, or an e-mail, and I’ll get right on it!
CommentsLight as a Feather Apr 7 2008
My boy Mike is back blogging his ass off again, and this time, he’s doing it on some decent software! Last few weeks me and Mike have been working on an ultra-cool blogging platform written using the Merb framework, and it’s now in production use for Mike’s blog. This very blog will follow suit shortly as I migrate over, and within a few weeks we are hoping to have the codebase in a good enough state to be able to open up the source, and start to invite contributions from anyone that feels the need to help out. The idea behind Feather is the same as Merb - lightweight core framework, extended heavily by plugins, allowing you to choose the pieces of functionality you need, and leave out the guff that you don’t. Keep it dialed in here for further updates on Feather over the next few weeks, and keep a keen eye on Mike’s blog too for more great posts. In fact, he’s already in the thick of it with this great post on why Ruby does it for him (and why .Net doesn’t).
Adventures in Merb Mar 17 2008
I decided to give Merb a go, and after doing a fair bit of reading up on it, I took the plunge. It’s a little rough around the edges, but that’s probably to be expected given it’s youth - however there are a number of cool features and benefits to using it, and it’s getting better and better as it’s being refactored. I did however come across a few interesting issues getting up and running, so I thought I’d share these to try and make the process easier for others.
I installed the gems from http://merbivore.com, by doing the following:
sudo gem install merb --source=http://merbivore.com --include-dependencies
This gave me the merb-core gem, along with merb-more. However, to get up and running with a database, we really need a database plugin - let’s try DataMapper.
sudo gem install datamapper --source=http://merbivore.com --include-dependencies
sudo gem install merb_datamapper --source=http://merbivore.com --include-dependencies
Now you’d think that a dependency for merb_datamapper would be datamapper itself, however it doesn’t get included, and so you need to download that as a gem, and then download merb_datamapper. We then need a few other gems, including one specific to the database you’ll be connecting to:
sudo gem install data_objects --source=http://merbivore.com
sudo gem install do_sqlite3 --source=http://merbivore.com
As you can see, I chose to install do_sqlite3 for accessing a sqlite3 database. However you could install “do_mysql”, or “do_postgres” to access MySql or PostgreSql databases respectively, and I’m sure there are others. Sqlite users using Mac OS X 10.4 (Tiger) should bear in mind an issue I came across, whereby a strange error is received when attempting to do any database related activity with the do_sqlite3 gem and the default native sqlite3 version that comes with the operating system. This manifested itself as a couple of different strange errors (including a “DataMapper constant not found” error when starting Merb), however the solution was simply to grab the latest sqlite source from www.sqlite.org, build it, and install it. Then try re-installing the do_sqlite3 gem as above, and you should find that they play together much better!
We can now proceed with creating a Merb app to play with:
merb-gen testapp
Looking in the “testapp” folder now shows us the initial structure Merb uses, which is fairly similar to how Rails applications are structured. The main differences that you’ll need to know straight away are that routes are defined in the “router.rb” file within the “config” directory, and that the main settings and application initialization stuff is within “init.rb” in the “config” folder. Let’s setup our app to use DataMapper by changing the “init.rb” file. Find the following lines:
### Uncomment for DataMapper ORM
# use_orm :datamapper
### Uncomment for ActiveRecord ORM
# use_orm :activerecord
### Uncomment for Sequel ORM
# use_orm :sequel
and uncomment the datamapper line, like this
### Uncomment for DataMapper ORM
use_orm :datamapper
### Uncomment for ActiveRecord ORM
# use_orm :activerecord
### Uncomment for Sequel ORM
# use_orm :sequel
This then tells our application to use and load the DataMapper database plugin. Further down in that file you’ll see something similar for testing, and you can choose whether to use rspec, or test_unit. Using rspec is the default. After we change the database settings, we run:
merb-gen
to get it to generate database config. This will create the file “database.sample.yml” in the “config” folder, which we can rename to “database.yml”, and configure correctly. Here is a sample development configuration set to use sqlite3:
:development: &defaults
:adapter: sqlite3
:database: db/testapp_development.sqlite3
Remember to create the “db” directory. Now to finish off our test application, we can create a dummy controller and views, to see our application in action.
merb-gen resource person first_name:string last_name:string date_of_birth:date
Now we need to migrate the data to take into account the new model. Note there are no migration files like in Rails, however there is a Rake task to migrate the data based on the DataMapper definitions with the model classes:
rake dm:db:automigrate
That should now create the database file (“db/testapp_development.sqlite3”), and we should now be able to play around with the model within our application. First, let’s run the application via the console, and inspect the new model:
merb -i
>> Person.count
This will display a count of 0, as there are no people in the database yet. Let’s create one:
>> Person.create({:first_name => "test", :last_name => "dude", :date_of_birth => Time.now})
Only this returns an error!
DataObject::QueryError: Your query failed.
table people has no column named date_of_birth
For some reason, the migrations within DataMapper tend to be a bit erratic - there is a console command you can run however that will often fix issues and sync the model definitions to the database more accurately:
>> DataMapper::Persistence::auto_migrate!
Running our create command from before should now work as expected, with a Person object returned and saved with an ID of 1. You can check to ensure that there is a Person object:
>> Person.count
=> 1
>> Person.all
=> [#Person]
>> Person.first
=> #Person
>> Person[1]
=> #Person
The above queries show how to retrieve all Person instances within the database, just the first, or a specific Person by ID. In this case, the same (and only) Person instance is returned (it’s returned as an array with a single element in the “Person.all” query). But now let’s check out the real deal, and see the web interface - fire it up by just running:
merb
This will start the server, and you can now browse to http://localhost:4000 to see the application. This will show a Merb error page, saying that no route matches the request “/”. This is because while we have a single resource within the application, it’s setup to be exposed by default at http://localhost:4000/people. Browse to that url, and you’ll see the default Merb generated view. Let’s hook this up to the root of the application so it’s accessible at the easier to remember url http://localhost:4000. Within the “router.rb” file in the “config” folder, look for the following lines:
# Change this for your home page to be available at /
# r.match('/').to(:controller => 'whatever', :action =>'index')
and change the second line to read the following (uncommenting it, and changing the controller to our “people” controller):
r.match('/').to(:controller => 'people', :action =>'index')
Now browsing to http://localhost:4000 will show you the same default view for the “people” index as it would if you were browsing http://localhost:4000/people. You can now customize these views to display and interact the models, in a similar fashion as you would do in Rails!
One other thing to bear in mind is that Merb apps default to port 4000 - however running different apps on that default port at differing times will cause issues because of the way the secret session key is managed. This will most likely be fixed in due course, but at the minute running a second app on the same port at a later date will often result in a secret key error - you can run each app on a different port, or simply find the cookie that represents the “lock” on that port by a specific application, and remove it; then a different application won’t have issues using that port. You may well find that re-using a Merb app port with a Rails app also causes an issue, again removing the cookie should fix this.
So that’s pretty much it - a very basic Merb app, some potential pitfalls found and sidestepped, and a powerful, lightweight web application framework at your fingertips. While it’s obvious Merb is a work in progress, it’s also obvious just how useful this framework might become, especially for those looking to create more streamlined, better performing applications. Comments
Tyred Mar 15 2008
While driving home after picking my wife up yesterday, about two minutes away from our house, we suddenly had a loud banging noise start up, and immediately we both thought “flat tyre”. I pulled over as soon as was possible, and took a look around the car. It had already got dark, and I couldn’t see anything obviously wrong with any of the tyres. None of them were flat, that was for sure. I took a look under the car, still nothing. It was obvious there was something wrong, and I thought it had to be tyre related, as the noise quickened slightly if I got a few miles per hour faster, and slowed as I slowed down. I drove home at around 10 mph, letting people pass where I could, and then we took another look at the car.
My wife noticed a hissing noise from the right rear tyre, and it became obvious that it was that tyre that had a puncture - however it must have only just happened, as it wasn’t yet flat at all. After a bit of investigation with the help of a flashlight, we found the culprit - what appeared to be a screw or bolt in the tyre. As it was already late, I left it until today to sort it out - I ran the tyre into a local place to see if it could be repaired, as the screw/bolt had gone in straight in the center of the tyre, and not on either side, so I was hoping the tyre itself and outer walls were largely intact.
It turned out it was irreparable, and this is the reason why:
UPDATED:Seems like I’ve lost this picture somewhere along the line! Needless to say, it was a photo of the tyre with a rather large bolt through it.
What you see in that picture is a bolt, around four or five inches long, the kind that are used in door handles. It wasn’t obvious from the outside how big it was, but with the tyre off of the wheel, you can see just how big an item it was. Somehow it went in dead straight, and considering the speed I was traveling at when I picked it up (around 35 mph), it was fairly lucky that no further damage was done. It was also lucky that we weren’t too far from home. However what that bolt was doing in the middle of the road, and how exactly it got wedged the way it did, I don’t know - the guys at the local tyre place seemed fairly amazed by it too!
The Budget, Democracy, And Britain Today Mar 13 2008
So yesterday was the budget in the UK, the day where the government outlined the nations finances, and proposed economic reforms. The Chancellor managed to put a positive spin on many of the economic forecast figures (especially given the global economic backdrop), however it was obvious that the majority of these figures seem to be fairly optimistic, and it doesn’t help that a number of the figures were massaged to suit their needs - conveniently leaving out the nationalisation of Northern Rock for example, which has adversely affected the economic outlook for the country. Had it been included in the figures on the nations debt, then the government would have been outside of their targets - of course, even with it excluded, they are barely making their targets, and barely meeting their ‘golden fiscal rules’.
I’m not going to go through all of the budget, as there are a lot of different aspects to it - however here is a brief run down of the bits that seem to be the main talking points today, and which are probably the most salient points for most Britons:
- Delayed rise in fuel duty - a 2p increase was due to come in in April, but that has now been delayed until October
- Incentives for those buying new greener cars, but potentially increased taxes when buying new cars that are deemed bad for the climate
- Funding set aside for 'researching’ road pricing (i.e. congestion charges, and toll roads)
- Alcohol duty raised - beer up 4p a pint, wine up 14p a bottle, and spirits up a massive 55p a bottle
The delay in the fuel duty sounds like good news - until you realise that fuel prices as a whole have increased by around a fifth in the last two years anyway, and while the biggest reason for that increase is the rise in crude oil prices, the tax that the government currently apply is a percentage - so when the price of fuel goes up, the actual amount of tax they take increases. Crude oil prices have gone up as a result over supply issues, and fears over conflicts in the Middle East - and so the increases are far above inflation. This means that you are paying more for your fuel now than you were a year ago, even in relative terms. A delay until October will still not allow the fuel prices to settle in line with inflation, and will still leave all of us out of pocket every time we fill up our cars.
Talking about cars - those buying new cars will be affected by a new 'showroom tax’. The idea? Taxing those who decide to purchase cars that are bad for the climate. However in reality, it appears that the definitions may include many cars that are commonly used by Britons today (such as the Ford Mondeo, and the Citroen Picasso). This means it isn’t singling out just the worst polluters. From April 2010, the highest polluting cars will result in £950 in vehicle excise duty in the first year. It’ll then be £455 per year thereafter. The next emissions band down will draw £750 in the first year, with £430 a year from then on. For current cars, from April 2009, the emissions bands will also change, and it’ll result in increased charges for many drivers. Of course, those driving green cars supposedly should end up paying less - but seeing as how these changes are forecast to generate £465m in 2009-10, and £735m in 2010-11, it’s obvious that this is another money spinner. It would make sense to me to concentrate on providing incentives to allow many drivers of much much older cars (of which there are still lots on Britain’s roads) to upgrade to new cars, which are surely better on emissions in many cases.
The fund set aside for research into 'road pricing’ seems like an awful lot of money to spend, given the state of the economy, and the tightening of the purse strings in other areas. No word yet on whether this 'road pricing’ would replace the road tax that all drivers are paying today anyway - however my guess would be that in the end, drivers will end up paying both the road tax, and 'pay as you go’ road pricing charges, as it’d just be another source of revenue for the government.
On alcohol, Labour chose not to adopt the ludicrous proposals put forward by the Tories a week or two ago (massive increases on high alcohol level drinks and alco-pops), however they did decide to apply some fairly hefty, above inflation tax increases to alcohol across the board. The Tory proposals were designed at curbing binge drinking amongst Britain’s youth, and there’s probably a similar sentiment behind the Labour proposals - however they are all missing the point in a fairly fundamental way. It seems as though everyone is being hit with the increased taxes, to cover the supposed increased costs that the National Health Service and the Police are facing when dealing with binge drinking on the streets. It actually makes more sense to simply bill those responsible for those increased costs. It surely doesn’t get any simpler than while handing a yob his court summons for drunk and disorderly conduct after releasing him from an overnight spell in the klink, the Police also hand him a bill for the jail cell for the night, and for their time. Likewise, when a drunken youth is discharged from hospital after having their stomach pumped because of the excess alcohol they irresponsibly consumed, they should have to pay their own medical bill. It seems to have gotten to a level within this country now where personal responsibility is a thing of the past, and so we all pay the price, in most cases, literally. While the above measures of course are simplified somewhat, the basic idea that people could be responsible for their own actions is something that is ignored in todays taxation system. And the main reason we are unlikely to see such a change, is that the increases in alcohol taxation that effect everyone will drag in more revenue for the government than they actually need to cover the increased costs posed by binge drinking, whereas if they only charged those responsible for the costs, they wouldn’t end up making any extra money on it. Potentially then, this is yet another stealth tax in many respects, designed to generate revenue to cover shortfalls in other areas (or to pay for expensive research into 'road pricing’).
Anyone that’s followed this thus far has probably gathered that my general feelings on the budget today aren’t positive. There seems to be a certain amount of sticking heads in sand, and ignoring the economic slowdown that’s affecting the country - instead putting a positive spin on massaged figures. There also seems to be a growing trend towards taxation ahead of personal responsibility. I think that the main problem facing this country at the minute though, is one of democracy.
Aside from the budget, and the economy; one thing that is forgotten is that the current Prime Minister, and the Cabinet he has put in place, have no public mandate to rule the country. While there are undoubtedly Labour supporters who are behind the current government, no-one in this country has been given the opportunity at the ballot box to decide whether the current Prime Minister, Gordon Brown, is right for the country. This is supposedly a democratic nation, and yet the leader of the country wasn’t put in place by any general election. His party was voted in (narrowly) almost three years ago, but he wasn’t the leader then, and if he had any stones at all, he would call a general election, and see if him and his party still have a mandate from the people of this country to make decisions, or whether it’s time that the country wants someone else in place. Of course, almost all of the newspaper and TV polls suggest that the country DOES want someone else in place, and as long as the public opinion suggests change, the current government will wait as long as possible before asking the nation to vote. They are making decisions here with no say from the 60m inhabitants of the country - that doesn’t sound like democracy to me. Here’s hoping that Britain becomes a democracy again sometime soon. Comments
Git A Load Of This Mar 12 2008
So it’s already made the rounds on a number of blogs, but having switched to Git about five weeks ago for all my code, I’ve now been using GitHub for the last three or so weeks, and it’s a really great service. The user interface is brilliant, and the integration with Git is incredibly simple. The fact that it’s still in beta means there’s lots more to come, and they’ve been very active at adding in new features over the last few weeks too, including most recently the beginnings of an API! I’m running a number of private repos at GitHub and it’s been nothing but a joy to use. They just announced their pricing plans for when they come out of beta, and it’s more than reasonable for the service they provide. Great job guys!
CommentsiPhone SDK Mar 6 2008
So today was another Apple event, the ‘iPhone roadmap’, and as expected, the SDK was outlined in some depth. To break it down, it basically looks like:
- The SDK is available, for free, from today (free Apple Developer Connection account required before download)
- The SDK will require Mac OS X 10.5 Leopard
- The SDK will provide extensions/additions to XCode/Interface Builder to create iPhone apps, as well as an iPhone simulator, and a remote iPhone debugger
- The 'App Store’, used to distribute iPhone applications direct to the iPhone and iPod Touch, will debut in June as part of the iPhone 2.0 firmware update - it’ll be available from today for select beta users
- There is an iPhone developer program, currently US only (expanding soon), that costs $99 to register, that presumably will put you first in line to be one of the select beta users to get hold of and test the iPhone 2.0 update before June
- Free apps will be just that, free to distribute through the 'App Store’
- Commercial apps will have price points set by the developer, with 70% kept by the developer, and 30% of the revenue going to Apple
- Apple already have a number of partners who have been working on iPhone apps, including EA, Sega, Salesforce.com and AOL
Comments
Ruby link round-up Feb 24 2008
I’ve seen a number of great Ruby articles, tutorials and discussions recently (and not so recently), as well as some interesting projects, so I thought I’d write a quick round-up of links to some of the most interesting stuff. It’s split by category, with a miscellaneous list for stuff that didn’t seem to fit anywhere else.
- Merb
- Amazon EC2 + S3
- iPhone
- Books
- Another post from Ezra, who happens to be one of the authors of ‘Deploying Rails Applications’. This post says that the book is now at the final beta stage, and includes some more advanced content such as Apache/Nginx scaling, and Xen setups. I’ve just ordered up the beta PDF, and will be receiving the paperback too when it ships in May. Hoping to do an initial review once I give the beta a read, looks very interesting though.
- Tools and projects
- Heroku, online Rails application creation and hosting. Very cool tool for creating or collaborating on a hosted Rails application, all through your browser.
- Rush, a Ruby based shell, from one of the guys behind Heroku. Interesting concept, along the same sort of lines as Windows Powershell - but because it’s Ruby, it has a much better syntax :-)
- An article about the usage of Beanstalk, a messaging queue system, to power the Nuby on Rails blog.
- Hot off the presses, a new Capistrano preview, with some cool features such as better role definitions, and better git integration.
- Miscellaneous
- An article on generating feeds using microformats within html.
- Good post from 37signals about building a web app, and making sure you get it right - even if it means starting over.
- An article on using Ruby for scripting tasks on Mac OS X.
- Interesting article on tackling master/slave database setups with Rails.
- Great screencast on PeepCode about git, a source control tool that is all the rage at the minute. Really good introduction to the tool.
Page 12 of 31 | Next page | Previous page