Monday, July 16, 2012

cakephp success is red?

"Why is all setFlash red? Can't we do a success in green?"

Well, yes, just change the successful to look like this.
 $this->Session->setFlash(__('The information has been saved'), 'default', array('class' => 'success'));

This assumes you're using cake's default css.

If, incidentally, you want to bake it ...
copy lib/Cake/Console/Templates/default/actions/controller_actions.ctp to app/Console/Templates/default/actions/controller_actions.ctp and make similar changes to "has been saved" entries (there are two?)

$this->Session->setFlash(__('The has been saved'), 'default', array('class' => 'success'));

incidentally, setting up this custom will break other bakes. If you want to keep the functionality, you can either copy "default/classes" and default/views" or 
ln -s /path/to/lib/Cake/Console/Templates/default/classes app/Console/Templates/default/classes
ln -s /path/to/lib/Cake/Console/Templates/default/views app/Console/Templates/default/views

(I recommend symlinks if possible just in case updates in the templates from source need to trickle down.) 

YMMV, hope it helps someone.

Thursday, July 12, 2012

htaccess to stop rewrite

If you want a .htaccess set in apache to stop rewrite redirect for a certain folder, turn off rewrite.

No, that's it. As long as override is enabled, .htaccess just needs the following:

<IfModule mod_rewrite.c>
RewriteEngine off

Monday, July 9, 2012

Managing Virtualbox Headless

I just copied a virtual machine from a Windows 7 host to an Ubuntu host. It was rather painless:
Stop the original guest vm, copy the folder, set up a new vm, use existing hard drive, and you're up (generally). I was using smoothwall, so I needed to mimic my network configuration, but otherwise, that's about it.

The fun part was the creation of the destination vm on a headless host. Sure, I could learn some command line, but I wanted a GUI. I added Cygwin-X to my Windows 7 box,
startx (opens X)
xhost+ (allows connections to X)

Opened putty with X11 forwarding to my linux box, then in putty

tweak tweak tweak

back in putty
vboxheadless -s vmName &

close everything, go on with life.

Saturday, July 7, 2012

Change RGB to a specific luminance

Perl code to create an RGB from a word/text entry (this is NOT the same as RGB "word colors", such as "blue" or "white")

use Digest::MD5 qw(md5_hex);
my $str = substr( md5_hex("test"), 0, 6);
print "RGB: " . $str."\n";
print "luminance:" . (0.2126*hex(substr($str,0,2)) + 0.7152*hex(substr($str,2,2)) +0.0722*hex(substr($str,4,2)));

This luminance scale is 0-255 (black to white). Divide by 256 for the percentage that you see in online color pickers.

What's with the luminance?
Ideally, you should have 3:1 or even 5:1 contrast to read text, but what do you do when the color is (somewhat) randomly generated and you want to be sure text is legible on the color?

For my purposes, I'm choosing white text on color.
A good cutoff for luminance is about a value of 85.

Based upon the above ratios, if you want to keep the same color (ish), for every 1 point change in green, you'll change red 3.364 (or about 3) points and change blue 9.9058 (or about 10) points. The change in luminance for this iteration is 0.2126*3.3640+0.7152*1+0.0722*9.9058 or 2.14558516 (roughly, 2) luminance units.

Given a luminance x (if given in percent, multiply 256), to achieve luminance y, a way to accomplish that is to take the luminance difference (y-x) and divide by 2.1456 to obtain the change in value of green.

Multiply the resulting change in green by 3.364 to get the change in red and by 9.9058 to get the change in blue to achieve the color with the new luminance.

The code below only executes in your browser and does not send to anyone.
It implements javascript md5
What color is your name?
In my trials, the results seem to be mostly green. If you don't like a given pallet for words, just change your offset for md5. I'm starting on the first character, but it can be shifted practically anywhere down the 32-character MD5 result.

Why MD5? Because it's reasonably assumed to be unique *enough* between random sources. I'm not using it for cryptography, here. This is just used for hex number generation.
<script language="JavaScript" type="text/javascript">
function sc(el) {
 var dest=document.getElementById('colorme');
 var dest2=document.getElementById('colorme2');'#'+el;'#'+el;
 var lum = 0.2126*parseInt(el.substring(0,2), 16) + 0.7152*parseInt(el.substring(2,4),16) + 0.0722*parseInt(el.substring(4,6),16);
 dest.value=el + " lum:" + lum;
 dest2.value=el + " lum:" + lum;
<input type="text" style="width:18em;" onclick="this.value=''" onchange="sc(hex_md5(this.value).substring(0,6))" value="type something and click outside">
<input type="text" id="colorme">
<input type="text" style="color:white" id="colorme2">

Blog Archive