Nerd News

Loading...

Search This Blog

Loading...

Friday, April 05, 2013

It took me 15 years to learn this about Perl

See my Perl Gotchas Presentation

An ingenious way to find Java on POSIX systems

_java_bin returns the full path to the java executable.

From http://search.cpan.org/~dolmen/DateTime-TimeZone-HPUX-1.04/lib/DateTime/TimeZone/HPUX.pm

our @JAVA_HOMES = (
    '/opt/java1.4',
);

{
    my $_java_bin;
    sub _java_bin
    {
        return $_java_bin if defined $_java_bin;
        $_java_bin = ''; # Default value: java not found (false)
        foreach (
                (map { ("$_/jre/bin/java", "$_/bin/java") }
                     (exists $ENV{JAVA_HOME} ? ($ENV{JAVA_HOME}) : ()),
                     @JAVA_HOMES,
                ),
                (map { "$_/java" } split(/:/, $ENV{PATH}) ),
            ) {
            next unless -x "$_";
            $_java_bin = $_;
            last;
        }
        return $_java_bin;
    }
}


Saturday, March 02, 2013

The rise of Pi

BBC News - Raspberry Pi and the rise of small computers "The Raspberry Pi has led this pack, purely because more than a million of them have been sold since orders started being accepted on 29 February 2012."

 

Saturday, February 16, 2013

A cygwin bug involving directory removal


On cygwin perl (at least), here's a fun bug especially in multi-process scenarios.

1. Open a file for writing. Don't close it.
2. Use rmtree to delete the directory the file resides in. Ignore the error.
3. Close the filehandle created in step #1
4. Repeat step 2 (delete the directory again - it will work this time)
5. Create the deleted directory again using mkpath. The attempt will succeed but the directory actually won't exist.
6. Create a file in the directory created in step 5. Error - permission denied, because its directory doesn't exist.

Friday, February 15, 2013

That feeling you get when their eyes cloud over when you're explaining why a hash of arguments is better than a list of 5 unnamed ones.

Thursday, January 31, 2013

Find the 10 largest directories on POSIX

From: Warren Young
Date: Wed, 30 Jan 2013 21:08:33 -0700


"This script helps me find the 10 biggest pigs on any system with a basic POSIX user environment."

#!/bin/sh

if [ $# -eq 0 ]
then
    dir=.
else
    if [ ! -d $1 ]
    then
        echo usage: $0 [directory] [options]
        echo
        echo "  Prints kb in use in directory; if directory isn't"
        echo "  given, '.' is assumed."
        echo
        echo "  If you give options, they are passed to du, in addition"
        echo "  to the -sk options the script provides."
        echo
        exit
    fi
    dir=$1
fi
echo -n Hang on, finding pigs in
if [ $dir = . ]
then
    echo " current directory..."
else
    echo " \"$dir\"..."
fi
du -sk $2 $dir/* | sort -rn | head -10


Monday, January 28, 2013

Wall Street is Still Kicking our Ass

<quote/> ... The lion's share of America's earnings increases in the past 30 years went to financial engineers -- people whose "skills" cost the rest of the economy trillions of dollars of lost assets and output. How should we fairly compensate those financial engineers? By my reckoning, they owe the rest of us about ten trillion dollars. What sort of skill does it take to give toxic mortgage-backed securities triple-A ratings? The most notable skill of these people was staying out of prison. The link between skills and earnings, always somewhat arbitrary, has evaporated. Robert Kuttner: Obama's Heaviest Lift