General
Upgrading turnkey redmine from 1.3.0.stable.8673 to 2.0.4.stable
by Craig Mayhew on May.18, 2013, under General
First, upgrade rails. This will take some time, go and make a tea/coffee.
#gem install rails
#cd /var/www
#mv railsapp railsapp-old
#hg clone –updaterev 2.0-stable https://bitbucket.org/redmine/redmine-all railsapp
#cp railsapp-old/config/email.yml railsapp/config/configuration.yml
#cp railsapp-old/config/database.yml railsapp/config/database.yml
#cp -r railsapp-old/files/ railsapp/files/
#chown -R root:www-data /var/www/railsapp
#cd railsapp
#gem install bundler
#gem install test-unit
#bundle install –without development test rmagick
#mkdir public/plugin_assets
#rake generate_session_store
#rake db:migrate RAILS_ENV=production
If at this point you get an error about the mysql-adapter:
Please install the mysql adapter: `gem install activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile)
Then edit this file:
#vi config/database.yml and change all instances of “adapter: mysql” to “adapter: mysql2″.
Then, install the addon:
#gem install activerecord-mysql2-adapter
edit you Gemfile
#vi Gemfile
replace the section:
platforms :mri_18, :mingw_18 do
group :mysql do
gem “mysql”
end
end
with:
platforms :mri_18, :mingw_18 do
group :mysql do
#gem “mysql”
gem “mysql2″, “~> 0.3.11″
end
end
then run this again and hopefully it should work:
#rake db:migrate RAILS_ENV=production
chown -R www-data:www-data files log tmp public/plugin_assets
rake db:migrate:upgrade_plugin_migrations RAILS_ENV=production
If you find this errors with: “don’t know how to build task ‘db:migrate:upgrade_plugin_migrations’”.
then use this instead:
#rake redmine:plugins:migrate RAILS_ENV=production
this next one may error, ignore it if it does
#rake db:migrate_plugins RAILS_ENV=production
#chmod -R 755 files log/ tmp/ public/plugin_assets
#rake tmp:cache:clear
#rake tmp:sessions:clear
References:
http://www.turnkeylinux.org/forum/general/20120722/guide-how-upgrade-redmine-latest-version-203-painlessly
http://www.redmine.org/boards/2/topics/33504
RaspberryPi Power Management with a PIR Sensor
by Craig Mayhew on Feb.02, 2013, under General
This is a simple guide to setting up a PIR sensor with a raspberryPI to send a wake-on-lan packet to one or more computers. The idea being that as I walk into my office, everything boots up or comes out of hibernation automatically.
SSH into the pi and get the latest python dev code:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-dev
sudo apt-get install python-rpi.gpio
Install the Wake On Lan command:
sudo apt-get install wakeonlan
Plug in your PIR sensor using the 5 volt power line (pin 2), GPIO 7 for data (pin 26), the ground pin (pin 6). A word of caution, these pins should absolutely not be shorted out, they are also static sensitive.
RaspberryPI with a working PIR sensor:

Create a file called PIR-wake-on-lan.py on the raspberryPI and put this source code into it:
https://github.com/craigmayhew/scratchpad/blob/master/python/PIR-wake-on-lan.py
You will need to edit the file and put in your own mac address in place of “wakeonlan 00:00:00:00:00:00″.
Try running the script.
sudo python PIR-wake-on-lan.py
Earths processing capacity in my lap
by Craig Mayhew on Nov.05, 2012, under General
I wondered how long one needs to wait before owning the current worlds computer processing power for under $1000.
A few studies have been done to measure the world’s processing power. In 2007 the entire world’s computer capacity measured at 6.4 x 1018instructions per second[1]. as estimated by Martin Hilbert, et al. Unfortunately that’s not really a useful measure of processing power. FLOP/s would have been more useful as it relates to the useful work you can do.
So I’m going to have to do some estimating myself. The research firm Canalys have come up with a figure of 112 million PCS sold in 2011. I’m going to estimate (complete guess) the processing power of the average computer sold at 30GFLOP/s. I’m basing that on an Intel Core i7 980 XE six core processor available in 2010 measuring at 109 GFLOP/s. Most people are going to go for mid range processors though so that’s where I get my 30GFLOP/s from. I’m aware this does not include the graphics processing power. So we have a total of 112000000 x 30GFLOP/s = 3360000000 GFLOP/s or 3.4 ExaFLOP/s.
This same processing power will be available in a laptop or smaller device by the year 2033[2] as measure in MIPS. So that’s 26 years for the processing power of the entire planet to be condensed into a device that sits on your lap. If you want to argue that my estimate of the worlds processing is off by a factor of 10 then make it 2037. This does however ignore any game changes such as quantum computing, optical computing, spintronics… the list goes on.
Also, that is just one data point and relies on moore’s law, perhaps 26 years has been a constant since the dawn of computing, or perhaps it’s a number that get’s steadily smaller over time. If I find more data, I’ll update this blog post.
Sources:
[1] http://www.uvm.edu/~pdodds/files/papers/others/2011/hilbert2011a.pdf
[2] http://www.transhumanist.com/volume1/moravec.htm
How I complied with the EU Cookie Law
by Craig Mayhew on May.28, 2012, under General
I am a keen believer in law. It stops me being killed for my wallet while walking to the shop, keeps my house from being broken into while walking to said shop and my family safe.
So when a new law is passed – I do my best to comply. This one however, is ridiculous.
The EU Cookie law.
A law passed by the european union as a european directive. A directive to protect online users from cookies. The same cookies that make the web as we know it actually work.
So to get my site to adhere to the european law (which is slightly different depending on the EU country so I assume as I am not a solicitor and to be on the safe side that I need to abide by all variations). All I need to do is get informed consent from my website visitors before placing any cookies on their machine. It is important to note at this point that it’s not just cookies from craigmayhew.com but also any cookies from third party services I use on my site (facebook buttons, twitter buttons, google analytics, google adsense… the list goes on).
So, all I need to do is prevent any anonymous google analytics data from being recorded, adverts displayed and twitter/facebook buttons from appearing until I have “implied consent” from the website user.
I could achieve complied consent by displaying a banner at the top (welcome back to the 90’s!) asking the user to consent to cookies, deny cookies or continue anyway which would default to allowing cookies. Assuming they consent or continue then I can record anonymous google analytics data, display adverts and use twitter/facebook buttons, but only on the second page view.
Great – except 90% of my visitors only visit one page on my site. They find the exact page they need via Google, read the page, get the info and get out. So now I can’t get advertising revenue from 90% of users?
Oh wait I could display a dialog to every first time visitor before content is loaded demanding they accept my cookies or leave. Yea that would keep the site profitable.
Thanks EU directive, good one.
In response I have removed all advertising, analytics and all share buttons. So on the upside you as the site user have slightly faster page loads, but with reduced functionality. The silver lining for me is that the site no longer makes any money and so I no longer have to worry about paying tax for it :)
UK Spaceport
by Craig Mayhew on May.19, 2012, under General
The BBC caught my eye with a recent article on the possibility of a UK spaceport. http://www.bbc.co.uk/news/technology-18114439. This is a nice idea but I doubt we have any near term use for it.
What we really need is a government effort to develop the worlds first space elevator. The first country to do this will have a monopoly over the space industry as it should reduce the cost of sending objects into space by 95%. Not to mention all the patents and intellectual property that could be profited from.
If the UK decided to do this it could create many jobs. Suddenly the world would be sending all their material and technology here that they want sending into space. It would establish the UK as the leaders in a new field. I’m sure it would go a long way to sorting out the UK debt crisis in the long term …
Browser Compatibility Testing in IE
by Craig Mayhew on May.19, 2012, under General
Oh the fun… Hopefully this will help you with testing in IE.
Internet Explorer Application Compatibility VPC Image
https://www.microsoft.com/download/en/details.aspx?id=11575
Utilu IE Collection
http://utilu.com/IECollection/
How to generate negative mass, traverse hyperspace and walk through walls, even with a dog.
by Craig Mayhew on May.19, 2012, under General
I came across this recently, it had me in stiches and I have no idea if it’s serious.
It’s a patent application for walking through walls. There are several gems in here including “Upon reading his explanation, I realized that the thunderstorm is actually a hyperspace physics phenomenom.” and my personal favourite “How to generate negative mass, traverse hyperspace and walk through walls, even with a dog”.
http://www.scribd.com/doc/20946878/Walking-through-walls-US20060014125A1
A quick Google and there are several patents by the same chap JOHN QUINCY ST. CLAIR.
25th Birthday
by Craig Mayhew on Jan.27, 2012, under General
Absolutly awesome birthday. I’ve finally managed to upload the videos from my first flying lesson in an Ikarus C42. I took off at a local private airfold at 11:15 this morning (I was just a passenger for take off and landing and wasn’t in any control). I was able to have a camera suckered to the side window to video the lesson. Take off is at 7:35 in the first video. The final video shows the landing at 11:00 and the inside cockpit at 13:25. The weather conditions were near perfect in the morning but turned wierd in the afternoon. Checkout the handful of hail!
For those interested, the Ikarus is a two seater microlight aircraft with a maximum cruise speed of 194kph (120mph). See the Ikarus C42 wikipedia page for more details.


Short, elegant Regular expression for primality testing
by Craig Mayhew on Jan.22, 2012, under General
/^1?$|^(11+?)\1+$/
I was thoroughly impressed with this regex. I’m not going to reiterate what other people have already explained. So instead I will place links to other blogs that explain this very cool regex primality test.
http://montreal.pm.org/tech/neil_kandalgaonkar.shtml
http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/
http://zmievski.org/2010/08/the-prime-that-wasnt
Thanks to <a href=”http://rantsofageek.com/”>Theo</a> for sending me a link to this!
Critical SSL Weakness Found
by Craig Mayhew on Sep.21, 2011, under General
Researchers Thai Duong and Juliano Rizzo claim to have found a weakness in SSL encryption. It allows them to view anything that is encrypted with SSL and therefore supposedly secure. It affects TLS 1.0 and below which is just about every form of SSL currently supported by web servers and browsers. They will demo the exploit at Ekoparty security conference.
So the internet and ecommerce is now broken?
Don’t panic – there is a fix – it just hasn’t been written yet. TLS 1.1 and TLS 1.2 exist which are not vulnerable to the exploit. However they are not supported by major browsers or web server distributions. I suspect this will rapidly change and support will appear in the next month or so. Also – the exploit is not public and I expect it will be kept a secret for as long as possible.
What to do?
For internet users: Make sure your browser, email client and operating system is bang up-to-date and apply updates immediately as they become available! If your preferred browser is slower than others in getting a fix then temporarily switch to one that does have the fix.
For website owners: If your using SSL at all e.g. ecommerce or email then get onto your hosts once a fix is released and make sure they are going to implement it ASAP. If they are not going to update then move to another host.
For web hosts: Keep your customers informed and hope a fix comes soon!!
I will try to update this post with info on browsers and server software as and when they begin to support TLS 1.1