Do not go gentle into that good night

Do not go gentle into that good night,
Old age should burn and rave at close of day;
Rage, rage against the dying of the light.

Though wise men at their end know dark is right,
Because their words had forked no lightning they
Do not go gentle into that good night.

Good men, the last wave by, crying how bright
Their frail deeds might have danced in a green bay,
Rage, rage against the dying of the light.

Wild men who caught and sang the sun in flight,
And learn, too late, they grieved it on its way,
Do not go gentle into that good night.

Grave men, near death, who see with blinding sight
Blind eyes could blaze like meteors and be gay,
Rage, rage against the dying of the light.

And you, my father, there on the sad height,
Curse, bless, me now with your fierce tears, I pray.
Do not go gentle into that good night.
Rage, rage against the dying of the light.

Dylan Thomas, 1952

Posted in Poetry | Leave a comment

php WTF

The following code works:

<?php
class TestClass {
    static function test_method($foo) {
        global $x;
        return str_replace('twitter', $x, $foo);
    }
}

$x = 'wibble';

ob_start(
    function ($html) {
        $pattern = '~(<a .*?href=["\'])([^"\']+)(["\'].*?>.*?</a>)~';
        return preg_replace_callback(
            $pattern,
            function ($matches) {
                $y = TestClass::test_method($matches[2]);
                return $matches[1] . $y . $matches[3];
            },
            $html
        );
    }
);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test for whether global variables work</title>
</head>
<body>
<article id="twitter">
<h1>Latest update from <a href="http://twitter.com/markfiend">my Twitter feed</a>:</h1>
<h2><a href="http://twitter.com/markfiend/statuses/304159221711241216">Wed 20 Feb 2013 09:23:04</a>:</h2>
<p>Case sensitivity is IMPORTANT: Consider: "I'm going to help Uncle Jack off a horse" and "i'm going to help uncle jack off a horse"</p>
</article>
</body>
</html>

However this does not:

<?php
class TestClass {
    static function test_method($foo) {
        global $x;
        return str_replace('twitter', $x->scalar, $foo);
    }
}

$x = (object) 'wibble';

ob_start(
    function ($html) {
        $pattern = '~(<a .*?href=["\'])([^"\']+)(["\'].*?>.*?</a>)~';
        return preg_replace_callback(
            $pattern,
            function ($matches) {
                $y = TestClass::test_method($matches[2]);
                return $matches[1] . $y . $matches[3];
            },
            $html
        );
    }
);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test for whether global variables work</title>
</head>
<body>
<article id="twitter">
<h1>Latest update from <a href="http://twitter.com/markfiend">my Twitter feed</a>:</h1>
<h2><a href="http://twitter.com/markfiend/statuses/304159221711241216">Wed 20 Feb 2013 09:23:04</a>:</h2>
<p>Case sensitivity is IMPORTANT: Consider: "I'm going to help Uncle Jack off a horse" and "i'm going to help uncle jack off a horse"</p>
</article>
</body>
</html>
Posted in Uncategorized | Leave a comment

Another fold of the treefrog

This is probably the last in the series of posts based around the frog and its base. See earlier posts: here, here, and here.

Tree Frog. Designed by Robert J Lang, folded by me. (35cm deluxe washi, finished model ~14cm long).

Continue reading

Posted in frog, Origami | Leave a comment

The source code for the @markov_bible twitter feed

A bit of background about Markov Chains might help for a start.

A while ago, I stumbled across a bit of Python for generating Markov Chains here. Basically it takes a large body of text (in this case, the King James Bible from project Gutenberg (although for my purposes I stripped out all of Gutenberg’s preamble, licensing details, book, chapter, and verse numbers etc. leaving just the text)) and from a random starting point of two consecutive words in the base text, randomly pick a word that follows those two words. (So from the Bible example, ‘In the’ might be followed by ‘beginning’, or by ‘sweat’, ‘day’, ‘six’, ‘selfsame’, ‘same’, ‘selfsame’, ‘mount’, ‘cave’, ‘tenth’, ‘first’, ‘third’, ‘tabernacle’…)

Now, I just saved the code from the Agiliq blog as markov.py and in the same path, save the Bible text as KingJamesBible.txt and also the following Python code as markovbibletweet.py:

#!/usr/bin/python
""" Uses markov.py to generate tweet-length texts from the Bible (AV). """

from markov import Markov

class MarkovBibleTweet(object):

    def __init__(self, url):
        "Generate the markov chain stuff first."
        file_ = open(url, 'r')
        self.mkov = Markov(file_)

    def tweet(self):
        "Trim the tweet to the start of a sentence and end of a word."
        twit = self.mkov.generate_markov_text(100)
        while twit[0] not in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
            twit = twit[1:]
        twit = twit[:140]
        while twit != '' and twit[-1] not in ';:?.,!':
            twit = twit[:-1]

        if twit == '':
            twit = self.tweet()
        else:
            if twit[-1] in ';:,':
                twit = twit[:-1] + '.'
        return twit

if __name__ == '__main__':
    m = MarkovBibleTweet('KingJamesBible.txt')
    print m.tweet()

Now this code actually “does the business”, generating the tweet and trimming it to fit into 140 characters. So how do we get this actually posted onto Twitter? The answer lies with tweepy.

To be continued…

Posted in Python | Leave a comment

The Second Coming

Turning and turning in the widening gyre
The falcon cannot hear the falconer;
Things fall apart; the centre cannot hold;
Mere anarchy is loosed upon the world,
The blood-dimmed tide is loosed, and everywhere
The ceremony of innocence is drowned;
The best lack all conviction, while the worst
Are full of passionate intensity.

Surely some revelation is at hand;
Surely the Second Coming is at hand.
The Second Coming! Hardly are those words out
When a vast image out of Spiritus Mundi
Troubles my sight: a waste of desert sand;
A shape with lion body and the head of a man,
A gaze blank and pitiless as the sun,
Is moving its slow thighs, while all about it
Wind shadows of the indignant desert birds.

The darkness drops again but now I know
That twenty centuries of stony sleep
Were vexed to nightmare by a rocking cradle,
And what rough beast, its hour come round at last,
Slouches towards Bethlehem to be born?

William Butler Yeats, 1920

Posted in Poetry | Leave a comment

Frog base extended

Following on from the previous two posts, if you unfold your frog base so that it’s back to a flat square, you will see that the crease pattern looks something like this:

Frog base crease-pattern.

Continue reading

Posted in frog, Origami | Leave a comment

…and from a frog-base to a frog

Take your frog base (see previous post)

1: Fold the four shorter points up inside. 2: Narrow the four longer points with mountain-folds. 3: Reverse-fold the first two points to form the front legs. 4: Reverse-fold the other two points to form the back legs.

Continue reading

Posted in frog, Origami | 2 Comments