All Glory to the Hypnotoad!

Show me the glory!

hypnotoad

Ok, I get it. Make it stop.

When I saw a really neat one line random color generator in a blog post, I saw it as an opportunity to glorify the hynotoad. This is the magic part:


(~~(Math.random()*(1<<24))).toString(16) 

In that line, ".toString(16)" gives us a hexadecimal value. We need to constrain our random numbers between 0 and ffffff, hexadecimally speaking, or 16777215 when converted to an integer. "1<<24" is a fancy and short way to achieve 16777216 using bitwise operators. The double tilde is a shorthand to lop off the decimal places that the call to "Math.random()" gives us. It could also have been achieved using "parseInt" on our random value.


(parseInt(Math.random()*(16777216))).toString(16)

This works just as well, but isn't nearly as cool looking.

Dropping our random color generator into a setInterval produces pleasing results.


setInterval(function(){
  var toads = document.querySelectorAll('.hypnotoad');
  [].forEach.call(toads, function(toad){
     toad.style.backgroundColor = "#"+(~~(Math.random()*(1&lt;&lt;24))).toString(16);
  });
}, 80);

Apply your hypnotoad class to any element you want to begin glorification.

Here's a link to a codepen, if you like that sort of thing

Receiving Emails in Redmine with GMail on Dreamhost

Setting up Redmine to create issues from emails, the way I did it, mostly involved getting a cron job running to rake redmine:email:receive_imap. The basic steps are:

    1. Create a GMail Account
    2. Add a script to run at intervals (I am running it every 30 – */30 * * * *

I created shell script in it’s own file that reads like this:

#!/bin/bash
/home/xxxx/.gems/bin/rake -f ~/xxxx/Rakefile redmine:email:receive_imap RAILS_ENV="production" host=imap.gmail.com ssl=SSL port=993 username=xxxx@gmail.com password=xxxx project=xxx tracker=bug priority=Immediate allow_override=project,tracker,priority --trace

One thing that hung me up was that for ruby gems to be in the path in the cron execution context, you’re crontab needs to look like this:

*/30 * * * * . /etc/profile && /path/to/script.sh

Without the “. /etc profile” part, your script won’t know what the hell a “rake” is.

I can’t get the “assigned_to” default to work, but I’m happy with it running properly for the time being.

Windows 8.1 and Visual Studio

I upgraded my Sony Vaio Pro 13 to windows 8.1 immediately after taking it out of the box. My intention was to use it as a development machine, so I planned to slap Visual Studio 2013 RC on next.

I grabbed the web installer and ran it. It started, ran for three seconds, and promptly crashed. Odd…maybe an issue with the web installer? I grabbed the .iso and mounted it. Same thing. Ok…ok…all part of trying to install a release candidate. I retreated back to the safety and comfort of VS2012. Oh no! Same problem!

At this point I did some googling and found out it has to do with a combination of Windows 8.1 and an Intel display driver. I changed my display driver to the generic one using the device manager and tried again. VS2013 still had issues, but VS2012 worked. I haven’t tried updating my display driver back and launching it yet. I’ll come back to this.

UPDATE
After several Sony and several Visual Studio/Windows updates, the issues are no more.

SVN Repo Admin – Commands to Remember

Things I need to remember about SVN on my server that I use less and less:

Make A Repo:

sudo mkdir /var/svn/
sudo svnadmin create /var/svn/
sudo chown -R www-data:www-data /var/svn/
sudo service apache2 restart

Add a user

sudo htpasswd2 -m /etc/apache2/dav_svn.passwd

document.getElementBy Whatever I Want

During re-factoring of a dreadful legacy app, I often came across javascript like this:

document.getElementById('firstName');

with HTML like this:

<input type="text" name="firstName" />

I was confused as to how this ever worked and made it into production. I always assumed that getElementById would get an element by it’s Id. This is for the most part true. However, in earlier versions of IE, getElementById would also work with name attributes. It’s this kind of “IE Logic” that did immeasurable damage to both development practices and the web at large. Even as a convenience feature, it should not have been used. When a function explicitly says what it does in it’s name, don’t use it any other way.

In hindsight, if you were of the opinion that “we only use IE here so it doesn’t really matter”, you were wrong. It does matter.

Codility

For weeding out developers from fakes, hit up codility.com.

I took the demo test and found it to be a fair challenge. Any developer mid-level and up should have no issues completing the test. They can choose from a variety of languages to complete the task. Hell, their language choice might even be a great topic during an interview.

I have sat through far too many interviews where the candidate had no business even applying – but somehow made it through the phone screens. From now on, CODE MUST BE WRITTEN!

jQuery Font Resizer

First, the CSS:

body, a#medium {
font-size:14px;
}
body.small, a#small{
font-size: 10px;
}
body.large, a#large{
font-size: 18px;
}

Second, the JS:

$(function() {
$("a#large").on("click", function (event) {
$("body").removeClass("small");
$("body").addClass("large");
event.preventDefault();
});

$("a#medium").on("click", function(event) {
$("body").removeClass("small");
$("body").removeClass("large");
event.preventDefault();
});

$("a#small").on("click", function(event) {
$("body").addClass("small");
$("body").removeClass("large");
event.preventDefault();
});
});

Third, the HTML:

<a id="small" href="#">A</a>
<a id="medium" href="#">A</a>
<a id="large" href="#">A</a>

Check it out