Ricky Moorhouse

Blog

Treasure Island

This afternoon we took the girls to the New Theatre Royal to watch Treasure Island, thanks to winning tickets in their twitter competition.

The set was really impressive with so many different things to spot with Abi before the show started, and had a fantastic ship's bridge, which doubled as the tavern entrance.

The show started with the beating of a drum and a fiddle player on stage, then the musicians took over and it developed into a big opening number, a combination which returned several times throughout, making great use of rhythmic elements intertwining with music from the excellent musicians.

There was a great balance of comedic and serious moments. The cast were fantastic and interacted well with the audience creating a great atmosphere.

The New Theatre Royal is a beautiful setting and all the staff were friendly and helpful. We had a really fun time and the girls both had a great time and got really into the show. If you can get to a performance, I'd strongly recommend it!

Recreating swipe to reveal in HTML, CSS and JS

One of the things I really like about the interface in Tweetie / Twitter for iPhone is being able to swipe a tweet to reveal actions beneath it.  This is my attempt to recreate it using HTML, CSS3 and Javascript.  The main swiping action seems to work nicely, but to complete it, I'd like to add a bit more bounciness, a sound effect on swipe (using ?) and have better handling of non-swipe actions.

The HTML used in the demo is very simple - just an unordered list. This currently uses jQuery because I already had it in the code I intend to use this with, but it's unnecessary for this part. The javascript adds the div containing the actions and event listeners for touch events. When your finger moves across the screen, if the vertical movement of the swipe is less than 10 pixels the default action is stopped to prevent the view-port moving sideways. If the horizontal movement is greater than 30 pixels, this indicates a swipe to the right, and the "swiped" class is added to the element. There may well be a better way to ensure normal scrolling and link clicking can take place, but this seems to work for now.

Javascript

<code class="language-javascript">
var swipeToReveal = {
init: function() {
document.addEventListener('touchstart', swipeToReveal.ontouchstart, false);
document.addEventListener('touchmove', swipeToReveal.ontouchmove, false);
$(document.body).append('<div id="revealedActions">'+swipeToReveal.actions+'</div>');
swipeToReveal.bgitems = $('#revealedActions');
swipeToReveal.bgitems.hide();
},
actions: 'Get some actions here',
startx: 0,
starty: 0,
target: null,
ontouchmove: function(e) {
var dx = e.touches[0].pageX - swipeToReveal.startx;
var dy = e.touches[0].pageY - swipeToReveal.starty;
if ((dy < 10) && (dy > -10)) {
e.preventDefault();
if (dx > 30) {
$(swipeToReveal.target).addClass('swiped');
}
}
},
ontouchstart: function(e) {
$('li').removeClass('swiped');
var target = e.target;
swipeToReveal.target = target;
swipeToReveal.bgitems.css({top:target.offsetTop,height: target.offsetHeight});
swipeToReveal.bgitems.show();
swipeToReveal.startx = e.touches[0].pageX;
swipeToReveal.starty = e.touches[0].pageY;
}
}

$(document).ready(function() {swipeToReveal.init();});
</code>

The main effect is produced in CSS using using -webkit-transform and -webkit-transition to slide the list item off the page when it has the class "swiped". Initially I did this by altering the left position of the element but the animation effect was very slow so I've moved to use a 3d translate to take advantage of the iPhone's hardware acceleration. To get the bounce effect I think I could replace the ease-in on the transition with a custom formula. The div that is added by the javascript is shifted into the background with a negative z-index.

CSS

<code class="language-css">
li {
/* positioning and colours removed */
z-index: 20;
-webkit-transform: translate3d(0,0,0) rotate(0deg);
-webkit-transition: -webkit-transform 200ms ease-in;
}
li.swiped {
-webkit-transform: translate3d(100%,0,0) rotate(0deg);
-webkit-transition: -webkit-transform 200ms ease-in;
}
#revealedActions {
background: #555;color: #fff;
text-align: center;
position: absolute;
width: 100%;
z-index: -10;
}</code>

View the Demo (only tested on iPhone)

10/10/10 10:10

10/10/10 10:10 - where I was:

Review: Surprised by Grace

Surprised by Grace: God's Relentless Pursuit of RebelsSurprised by Grace: God's Relentless Pursuit of Rebels by Tullian Tchividjian

My rating: 5 of 5 stars

Very clear and challenging look at the book of Jonah, showing us that the gospel is not just for those who haven't yet heard it but something that we as Christians need to keep coming back to. The book of Jonah points us to God and how he deals with Jonah's rebellion and ultimately our own rebellion.

View all my reviews

MySQL Locking

After experimenting a bit with MySQL locking today, I thought I'd make a note of what I'd discovered:

To create a lock, you need to use:

<code>LOCK TABLES table1 [READ |WRITE], table2 [READ |WRITE]</code>

READ is used to stop other people changing the table while you read from it. WRITE is used to stop other people reading the table while you write to it.

Once you have issued a LOCK TABLES statement, you will not have access to any tables you didn't include.

When you have finished, you can issue the UNLOCK TABLES command.

The lock remains until you issue the UNLOCK TABLES command, your session ends, you start a transaction or your client is disconnected.

The MySQL locking mechanism is no use if you need to lock something between PHP requests, unless you have a separate process running persistently to maintain the connection to the database.

Jonah Header

Our new Momentum devotional series on Jonah started today - here's a glimpse of my header design.

Recover from "Failed to open the relay log"

If you find that after rebooting your MySQL slave it stops replicating with the master and you see the "Failed to open the relay log" error in the logs it is probably caused by MySQL putting it's relay logs in /var/run by default, which gets cleared out on boot.

To fix this, you need to change the location MySQL uses for the logging by adding the following line to the [mysqld] section of /etc/my.cnf

relay-log = /var/lib/mysql/relay-bin

Then edit /var/lib/mysql/relay-log.info to point to the first new relay log (leaving the master information the same.

/var/lib/mysql/relay-bin.000001 1 mysql-bin.12345 123456789

Then from the mysql prompt start the slave:

mysql> START SLAVE;

(Source: Arjen's Journal)

Drawing of me

Abi drew this for me. She says I'm not a monster, I just have my teeth out!

Daddy by Abi

Self portrait

art

A traced picture on my iPhone, styled and touched up a bit for my twitter avatar and if you look closely, you can find it on my blog too...  I'm really liking Adobe Ideas for quick sketches, so there might well be more pictures of family and friends coming soon!

Monster #2

art

Same as #1 this was sketched in Adobe Ideas and finished in Sumo paint. I will give them names eventually, but for now Abi wants to call this one "princess bird"