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;

Upgrading Ruby on Redhat EL4 for Ruby on Rails Development

We don’t typically use Ruby on Rails in house. Up until recently, I was the dev guy as well as the server guy, the support guy and all the other hats I wear. Since I don’t do Rails development, there was no reason to get it setup. Recently, with the addition of Gary to the b5media team, Rails development became something we do. So I set about configuring the servers for Rails projects (first time for me!) and discovered that Red Hat Enterprise Linux 4 only ships with Ruby 1.8.1. 1.8.2 is needed for Rails.

Nice. The easiest way I found to upgrade to a newer version of Ruby without going through extreme dependency hell, was to follow this really short procedure:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@server ~]# cd /tmp
[root@server /tmp]# wget http://dev.centos.org/centos/4/testing/i386/RPMS/ruby-1.8.5-1.el4.centos.i386.rpm
[root@server /tmp]# wget http://dev.centos.org/centos/4/testing/i386/RPMS/ruby-libs-1.8.5-1.el4.centos.i386.rpm
[root@server tmp]# rpm -e ruby
[root@server tmp]# rpm -Uvh ruby-libs-1.8.5-1.el4.centos.i386.rpm
warning: ruby-libs-1.8.5-1.el4.centos.i386.rpm: V3 DSA signature: NOKEY, key ID 7203f491
Preparing...                ########################################### [100%]
   1:ruby-libs              ########################################### [100%]
[root@server tmp]# rpm -Uvh ruby-1.8.5-1.el4.centos.i386.rpm
warning: ruby-1.8.5-1.el4.centos.i386.rpm: V3 DSA signature: NOKEY, key ID 7203f491
Preparing...                ########################################### [100%]
   1:ruby                   ########################################### [100%]
[root@server tmp]# ruby -v
ruby 1.8.5 (2006-08-25) [i386-linux]
[root@server tmp]#

This routine downloads the ruby libs 1.8.5 and ruby 1.8.5 RPMs from the CentOS testing repository. It then removes the ruby 1.8.1 library (

1
rpm -e

) along with dependencies. This step is done to avoid problems installing the new version.

Pretty standard stuff, but navigating the treacherous waters of RPM and dependencies is something I don’t mind helping someone avoid.