Creating a personal Dropbox – using Sparkleshare with Webfaction

I wanted to create a personal version of DropBox, using my own hosting, in order to get around the privacy concerns of that service. I found this nifty application (despite the awful, awful name) called Sparkleshare which claimed to do exactly that, being a client interface to a git repository.

I wanted to use a git repository on my own hosting – webfaction – but couldn’t find a complete tutorial, so thought I’d reproduce the steps here. Thanks to Neum for getting me most of the way there.

1. Install git on your host
Read more …

Coloured options in a select element using jQuery

Styling form elements can be treacherous territory, as while css should allow this kind of functionality, form handling is increasingly within the remit of the browser (especially across mobile and tablet platforms). However, there are times when plain coloured drop-down lists are not desirable – for example on a status dashboard with many such elements – and this is one method that can be used to change this which appears to fail gracefully.

Let’s say we want to create a select box like the following:

Firstly we define the element:
Read more …

The Mandelbrot set in an html5 canvas

The Mandelbrot set is one of the pieces of mathematics behind the iconic fractal images of the 80s and 90s, and here I present how to render it on an html5 canvas, entirely in the browser.

The full mathematics of the Mandelbrot set are beyond the scope of this post, but can be found here. For our purposes, all we need to know is that we are dealing with a set of numbers – that is, every possible number either belongs to, or does not belong to, the set.

The Mandelbrot set deals with complex numbers – that is, numbers which have both a real and imaginary component. When we plot a fractal 2 dimensional image, each point represents a number, with a real component plotted in the horizontal axis, and the imaginary component plotted in the vertical axis (both purely by convention).

So, to render the image, we need to take every point within the image, determine which complex number it represents, determine whether or not that complex number belongs to the set, and colour it accordingly.
Read more …

Simulating a wind speed time series in python

I needed to generate a wind speed time series for a simulation, and couldn’t find any pre-existing code in Python to achieve this.

However, I did find the following post on using a Markov autoregressive function to achieve the same in R:

http://procomun.wordpress.com/2010/11/02/how-to-simulate-wind-speed-time-series-with-r/

So I’ve copied the mathematics used there and ported it across to Python, but with a bit of OOP rearrangement to give an object which will compute values on demand. In retrospect, a full-on generator class might be more pythonic, but I’ll leave that for now.

First some imports and helper functions:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env python
import datetime
import math
import numpy
import random
import operator
from collections import Counter

#homegrown weibull probability function
#scipy.stats.exonweib.pdf gives different result from R dweibull function
def weibullpdf(data,scale,shape):
    return [(shape/scale)*((x/scale)**(shape-1))*math.exp(-1*(x/scale)**shape) for x in data]
   
#matrix-vector multiplier from http://code.activestate.com/recipes/121574-matrix-vector-multiplication/
#equivalent to %*% in R
def matmult4(m, v):
    return [reduce(operator.add,map(operator.mul,r,v)) for r in m]

Read more …