Friday, August 3, 2012

What if a company used its workstations to store data redundantly?

Oh, you know those small companies with a shared folder? Not exactly what I'm talking about.

So, let's see... large multinational company with several thousand deployed computers running 4GB RAM and 1TB hard drive apiece and the money is spent on the centralized management of servers to hold the data?

OK, you got me. ... But what if it were possible to leverage all the machines for encrypted, distributed data storage and processing power? It's not just data on your servers, it's data on your network.

What if you didn't really need a server?

But how would you back up?

Same way as normal, probably.

The key is that the data is redundantly distributed, a kind of hybrid of both RAID and torrent, but the workstations don't have to hold *all* the data apiece, just enough of the data to help complete the request if they're a part of the network, with the centralized repository being the key. Of interest, perhaps, is that if the server dies, the data should be aggregately recoverable from the workstations. In theory, if the server dies, the data is still accessible from the workstations, and likely the server's downtime would be unnoticed by the users.

I'm sure someone has thought of this, but if not, something I'm thinking about.

What if, further, the "server" floated CPU between the machines? I mean that the server is a virtual machine in the workstation cloud.

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
</IfModule>

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
VirtualBox

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');
 dest.style.backgroundColor='#'+el;
 dest2.style.backgroundColor='#'+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;
}
//-->
</script>
<form>
<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">
</form>

Wednesday, June 27, 2012

Check All Check None Javascript

A checkall/check none javascript implementation that doesn't care about ASP.

You ready?


  • Check all
  • Check me!
  • Check me, too!
  • Check this third box.
<script type="text/javascript">
function checkall(id,value) {
   var form = document.getElementById(id);
   for (var n=0; n< form.length; n++)
     if (form.elements[n].type == 'checkbox')
        form.elements[n].checked = value;
  return false;
}
</script>
<form id="myForm">
<ul>
<li><input type="checkbox" onclick="checkall('myForm', this.checked)">Check all</li>
<li><input type="checkbox">Check me!</li>
<li><input type="checkbox">Check me, too!</li>
<li><input type="checkbox">Check this third box.</li>
</ul>
</form>
Code markup via quickhighlighter.com

Tuesday, June 26, 2012

Pass a previous value in a select box

Renamed: Set a default select option when normal default is blank.
Let's say you want to do an event on a select onclick ... maybe something like a select with a blank as default, but if it's clicked, you want to change it to some other default (today's month?) ... but you also want that original blank to be selectable to "erase" the entry. This does not require jQuery or ASP. No need for a library to do this. Use it how you want.



    <script type="text/javascript">
        function setDefault(el) {
            if (el.previousValue != "") {
                return;
            }
            if (el.value) {
                return;
            }
            if (el.value == "") {
                el.value = "choose me"
            }
        }
    </script>
    <select onclick="setDefault(this)" onfocus="this.previousValue=this.value">
        <option value=""></option>
        <option value="skip me">skip me</option>
        <option value="choose me">choose me</option>
    </select>
Code marked up with quickhighlighter.com

Blog Archive