Aug. 30th, 2012

You can set variables inside an Apache .htaccess file. To copy directly from someone else's example:

 RewriteCond  %{REQUEST_URI}  ^/category_abc/ 
 RewriteRule .* - [E=cat_id:1] 

 RewriteCond  %{REQUEST_URI}  ^/category_def/ 
 RewriteRule .* - [E=cat_id:2]

 - The E= tells Apache we're creating a new ENV variable. 
 - The cat_id is the name of the variable we're creating 
 - The :x is the value of the variable (simple key : value syntax).

And from another example:

RewriteCond %{HTTP:Accept-Language} ^.*(de|es|fr|it|ja|ru|en).*$ [NC]
RewriteRule ^(.*)$ - [env=lang:%1]
Set lang var to URI
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+)/(de|es|fr|it|ja|ru|en)/\ HTTP/ [NC]
RewriteRule ^(.*)$ - [env=lang:%2]

Environment variables are referenced as %{ENV:varname}. How they are used is another story. There are places you can't use them.

# Make a variable for RewriteBase
RewriteCond "/base_dir/" ^(.*)$
RewriteRule ^(.*)$ - [E=RewriteBase:%1]
# Fails, causes an internal server error.
RewriteBase %{ENV:RewriteBase}

You can't do this either:

# RequestPrefix is a previously declared variable. 
RewriteCond %{REQUEST_URI} ^%{ENV:RequestPrefix}(.*)$
RewriteRule ^(.*)$ - [E=RequestSuffix:%1]

A quick web search finds someone claiming that rewrite condition patterns are compiled before variables are interpreted.

I finally got my Javascript implementation of Craig Reynolds's boids algorithm to work. Here is the relevant code:

var weights= new Array(1.0, 1.0, 1.0);

sepvect = sepvect.multiply(weights[0]);
alivect = alivect.multiply(weights[1]);
cohvect = cohvect.multiply(weights[2]);

I just needed to record magnitudes for one run and fiddle with the weights. (0.5,1.0,0.2) seemed to do the trick, though I should test with different numbers of boids to see if the magnitudes are relative to that variable.

As regards "finally", I started on this so long ago that I forget when and have intermittently picked it up and re-abandoned it since then. The oldest timestamp that I can find for it is 2006, but I think it goes back to 2003 or 2004 when it was going to be something that I would put together during spring break. The biggest problem was a trig error that I fixed last month after having almost fixed it earlier, causing directions to be wrong in one or two of the four quadrants.

While looking through old files, I found a TODO list so old that I've actually done most of the things on it. Usually these things double in size every year. I shall celebrate with a mocha. Details below the cut, if anyone cares. )

Page generated Jul. 8th, 2025 02:33 am
Powered by Dreamwidth Studios