Fun With Programming Languages

Tonight, a Facebook thread got a little out of control after I posted a status update that I was “mentally bankrupt.” It was a long day working on client work – a project that is just about done but past due.

After some commentary by Facebook friends, we got to writing little scripts that would take a random selection from a group of adjectives and adverbs and put similar phrases together randomly.

What came of this exercise was a fun little jaunt into a variety of programming languages.

PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
$adverbs = array(
    'mentally',
    'morally',
    'emotionally',
    'socially',
    'psychologically'
);

$adjectives = array(
    'devoid',
    'bankrupt',
    'empty',
    'hollow',
    'vacant',
    'sleeping with fishes',
    'taking a dirt nap',
    'shallow'
);

echo $adverbs[array_rand( $adverbs )] . ' '
    . $adjectives[array_rand( $adjectives )];
?>

Ruby

1
2
3
4
5
6
7
8
9
10
11
adj = [ "mentally", "morally",
    "emotionally", "socially",
    "psychologically" ]

adv = [ "devoid","bankrupt",
    "empty", "hollow","vacant",
    "sleeping with fishes",
    "taking a dirt nap","shallow" ]

print adj[rand(adj.length)] + " "
    + adv[rand(adv.length)] + "n"

Python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import random

def popchoice(seq):
    return seq.pop(random.randrange(len(seq)))

adj = [ 'mentally', 'morally',
    'emotionally', 'socially',
    'psychologically' ]

adv = [ 'devoid','bankrupt','empty',
    'hollow','vacant','sleeping with fishes',
    'taking a dirt nap','shallow' ]

print popchoice(adj) + " "
    + popchoice(adv)

SQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
CREATE TEMPORARY TABLE adjectives (
    adjective VARCHAR (30) NOT NULL
    );

CREATE TEMPORARY TABLE adverbs (
    adverb VARCHAR (30) NOT NULL
    );
   
INSERT INTO adjectives (adjective)
    VALUES
    ('mentally'),
    ('morally'),
    ('emotionally'),
    ('socially'),
    ('psychologically');
   
INSERT INTO adverbs (adverb)
    VALUES
    ('devoid'),
    ('bankrupt'),
    ('empty'),
    ('hollow'),
    ('vacant'),
    ('sleeping with fishes'),
    ('taking a dirt nap'),
    ('shallow');
   
SELECT CONCAT_WS(
    ' ',
        ( SELECT adjective FROM adjectives ORDER BY 1 LIMIT 1 ),
        ( SELECT adverb FROM adverbs ORDER BY 1 LIMIT 1 ) )
    AS RandomStuff;

For PHP Devs, a Twitter PHP Class

At the end of this post, this site is going into a twitter free period of two weeks. I’m sensitive to the fact that we talk about Twitter quite a lot and not always doing a good job of reaching into all of real life like we’d like. So after this post, Twitter will not be mentioned here until June 12. :-)

However, I wanted to get this out the door for devs to knock on and bang out. Awhile ago, I created the dctwits Twitter group and released the generic code. It included a Twitter class created by David Billingham and slightly modified for our use.

A few days ago, I released the WP-Twitterpitch plugin which also used the same class. It’s a very useful class but, to be honest, was a little messy, didn’t support XML and JSON and didn’t have support for all the Twitter API.

So I cleaned it up, extended it, fleshed it out a bit more, brought in Keith Casey as a developer and we’re basically launching the class as a version 1.0-beta today.

I’ll work on documenting things a bit more but there is some basic usage on the site and the code itself is pretty well documented. I need testers to bang on this code and submit issues back, via the Google Code page. Patches welcome as well. And I’d love to see how you use this. You can download direct or via SVN.

When Keith gets done with the DC PHP Conference, we’ll look at pushing it out as stable.