Skip to content

Instantly share code, notes, and snippets.

DRAFT SPECIFICATION
# Zhook: Zip + HTML + Book.
Software that displays a Zhook file is here called a Reading System (RS).
A Zhook file is a zip file with a .zhook extension, which must contain:
* index.html (the Index)
@joseph
joseph / gist:573248
Created September 10, 2010 07:29
Making sense of touch events on iframes in iOS 4.1
function translateTouchEvent(element, target, evt, edata) {
// IN 4.1 ONLY, if we have a touch start on the layer, and it's been
// almost no time since we had a touch end on the layer, discard the start.
// (This is the most broken thing about 4.1.)
if (
p.brokenModel_4_1 &&
!edata.frame &&
!p.touching &&
edata.start &&
p.edataPrev &&
<!-- Assuming you have a Monocle reader in the global 'reader' variable -->
<div onclick="reader.moveTo({ direction: -1 });">Previous page</div>
<div onclick="reader.moveTo({ direction: 1 });">Next page</div>
@joseph
joseph / gist:1098634
Created July 22, 2011 01:12
blocks_for helper
# Iterates over an array and creates a bunch of "blocks" containing the
# yielded content. Example:
#
# <% urls = [
# "http://inventivelabs.com.au",
# "http://booki.sh",
# "http://nomify.com",
# "http://rungs.com.au",
# "http://getslipcase.com"
# ] %>
@joseph
joseph / Vagrantfile
Created March 22, 2012 04:14
Various fixes for Vagrant (Lucid64) on Mac OS X Lion
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Preventing kernel panics - VirtualBox 4.1 and Mac OS X Lion 10.7.
#
# This happens on my Macbook Air Mid-2011 Core i7. Every few hours, with
# one or (particularly) more VMs running, you will get a kernel panic.
#
# Some reading:
# https://www.virtualbox.org/ticket/9359
@joseph
joseph / .master.screenrc
Created September 26, 2012 08:23
Screen for vagrant
#==============================================================================
# MASTER SCREENRC FILE
# This contains the default 'screen' settings I like to use across all
# environments.
# Created: 4 Nov 2006
# Author: Joseph Pearson
# Based to a greater or lesser extent on various resources on the 'net.
#------------------------------------------------------------------------------
startup_message off
@joseph
joseph / audlbls-to-smil.rb
Created October 11, 2013 14:04
A guileless script for converting Audacity labels to SMIL, with very little configurability.
#!/usr/bin/env ruby
file_path = ARGV.shift
base_name = File.basename(file_path, '.txt')
html_file = base_name+'.html'
sound_file = 'audio/'+base_name+'.mp3'
out = %Q`<?xml version="1.0" encoding="UTF-8"?>
<smil xmlns="http://www.w3.org/ns/SMIL"
xmlns:epub="http://www.idpf.org/2007/ops"
@joseph
joseph / gist:6981446
Created October 14, 2013 20:10
The first function is specific to my Monocle-based app. But the second one is arguably useful, despite the name. It creates an AudioBuffer of the smallest viable mp3 (per http://www.hydrogenaudio.org/forums//lofiversion/index.php/t26315.html) and plays it immediately. You would invoke this from a click or touch event to "unlock" the AudioContext…
function panderToMobileSafari() {
if (!Monocle.Browser.is.MobileSafari || p.pandered) { return; }
oneHandClapping(p.context);
p.pandered = true;
debug('Pandered to MobileSafari.');
}
function oneHandClapping(audioCtx) {
var arr = [
@joseph
joseph / klass1.js
Last active August 29, 2015 13:57
JS class pattern [1] — "KIP"
// AMD module definition:
define(function (require) {
// An instantiable class:
var K = function () {
// This represents the public interface for the object.
var I = this;
// Properties of the object:
var P = I._p = {};
@joseph
joseph / klass2.js
Last active August 29, 2015 13:57
JS class pattern [2]
// AMD module definition:
define(function (require) {
// An instantiable class:
var K = function () {
this._initialize();
this._p = {};
};