Thursday, November 26, 2009

heart of darkness

that's right, Windows Server 2008. One recurring annoyance (amongst many) is the status of files that are 'blocked' by default ie. cannot be executed or bug you whenever you want to open them.

Normally you will 'unblock' them by getting the file properties in explorer & selecting the 'unblock' button. Bit of a problem in the case of several hundred files in say a webapp installer.

A solution: install sysinternals streams app. This alters the file attributes so as to remove the 'blocking'. Running the following wil recursively fix an entire directory:

streams.exe -s -d blah:\target\directory

JavaScript print (to console): Rhino

Rhino implements the core JavaScript language. There's no DOM in there to simulate a web browser, so to print lines to the quick & dirty JS shell, you have to use it's own print statement:

print("text here"); unlike the typical: document.write("text here");

the syntax here is just the same as building a JavaScript string: "literal text" + variable...

Likewise Max/MSP has it's specific: post("blah"); to print to the max message window.

JavaScript development environment

disclaimer - these postings are quite unfriendly - perhaps I'll edit them into something more readable when they seem to be kind of complete

so I decided to get back onto the JavaScript thing. The purpose of this being to do work for upcoming projects in Max/MSP and some web application stuff (via ajax kind of ways of doing things I imagine).

What it comes down to is re-learning the language (whoops) and the best way to code particular tasks. So I want something 'platform neutral' ie. not to load into a web browser etc just to see if it works...

Mozilla Rhino comes to the rescue: a JS interpreter written in Java - which opens up some nice ideas for embedding, calling Java classes from your script etc. Here, I'm just going to use the JS shell utility as a simple execution shell to call files containing js code. The method of calling it via the command line is a bit tedious, so the following is neaters:

This is the basic setup once the Rhino download is safely unpacked in /opt (& referred to via a link: /opt/rhino.

a) add the rhino jars (js.jar & js-14.jar) to your CLASSPATH.
b) create an alias in your shell:

alias js="java org.mozilla.javascript.tools.shell.Main"
Then you can simply execute a file of JS code with:

> js ./test_file.js

Rhino flags etc should all work etc.

easy. Quick & Dirty.

Wednesday, November 11, 2009

http proxy environment variable

I keep on forgetting this - because it's set and forget. Then you move to new machine, try and run apt or something and...

To use the internets from your shell (lynx,wget, apt or yum from the command-line etc) when located behind a proxy server. Set an env var 'http_proxy' in your profile (.bashrc, .profile etc) - or just set it from a script or command line:

export http_proxy=http://your.proxy.address:proxy-port

if the proxy server wants authentication:

export http_proxy=http://username:password@your.proxy.address:proxy-port
(hmm, password in plain text - make sure your dot files can only be read by self)

My problem is that I tend to forget to add the protocol ('http://') to the above line & then waste some time swearing when it doesn't work. I need to setup more machines, then I'd remember.

Saturday, February 21, 2009

perl one-liner

perl -e 'while(<*.png>){$n=sprintf("%02d",++$i,$_);rename($_,$n."frumpus\.png")}'

append an ascending number to all the files in a directory: ie "27frumpus.png"