Just finished 8 examples of how to use the javascript visualisation library D3 nest function - notes to self really, but shared in case they are useful for others.
http://bl.ocks.org/3176159 to see the code
http://bl.ocks.org/d/3176159/ to see all the examples run.
Wednesday, July 25, 2012
Thursday, July 12, 2012
Simple D3 examples to try
I learn by looking at examples and then trying to modify them to do what I want. I've started creating little gists to record how use different features of d3. In case they help others, here is a start. They can all be run in bl.ocks
Processing CSV strings and files and grouping with nest:
Processing CSV strings and files and grouping with nest:
- https://gist.github.com/3053667 - processing csv string
- https://gist.github.com/3053705 - processing csv file
- https://gist.github.com/3096857 - nesting/grouping to two levels
Drawing Axes:
- https://gist.github.com/3053419 - simplest possible
- https://gist.github.com/3059392 - date axis
- https://gist.github.com/3061203 - prettified, angled date labels and uses extent
- https://gist.github.com/3098488 - rescale an axis using a transition
Monday, February 20, 2012
Getting to grips with D3 Visualisations

D3 is a great library for creating all kinds of data visualisations written by Mike Bostock, but until recently I just couldn't get to grips with it. But then I discovered Scott Murray's great series of tutorials that start with the basics and build up and Luke Francl's appropriately named D3 for Mere Mortals. I've done some basic charts and am now rewriting the Protembla project management visualisations in D3. A big thank you to Mike, Scott and Luke.
Labels:
dataviz
Wednesday, February 15, 2012
What is the US of A?

Watching the BBC's Panorama program on poverty in the USA lately I was shocked at the levels of homelessness, hunger and lack of healthcare in the US, still the richest country in world and still pushing their way of life on the rest of us. Even more shocking to me was the attitudes of the Republican politicians, it's your life, it's your responsibility and if you can't afford to go to the doctor, well that's your problem.
To me that is not civilized. I think one of the measures of a civilization is how it treats its weak and how it treats its animals. Even the more sophisticated animals look after their sick, their younge and their old.
But then I realised America is not a civilisation, it's not a culture, it's an economy. As an economy the measure of their success is how strong their economy is and weeding out the weak is a necessary part of maintaining that success. But has that always been so?
I don't think so. American is given us much to experiment with, some of it we love, so we don't and much we absorb without question and I think the love of money and this concept that the economy is our lord and master that cares only for sort term profit, falls in that latter category. Where that came from I don't know, but I don't think it was part of the plan of any of the cultures that found themselves there over the centuries.
Personally I am happy to live in less affluent Ireland, despite it's many problems, where we care for each other, are embarrassed to hear of people falling through the net and ashamed of our greed getting the better of us in the last years. I'd much rather be poor and part of caring community than rich and living behind locked gates.
Labels:
economy
Saturday, February 4, 2012
Panic! - Beef stew without onions

I don't think I have ever made beef stew without an onion but I'd defrosted the beef and wasn't going to drive all the way into town for an onion so it was time to improvise.
I'm going through a ginger and, separately, an apple phase at the moment and also watching How to Cook like Heston - cheese programme was the latest. So having just finished a rich and satisfying beef stew, here is a rough and ready recipe:
Brown the beef chunks in hot oil then added glass (or two) of red wine to deglaze.
Add tins of chopped tomatoes in roughly equal quantity to the beef - in my case two tins, plus a bit of extra water to wash the tins out.
Add roughly copped garlic - three big cloves
Add roughly chopped ginger - two tables spoons
Oyster Sauce - two tablespoons
Rind or a large piece of hard goats cheese (thanks Heston)
Brought to the boil and then simmered for an hour with the lid on as didn't want to reduce.
Added one large cooking apple chopped in large chunks without skins and simmered for another 10 mins. You want the apple to be cooked but not disintegrated.
Was planning to add some cous cous but the larder was bare of cous cous so had wholemeal fusili cooked in the juice of the stew instead.
Really rich an filling and the chunks of apple were a nice surprise. The cheese rind really worked and easy to identify and pull out before eating. Mmmmmm.
Labels:
recipe
Tuesday, January 31, 2012
Customising django registration - no activation email or just a username
A client had a need for removing the email activation from the standard django registration process and a prototype system I am working on needed the ability to create a user from just a username, so I was delighted to find that the current django-registration development version makes this kind of customisation easy.
Here's how:
In the registration folder, there is a new folder called backends. Create a new folder, for example myreg, and put two files in it.
The __init__.py does the main work:
In this example there are two changes from the default, there is no email activation required and the registration form also asks for the users first and last names.
The second file is urls.py where you need to point to your new backend
Now an even simpler version. Just enter a username and the user is created and you are logged in. Note that I wanted a default password so I made password1 a hidden field on the form with the value I wanted so that is how it is able to create the user. I could also have hard coded it into the register method below.
Now in urls.py you just need to call your new backend
Here's how:
In the registration folder, there is a new folder called backends. Create a new folder, for example myreg, and put two files in it.
The __init__.py does the main work:
In this example there are two changes from the default, there is no email activation required and the registration form also asks for the users first and last names.
__init__.py
from django.conf import settings
from django.contrib.auth import authenticate
from django.contrib.auth import login
from django.contrib.auth.models import User
from django import forms
from registration import signals
from registration.forms import RegistrationForm
class MyRegBackend(object):
"""
A registration backend which implements the simplest possible
workflow: a user supplies a username, email address and password
(the bare minimum for a useful account), and is immediately signed
up and logged in.
"""
def register(self, request, **kwargs):
"""
Create and immediately log in a new user.
"""
username, email, password, first_name, last_name = kwargs['username'], kwargs['email'], kwargs['password1'], kwargs['first_name'], kwargs['last_name']
u = User.objects.create_user(username, email, password)
u.first_name = first_name
u.last_name = last_name
u.save()
new_user = authenticate(username=username, password=password)
login(request, new_user)
signals.user_registered.send(sender=self.__class__,
user=new_user,
request=request)
return new_user
def activate(self, **kwargs):
raise NotImplementedError
def registration_allowed(self, request):
"""
Indicate whether account registration is currently permitted,
based on the value of the setting ``REGISTRATION_OPEN``. This
is determined as follows:
* If ``REGISTRATION_OPEN`` is not specified in settings, or is
set to ``True``, registration is permitted.
* If ``REGISTRATION_OPEN`` is both specified and set to
``False``, registration is not permitted.
"""
return getattr(settings, 'REGISTRATION_OPEN', True)
def get_form_class(self, request):
class MyRegForm(RegistrationForm):
"""
add first and last names to the form
"""
first_name = forms.CharField(
label='First name',
max_length=30,
required=True)
last_name = forms.CharField(
label='Last name',
max_length=30,
required=True)
return MyRegForm
def post_registration_redirect(self, request, user):
"""
After registration, redirect to the home page
"""
return ("/", (), {})
def post_activation_redirect(self, request, user):
raise NotImplementedError
The second file is urls.py where you need to point to your new backend
urls.py
from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
from registration.views import activate
from registration.views import register
urlpatterns = patterns('',
url(r'^register/$',
register,
{'backend': 'registration.backends.myreg.MyRegBackend'},
name='registration_register'),
url(r'^register/closed/$',
direct_to_template,
{'template': 'registration/registration_closed.html'},
name='registration_disallowed'),
(r'', include('registration.auth_urls')),
)
Now an even simpler version. Just enter a username and the user is created and you are logged in. Note that I wanted a default password so I made password1 a hidden field on the form with the value I wanted so that is how it is able to create the user. I could also have hard coded it into the register method below.
__init__.py
from django.conf import settings
from django.contrib.auth import authenticate
from django.contrib.auth import login
from django.contrib.auth.models import User
from registration import signals
from registration.forms import RegistrationForm
class MyReg2Backend(object):
"""
A registration backend which implements the simplest possible
workflow: a user supplies a username, email address and password
(the bare minimum for a useful account), and is immediately signed
up and logged in.
"""
def register(self, request, **kwargs):
"""
Create and immediately log in a new user.
"""
username, email, password = kwargs['username'], kwargs['email'], kwargs['password1']
User.objects.create_user(username, email, password)
# authenticate() always has to be called before login(), and
# will return the user we just created.
new_user = authenticate(username=username, password=password)
login(request, new_user)
signals.user_registered.send(sender=self.__class__,
user=new_user,
request=request)
return new_user
def activate(self, **kwargs):
raise NotImplementedError
def registration_allowed(self, request):
"""
Indicate whether account registration is currently permitted,
based on the value of the setting ``REGISTRATION_OPEN``. This
is determined as follows:
* If ``REGISTRATION_OPEN`` is not specified in settings, or is
set to ``True``, registration is permitted.
* If ``REGISTRATION_OPEN`` is both specified and set to
``False``, registration is not permitted.
"""
return getattr(settings, 'REGISTRATION_OPEN', True)
def get_form_class(self, request):
return RegistrationForm
def post_registration_redirect(self, request, user):
"""
After registration, redirect to the user's account page.
"""
return (user.get_absolute_url(), (), {})
def post_activation_redirect(self, request, user):
raise NotImplementedError
Now in urls.py you just need to call your new backend
urls.py
from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
from registration.views import activate
from registration.views import register
urlpatterns = patterns('',
url(r'^register/$',
register,
{'backend': 'registration.backends.myreg2.MyReg2Backend', 'template_name': 'registration/registration_form_quick.html'},
name='registration_register'),
url(r'^register/closed/$',
direct_to_template,
{'template': 'registration/registration_closed.html'},
name='registration_disallowed'),
(r'', include('registration.auth_urls')),
)
Labels:
django,
registration
Sunday, December 4, 2011
Is cat food addictive (for cats!)

A friend brought some fancy Felix cat food in sachets when I asked her to pick up a bit of cat food on her way here. My cats are outside cats. Their normal diet is dried cat food once a day with small beasties as they catch them. Just occasionally they get a tin of cat food for a treat. They do well on this diet always looking sleek and shiney.
Anyway they wolfed down the Felix that night and I thought no more about it. Next morning I was mobbed at the door as though they hadn't been fed for days. They spent the whole day at this and finally got their fix in the evening. Next day the same. Thankfully the Felix sachets are finished and their behaviour is returning to normal. What was that about?
Labels:
cats
Subscribe to:
Posts (Atom)
