Please support legal recognition of humanist marriages on the 20/21 May
by Developer @ pebbl.co.uk on Wednesday, 15 May 2013
Dear Sadiq Khan MP,
I am writing wrote to you the other day as your constituent to request your support for the legal recognition of humanist marriages when it is debated and voted upon at the Report Stage of the Marriage (Same Sex Couples) Bill on 20/21 May.
It seems baffling to me, as I'm sure it does to you, that people should still be discriminated against in particular terms of law solely based upon their sexuality or religious beliefs; where those beliefs in question neither hurt or discriminate against others.
If those who believe in a particular religion are allowed to be married in the way they wish, then so should every and anyone else, even those who follow no religion. I for one have always disliked the idea of a registry office wedding, precisely for the fact that it cannot be easily personalised and always seems to be held in places that have a similar feel to that of polling stations or classrooms. Not in a nice place to remember for the rest of your life. Obviously it is possible to have a registry wedding and then an event elsewhere, but this is where the problem lies, why should certain people have to do this... when others do not.
This simple change to the aforementioned bill would harm no one, yet it would enable people like myself to have the same choices as other human beings who — due to the simple randomness of life — just happen to hold differing belief systems.
Thank you for your time.
Was just checking back over a few old sites that I worked on and realised that some of the easter eggs I built in were still there and working — considering I know the guys behind these site pretty well, and it's been a few years (try closer to 7), I don't think they'll mind if I at least point one out.
I'm of the opinion that sites should have more fun / hidden elements baked-in, rather than the increasingly impersonal, out-of-the-box and off-the-shelf sites that you see everywhere today. It's those kinds of playful elements that give a human touch and memory to the otherwise transient complexity that forms the web.
To find the above Flash map you just need to visit http://www.airportguides.co.uk. Checking the map you'll see that there are two thin lines that cross at one point, triple click where the lines cross (you should get a pointer cursor) and then you should see a new island appear. Clicking this island should modify the content of the page, injecting some credits about the people who built the site — a kind of hidden humans.txt :)
Now for something else that humanises an otherwise hard to reach subject... and obviously does it in a far superior way — *hats off*.
JavaScript : Clone an object in JavaScript with Doppel
by Developer @ pebbl.co.uk on Thursday, 9 May 2013
With all my recent work towards Describe.js there have been a few mini functionalities that I've been able to generalise, ExpReg was one, Doppel is another. I've seen many deep clone methods in my time, but for Describe I needed the option to change the way the cloning was accomplished on a per usage basis. This might be quite a specific use-case, but there's no harm in putting it up here as a separate piece of code.
Whilst the following design is obviously not optimal — calling a function for every clone operation is quite slow — it does offer a lot of flexibility and mean that external code can form part of the cloning process.
var objToClone, objDoppel;
objToClone = {'hello':{'abc':123}, 'world':{'def':'456'}};
objDoppel = Doppel(objToClone);
console.log( objDoppel ); /// an output that looks like objToClone
console.log( objDoppel.test ); /// undefined
objToClone.test = 'added';
console.log( objDoppel.test ); /// 'added'
Doppel is hardwired to use Doppel.IMPOSTOR by default. This descriptor attempts to create clones that inherit from their origin — as shown above. If you wish to override this behaviour you could just modify Doppel.IMPOSTOR any way you like, or, you could pass in another descriptor:
var objToClone, objDoppel;
objToClone = {'hello':{'abc':123}, 'world':{'def':'456'}};
objDoppel = Doppel(objToClone, Doppel.CLONE);
console.log( objDoppel.test ); /// undefined
objToClone.test = 'added';
console.log( objDoppel.test ); /// undefined
Essentially Doppel is a map function but for objects. If you so wished you could do something like this:
var objToClone, objDoppel;
objToClone = {'hello':{'abc':123}, 'world':{'def':'456'}};
objDoppel = Doppel(objToClone, {
'object' : function(){ return {}; }
'string' : function(e){
return e.target.replace('456', '654');
}
});
Which would result in a cloned object but with 'def':'456' being changed to 'def':'654'. Anyway, it's a random bit of code that someone else might find useful, so here it is:
/**
* Doppel 0.1
*
* Doppel is a system that can clone an object in a tailored way.
*
* @param obj : the object to be cloned
* @param behaviour : an object containing type-keys which
* describe what should be done for each
* var type found. See Doppel.IMPOSTOR or
* Doppel.CLONE for examples, you can pass
* your own object too.
* @param recurse : boolean if true will deep clone, if false
* will only clone the object passed. (not
* implemented fully yet, assume true)
*
* @author Phil Glanville - 2013/05
*/
var Doppel = (function(){
var g, describe, doppel, impostor, DoppelEvent;
/// DoppelEvent mimics a similar implementation of an Event object
/// an instance of this "event" is passed into each clone description
/// method, giving quite a bit of useful information, and allowing
/// that code to decide where the recursion stops.
DoppelEvent = function(target, parent, property, path){
/// the target object
this.target = target;
/// the parent of target
this.parent = parent;
/// property on the parent storing target
this.property = property;
/// a built recursive path of properties
this.path = path;
/// Doppel will continue to recurse if true
this.recurse = true;
};
DoppelEvent.prototype.preventRecursion = function(){
this.recurse = false;
};
DoppelEvent.prototype.allowRecursion = function(){
this.recurse = true;
};
/// the actual recursive worker function
g = function(obj, behaviour, recurse, work, parent, property, path){
var r,i,e,t = describe && describe.type
? describe.type(obj)
: typeof obj
;
if ( recurse ) {
e = new DoppelEvent(obj, parent, property, path);
/// just in case we've come across this object before.
/// @todo: would be good to find a more optimal way that
/// doesn't rely on modifying any src or dst object.
if ( (i=work.src.indexOf(obj)) !== -1 ||
(i=work.dst.indexOf(obj)) !== -1 ) {
return work.dst[i];
}
}
/// create our doppel
r = (i=behaviour[t]||behaviour['default']) ? i.call(this, e) : obj;
/// store for checks next time around
work.src.push( obj );
work.dst.push( r );
/// if we are still allowed to recurse
if ( e.recurse ) {
for( i in obj ) {
r[i] = g(obj[i], behaviour, recurse, work, obj, i, path+'/'+i);
}
}
return r;
};
/// the exposed function that will be Doppel()
doppel = function(obj, behaviour, recurse, work){
recurse = true; /// false mode is not fully implemented yet.
describe = typeof describe !== 'undefined'
? describe
: {type:function(o){return typeof o;}}
;
if ( arguments.length === 2 ){
if ( behaviour === true ) {
behaviour = doppel.IMPOSTOR;
recurse = true;
}
else if ( behaviour === false ) {
behaviour = doppel.IMPOSTOR;
recurse = false;
}
else {
recurse = true;
}
}
else if ( arguments.length === 1 ){
recurse = true;
}
if ( !behaviour ){
behaviour = doppel.IMPOSTOR;
}
if ( recurse ) {
work = {src:[], dst:[]};
}
return g(obj, behaviour, recurse, work, null, null, '');
}
/**
* using the impostor description means that each of your
* clonable properties will inherit from the origin, but
* will essentially be a new object in-themselves.
*/
impostor = function(){};
doppel.IMPOSTOR = {
/// for objects, create a new instance with the origin inherited
'object' : function(e){
impostor.prototype = e.target; return new impostor();
},
/// please note function clone does not honour function.length
'function' : function(e){
return function(){e.target.apply(e.src, arguments);}
},
/// you could inherit an array from an array, but it would be weird
'array' : function(e){
return target.slice(0);
},
/// for anything else, return the origin
'default' : function(e){
e.preventRecursion();
return e.target;
}
};
/**
* The Clone description will actually create new objects for clonable
* items. These new items have no link to their origin what-so-ever.
* This is a very simple clone, if you wish to perform cloning of
* objects containing DOM Elements or other complex Native
* constructs I'd recommend building your own description object.
*/
doppel.CLONE = {
/// for objects, new object
'object' : function(e){
return {};
},
/// for arrays, slice clone
'array' : function(e){
return e.target.slice(0);
},
/// for anything else, leave as it is
'default' : function(e){
e.preventRecursion();
return e.target;
}
}
return doppel;
})();
- Leave your comment • Category: Coding, JavaScript
- Share on Twitter, Facebook, Delicious, Digg, Reddit
Please drop your legal challenges with regard to the Robin Hood / Tobin Tax.
by Developer @ pebbl.co.uk on Thursday, 2 May 2013
Dear George Osborne,
For once I felt as though many countries around the world were doing the right thing.. obviously ignoring the UK — I haven't seen us do much of anything right for a while — and now I hear that we, as a country, are trying to get in the way of other countries doing what they think is best. Why??
I keep hearing arguments against the "Robin hood tax" idea, and none of them hold water, especially when the number of countries involved is high. In fact all I see, as I have done with much of the financial issues of late, is big business and the very wealthy protecting their own interests. Now I totally understand the need for people to protect their own worlds, but you have to agree that the current way of existence is rather skewed towards those with deep pockets; and those with money have far more resources to fend for themselves than anyone else. They do not need any further help, and should remember they would not have got where they are without many of the little people underneath.
So I am writing to ask you to please drop your legal challenges with regard to the Robin Hood / Tobin Tax. You are not standing for my interests — as a UK Voter — in any way, shape or form. In my mind this tax is a small change that will make a large positive difference to many the world over, way beyond the foolishly imposed boundaries of "Country".
Believe it or not, we are all in this [Life] together, silly political catchphrases aside.
Thank you for your time.
VAT : Oh what I would do for a world where things actually made sense.
by Developer @ pebbl.co.uk on Sunday, 28 April 2013
Another rant post I'm afraid. After finally managing to submit my first VAT Return online, I spotted a link where I could give feedback to HRMC. It's only after merrily filling out a short complaint in their textarea that I spot the words "350 character limit"... forget how simple it is to limit a textarea, or to give a character counter... as usual I'm not supposed to expect the same level of quality from a government run website to that of the rest of the commercial world, or so it would seem, but I keep falling into that trap. So rather than completely truncate what I wrote I thought I'd post it here:
350 chars is not enough!
As usual, whenever I end up having to do dealings with any branch of the HRMC online it's as if only those who have studied Tax law could navigate and understand exactly what is expected, and only those who spot small links at the top right (a very bad location for western eyes) will find some of the most important navigation items. After your tenth page, third dead-end and twentieth bullet point starting with a complicated "IF" statement, you are already lost as to what applies and what doesn't.
My main complaint is that there is hardly any tailoring to the individual user, or type of business, something that the business world has to do otherwise they face losing custom. The whole experience when dealing with anything tax related is so impersonal I spend most of my time unsure if I've actually managed to do things correctly -- which is all I wish to do. This has been so much to the point that I have now taken on an accountant, and even now, things are still murky.
If the above wasn't bad enough, you even have inaccuracies in your forms. I've recently signed up to the flat-rate VAT Scheme, and if I had gone ahead reading your nine box VAT form myself, I would have filled out the values as it was asked. Thankfully my accountant advised me that I should be filling out box 7 with gross figures... there is no mention of this on the form itself.
Overall, I got the same experience from the VAT system as I have done with the Self Assessment system, the only positive is that the VAT form is much, much shorter.
Anyone might think this complication is done on purpose to create jobs...
Oh and one more thing...
The form doesn't even allow for return characters...!?! It doesn't tell you this however, it just gives you an error back saying "incorrect format" — good work HRMC.
describe.js v0.4, 0.5 and 0.6 have all been, urm... skipped.
by Developer @ pebbl.co.uk on Saturday, 27 April 2013
Things have gone a little quiet on the describe.js front, and the reason for this is that the last three versions have failed to be finished, and so, have also failed to see the light of day. Mainly because I kept on coming up with better ideas, well at least according to my brain anyway.
So just to keep things going — until I actually post some code — I thought I'd report that I'm now working on version 0.7. There is a reason for these leaps, which I'll explain once I'm done, but it should mean that describe will be even more powerful and extensible than before.
You'll just have to take my word for it for the moment though.
- Leave your comment • Category: Coding, JavaScript
- Share on Twitter, Facebook, Delicious, Digg, Reddit
I just put this miniature library together to help work with Regular Expressions in a cleaner and abstracted manner. It's pretty simple, but RegExp interaction in JavaScript has always been a little clunky in my opinion, so it doesn't take much to smooth things out a little.
/// example usage
var result =
ExpReg(/\|/gi)
.haystack('[believe|dont]|[either,way]')
.replace(function(match, i){return '{'+i+'}';})
.haystack()
;
/// result = '[believe{8}dont]{14}[either,way]'
Whilst the above may actually be shorter to type in pure JavaScript:
String('[believe|dont]|[either,way]')
.replace(/\|?(\[[^\]]+\])/gi, function(match, i){
return '{'+i+'}';
})
;
.. the problem with the above is that it is completely different from the formation to step through items matched, for example:
var m, re = /\|?(\[[^\]]+\])/gi;
while( (m = re.exec('[believe|dont]|[either,way]')) ) {
/// do whatever processing required here.
};
The main benefit of using ExpReg would be that the way of dealing with Regular Expressions is standardised, and all the RegExp objects that are created are remembered, so you can refer back to them quickly — useful in code that reuses expressions. Plus it's easy to add new methods that work in a builder fashion — similar to jQuery.
/// another example using a string instead of literal RegExp
ExpReg('/./gi')
.haystack('this should match every letter')
.each(function(match, i){alert(i)})
;
/// an example of mapping
var words =
ExpReg(/\w+/gi)
.haystack('this should match every word')
.map(function(match){return match})
;
Just in case it comes in useful, here is the recently imagined source code of expreg.js :)
/**
* ExpReg 0.1
*
* ExpReg is just a simple RegExp wrapper that has some useful
* functions for dealing with Regular Expressions. This include
* is designed to work with require.js but can also operate as
* a normal js include.
*
* @author Phil Glanville - 2013/05
*/
var ExpReg;
/// define not-exist fallback
(typeof define === 'undefined' &&
(define=function(a){return (ExpReg = a())}));
/// hook into require.js
define(function(){
"use strict";
var global = {
delims: new RegExp('^([^a-z0-9\s])(.+?)\\1([gimy]{0,4})$','i'),
lookup: {}
};
/**
* The outer wrapping constructor that will be exposed as ExpReg
*/
var ExpReg = function(re, haystack){
var t;
if ( this instanceof ExpReg ) {
if ( !global.lookup[re] ) {
if ( re instanceof RegExp ) {
global.lookup[re] = re;
}
else if ( (t = global.delims.exec(re)) ) {
global.lookup[re] = new RegExp(t[2],t[3]);
}
}
this.exp = global.lookup[re];
this.source = haystack?haystack:'';
this.matches = [];
this.matched = false;
this.reversed = false;
}
else {
if ( typeof this == 'string' ) {
return new ExpReg(re, ''+this);
}
else {
return new ExpReg(re, haystack);
}
}
};
/**
* Simple jQuery like attr function
*/
ExpReg.prototype.attr = function( name, value ){
if ( arguments.length == 2 ) {
this.exp[name] = value;
}
else {
return this.exp[name];
}
};
/**
* Define the haystack that the RegExp will search
*/
ExpReg.prototype.haystack = function(string){
if ( arguments.length && (typeof string == 'string') ) {
this.source = string;
this.matched = false;
return this;
}
else {
return this.source;
}
};
/**
* Return a particular matched item. A matched item will
* be an object that contains a zero-indexed array of .groups
* and an .offset property that gives the start of where the
* match was found.
*/
ExpReg.prototype.item = function(n){
if ( arguments.length == 0 || n === undefined || n === null ) {
return this.matches;
}
else if ( n < 0 ) {
return this.matches[this.matches.length+n];
}
else if ( n < this.matches.length ) {
return this.matches[n];
}
else {
return null;
}
};
/**
*
*/
ExpReg.prototype.findAll = function(){
/// remove previously found items
this.matches.length = 0;
/// reset and scan
var groups; this.exp.lastIndex = 0;
/// if we are global we can findAll
if ( this.exp.global ) {
while( (groups = this.exp.exec(this.source)) ) {
this.matches[this.matches.length] = {
groups: groups,
offset: this.exp.lastIndex-groups[0].length
};
}
}
/// if not global, match the first and stop
else {
this.matches[this.matches.length] = {
groups: (groups = this.exp.exec(this.source)),
offset: this.exp.lastIndex-groups[0].length
};
}
///
this.matched = true;
};
/**
* Replace current selection with either string or result of callback
*/
ExpReg.prototype.replace = function(param){
if ( !this.matched ) { this.findAll(); }
if ( this.matches.length ) {
if ( typeof param == 'string' ) {
this.source = this.source.replace(this.exp, param);
}
else if ( param.call ) {
var exrg = this;
this.source = this.source
.replace(this.exp, function(a,b){return param(a,b,exrg)});
}
}
return this;
};
/**
* Call a callback for each match found
*/
ExpReg.prototype.each = function(callback){
if ( !this.matched ) { this.findAll(); }
if ( this.matches.length ) {
var i, l = this.matches.length;
for( i = 0; i < l; i++ ) {
callback.call(this, this.matches[i], i, this);
}
}
return this;
};
/**
* Map the matches to an array
*/
ExpReg.prototype.map = function(callback){
var a = [];
if ( !this.matched ) { this.findAll(); }
if ( this.matches.length ) {
var i, l = this.matches.length;
if( typeof callback == 'undefined' ) { callback = 1; }
if ( callback.call ) {
for( i = 0; i < l; i++ ) {
a[i] = callback.call(this, this.matches[i], i, this);
}
}
else {
for( i = 0; i < l; i++ ) {
if ( this.matches[i] &&
typeof this.matches[i].groups[callback] != 'undefined' ){
a[i] = this.matches[i].groups[callback];
}
}
}
}
return a;
};
/**
* wrap the matches with strings
*/
ExpReg.prototype.wrap = function(pre, post){
this.replace(function(match){
return pre+match+post;
});
return this;
};
ExpReg.prototype.reverse = function(){
if ( !this.matched ) { this.findAll(); }
this.matches.reverse();
this.reversed = !this.reversed;
return this;
};
/**
* debug log
*/
ExpReg.prototype.log = function(pre, post){
this.each(function(match, i){
console.log(i, match);
});
return this;
};
String.prototype.ExpReg = ExpReg;
return ExpReg;
});
/// remove our temporary define fallback
(ExpReg) && (define = undefined);
- Leave your comment • Category: Coding, JavaScript
- Share on Twitter, Facebook, Delicious, Digg, Reddit

