Friday, May 29, 2009

file timestamp in RFC-2822 format

Creating an RSS feed from a script was pretty straight forward, but I ran into some nuisance getting the file timestamps in the right format:

element pubDate: Schemas validity error : Element 'pubDate': [facet 'pattern'] The value 'Thu May 28 22:53:18 EDT 2009' is not accepted by the pattern '(((Mon)|(Tue)|(Wed)|(Thu)|(Fri)|(Sat)|(Sun)), *)?\d\d? +((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec)) +\d\d(\d\d)? +\d\d:\d\d(:\d\d)? +(([+\-]?\d\d\d\d)|(UT)|(GMT)|(EST)|(EDT)|(CST)|(CDT)|(MST)|(MDT)|(PST)|(PDT)|\w)'.

element lastBuildDate: Schemas validity error : Element 'lastBuildDate': 'Thu May 28 22:53:18 EDT 2009' is not a valid value of the atomic type 'Rfc822FormatDate'.

That's the output of validation from xmllint and the XSD I have... if it's "RFC 822", "RFC 2822", doesn't really matter that much to me...

I finally got ls to produce this output format:


% ls -l myfile --time-style=+'%a, %d %b %Y %T %z' | cut -f6-11 -d' '


The date command has a nice flag (-R) that will print in this format too:


% date -R ; date +'%a, %d %b %Y %T %z'
Fri, 29 May 2009 10:14:53 -0400
Fri, 29 May 2009 10:14:53 -0400


Makes me wish we could just use %s... :-P

Wednesday, May 27, 2009

css sprites for js games

The other day, I started to look at css sprites again.

Imagemagicks' montage command is a groovy way to concatenation images together:

montage  ???1.png   -tile 1x -geometry +0+0 -background none last1.png


Along with some js shenanigans, I was able to write a small bejeweled-like puzzle game.

It's pretty neato! Give it a go!!

Monday, March 23, 2009

feelin' randy!

Shuffle! Chaos! Randomness! Surprise me! How many times... have you wanted to:
  • shuffle a list of mp3 to pass to mplayer
  • randomize a list of background images to eog
  • pick a random file from a directory
Once or twice? OK! These can all be boiled down to reading in lines from stdout, mixing 'em up and spewing them back out in a random order.

Check out this tiny haxe program called randy. It's self compiling:
% wget http://brianin3d-misc.googlecode.com/svn/trunk/random/haxe/Randy.hx
% chmod 755 Randy.hx
% ./Randy.hx
% echo -e "1\n2\n3" | ./randy
1
3
2

I wrote it just 4u!

Wednesday, March 11, 2009

got the macro replacement blues

As crazy as it may seem, I have implemented this type of silly macro replacement stuff about a million times:

public String replace( String message, Object ... argz ) {
int i = 0;
for ( Object arg : argz ) {
message = message.replaceAll(
"\\{" + ( i++ ) + "}"
, arg.toString()
);
}
return message;
}


Basicly it converts something like:

"this is some {0}, Mr. {1}... some real {0}" + "mess" and "Man"

to something like:

this is some mess, Mr. Man... some real mess

The only "tricky" part is that you have to escape the opening curly with a backslash and then escape the backslash with a backslash...

Sigh...

Sunday, March 8, 2009

UpperCamel: compiling haxe to a native executable

UpperCamel is a little program for going back and forth between
camel case and underlined uppercase.

Typically camel case is used for class names, variables, and method names.

Whereas underlined uppercase is used for constants, statics, etc.
     Sample Input     | Sample Output
------------------+-------------------
UpperCamel | UPPER_CAMEL
ThisIsNeatoEh | THIS_IS_NEATO_EH
UPPER_CAMEL | upperCamel
MIX-and-Match | mixAndMatch

Somewhat useful... The main point is to show how to compile haxe to create a native executable:
% haxe -main UpperCamel -neko upperCamel.n
% nekotools boot upperCamel.n
% echo hello_world | ./upperCamel
helloWorld

Neat, huh?
% file upperCamel
upperCamel: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.8, dynamically linked (uses shared libs), stripped
% ldd upperCamel
linux-gate.so.1 => (0x4001a000)
libneko.so => /usr/lib/libneko.so (0x4002e000)
libpthread.so.0 => /lib/libpthread.so.0 (0x4004d000)
libc.so.6 => /lib/libc.so.6 (0x40065000)
libdl.so.2 => /lib/libdl.so.2 (0x401a8000)
libgc.so.1 => /usr/lib/libgc.so.1 (0x401ad000)
libm.so.6 => /lib/libm.so.6 (0x401e1000)
/lib/ld-linux.so.2 (0x40000000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x40207000)

The code for UpperCamel.hx has a bit of shell script which makes it easy to compile for Unix-env type folks:
% wget http://brianin3d-misc.googlecode.com/svn/trunk/UpperCamel/UpperCamel.hx
% chmod 755 UpperCamel.hx
% ./UpperCamel.hx
% file ./upperCamel
./upperCamel: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.8, dynamically linked (uses shared libs), stripped

Haxe to binary executable is a nice path for whipping up custom commands when you need them with a really low price of admission!

Go, Haxe!