Instead of having to use one of the various javascript rss libraries, one can take advantage of google reader’s (undocumented) api.

note: the following assumes that the jQuery library is being used
Read the rest of this entry »

Just a little hack using show to make the earlier summing series example look a bit nicer.

Start with what I had before:

sumseries a b f = sum[f n|n<-[a..b]]

I have swapped around and renamed the arguments a little, just to tidy it up a tad.
Summing the first 5 evens (2 + 4 + 6 + 8 + 10):

*Main> sumseries 1 5 (\r -> 2*r)
30

So, I want to prettify it. I want to use Σ for the sum function. So this is easy, right? Just call the function Σ and be done with it. Not so – Sigma is an uppercase letter, and in haskell, these are reserved for datatypes.

Solution: make a datatype

data Σ a = Σ a a (a -> a)

Sure, we have a datatype, but we can’t call this. Now for the hack:

instance (Show a, Num a, Enum a) => Show (Σ a) where
show (Σ a b f) = show $ sumseries a b f

– when we want to show the datatype, like in ghci’s prompt, we call sumseries and show the result of that instead.

Example:

*Main> Σ 1 5 (\r -> 2*r)
30

or more concisely

*Main> Σ 1 5 (*2)
30

If you’ve studied capacitors, you’ll have (very probably) come across the decay equation:
Q = Q_0 e^\frac{-t}{RC} where R is resistance, C is capacitance, Q is the charge on the capacitor at time t and Q_0 is the initial charge.

Where does this come from?

Firstly from the basics of circuits, we know that V = IR (yes, I’m using the british convention with regards the symbol for voltage, I understand elsewhere U is used instead).
V = IR \Rightarrow I = \frac{V}{R}

Now when we discharge a capacitor through a circuit, the e.m.f.s are supplied by the capacitor.
Q = CV \Rightarrow V = \frac{Q}{C}

Now substitutiting for V in the above equation gives
I = \frac{V}{R} \Rightarrow I = \frac{\frac{Q}{C}}{R} = \frac{Q}{RC}

So we now have an equation for the current in the circuit, but wait, where does this current come from? It’s the capacitor discharging – this current is equal to the rate of discharge of the capacitor, so:
-I = \frac{{\mathrm d}Q}{{\mathrm d}t}
So substituting the above expression for I
-\frac{Q}{RC} = \frac{{\mathrm d}Q}{{\mathrm d}t}

Ooh look, a differential equation.
Seperate the variables giving:
\int -\frac{1}{RC} \, {\mathrm d}t = \int \frac{1}{Q} \, {\mathrm d}Q
\Rightarrow \frac{-t}{RC} = ln(Q) + ln(k) where k is some constant.
\Rightarrow e^\frac{-t}{RC} = kQ
\Rightarrow Q = \frac{1}{k}e^\frac{-t}{RC}

If we define the initial charge to be Q_0 – the charge when t = 0
\mathrm{ let } t = 0 \Rightarrow Q_0 = \frac{1}{k}
so we now can replace \frac{1}{k} giving:

Q = Q_0 e^\frac{-t}{RC}

MY WORK HERE IS DONE

:D

I came across PyWebKitGtk and had to try it.
A browser, in 14 lines.

#!/usr/bin/env python

import gtk
import webkit
import gobject

gobject.threads_init()
win = gtk.Window()
bro = webkit.WebView()
bro.open("http://www.google.com")
win.add(bro)
win.show_all()

gtk.main()

And the obligatory screenshot:

A browser in 14 lines of python using webkit and gtk.

A browser in 14 lines of python using webkit and gtk.

I changed my wordpress theme to something dark so want a new header – why not a blackboard :D

  1. Create a new blank image – since the dimensions of the header are 760×200, I made it these dimensions
  2. Fill the background with a dark greeny colour – I chose #0b1205
    I chose a dark-green colour

    I chose a dark-green colour

  3. Go to filters->render->clouds->fog, set the colour to a light grey – I chose #d2c9b7 – and leave the other settings as they are (turbulence 1.0, opacity 100). This creates a new layer and renders some ‘fog’. Put the opacity of this layer to around 12.0
    I set the opacity to 12

    I set the opacity to 12

  4. Now for the text. Put some text on your blackboard with a whitish (#e7e7e7) font colour. Maybe try a slightly wavey font or one that imitates handwriting. I chose one of the Fell Types Fonts.
    A handwriting font may also look good.

    A handwriting font may also look good.

  5. Duplicate this layer. Now go to filters->map->warp. Leave almost everything as-is, but change the Dither Size to 1.0 (you may want to play around some more, but these settings seem to work).
    You could perhaps play around with these settings a bit more.

    You could perhaps play around with these settings a bit more.


    The text should now look fairly chalky.
  6. Lock the layer you just warped and select the other text layer – the one that hasn’t been warped. Put this below the warped layer. Choose filters->blur->motion blur. Choose Zoom. Set the centre of the blur to the right of your text and set the length to about 15.
    The result of the blur and the settings used to create this.

    The result of the blur and the settings used to create this.

  7. Set the opacity of this layer to about 15. Choose the smudge tool and a fairly large fuzzy brush. Smudge the layer about a bit.
    Just smudge it about a bit.

    Just smudge it about a bit.

  8. Make a new layer, call this border, and put it above all of the other layers. Choose select->all then select->shrink and enter the size of the border you want – I chose 12. Now choose select->invert and fill the resulting selection with a wood texture – I chose wood#1 but you could find a more exotic texture. Cancel the selection (select->none)
    Maybe not the most convincing wood texture, but it was there and I'm lazy.

    Maybe not the most convincing wood texture, but it was there and I'm lazy.

  9. Place guides at the edges of your border – i.e. for me this was at 12 and 188 vertically, 12 and 748 horizontally.
  10. Make a new layer called shadow, and put it beneath your border layer. Make sure snap to guides is turned on (view->snap to guides). Select a fuzzy brush sized about 13 pixels. Set the brush colour to black. Now stroke along the top and left guides. I did this twice for both.
  11. Make a new layer called highlight and put it beneath the shadow layer. Set the brush colour to white. Stroke along the right and bottom guides in the same way as before. This looks too bright, so set the opacity of this layer to about 6.
    Makes it look a bit more 3D.

    Makes it look a bit more 3D.

  12. All done!
    All done!

    All done!

This morning Dream_Team brought up the age-old debate of whether
0.999\dot{9} = 1
which of course it does.

Method 1

\mathrm{let } x = 0.999\dot{9}
\Rightarrow 10x = 9.999\dot{9}
\Rightarrow 10x - x = 9x = 9.999\dot{9} - 0.999\dot{9} = 9
\Rightarrow x = 1
Although this seems fairly conclusive, there is a much nicer (IMO) way.

Method 2

One can treat the infintite decimal expansion as a geometric series.
0.999\dot{9} = 0.9 + 0.09 + 0.009 + 0.0009 \ldots
\textrm{The common difference, } r = \frac{1}{10} \textrm{ and the first term, } a = 0.9
Then it becomes apparent that the value of 0.999\dot{9} is equal to the sum to infinity of the geometric series.
0.999\dot{9} = S_\infty
And for a geometric series with common difference r and first term a
S_\infty = \frac{a}{1 - r}     for explanation see below
So for 0.999\dot{9}
S_\infty = \frac{0.9}{1 - 0.1} = \frac{0.9}{0.9} = 1 Voilà.

This then prompted me to code some haskell, creating types for geometric and arithmetic series, but that post can come later.


Sum of Geometric Series


\textrm{let } S_n \textrm{ represent the sum to }n \textrm{ terms}
S_n = a + ar + ar^2 + ar^3 + ... + ar^{n-1}
rS_n = ar + ar^2 + ar^3 + ar^4 + ... + ar^n
S_n - rS_n = a - ar^n
S_n = \frac{a - ar^n}{1 - r} = \frac{a(1-r^n)}{1-r}

Now for the sum to infinity:
\textrm{if} \left | r \right | < 1 \textrm{ then } \lim_{n \to \infty} r^n = 0
\Rightarrow S_\infty = \frac{a}{1-r}

This almost makes me want to learn APL. Almost.

Just a python script, to print the name of the current desktop. Could be useful to pipe to conky or something.

#!/usr/bin/env python
from Xlib import display, Xatom
dsp = display.Display()
rootwin = dsp.screen().root

DESKTOP_NAMES = dsp.intern_atom("_NET_DESKTOP_NAMES")
CURRENT_DESKTOP = dsp.intern_atom("_NET_CURRENT_DESKTOP")

def get_names():
    names = rootwin.get_full_property(DESKTOP_NAMES, 0)
    names = names.value.split("\x00")
    return names

def current_desktop():
    return rootwin.get_full_property(CURRENT_DESKTOP,
                                     Xatom.CARDINAL
                                     ).value[0]

try:
    print get_names()[current_desktop()]
except:
    print "error getting name"

Requires the python bindings for xlib

This is a short story in Charles Stross’s “The Laundry” series, published on Tor.com

Read it online here
or download it as a pdf here (other formats found by clicking the download link on the left side)

How to set the transparency opacity of a window with Xlib.

Set the _NET_WM_WINDOW_OPACITY property to an integer between 0x0 and 0xffffffff
An example function to set the opacity of a window using Xlib and python:

from Xlib import Xatom
def setOpacity(self, display, window, opacity):
        if 0.0 < = opacity <= 1.0:
            real_opacity = int(opacity * 0xffffffff)
            window.change_property(
                display.get_atom('_NET_WM_WINDOW_OPACITY'),
                Xatom.CARDINAL,
                32,
                [real_opacity,],
                )
        else:
            return

For this to work however, a composite manager of some kind must be running, but xcompmgr will suffice.