Saturday, December 5, 2009

PHPMyAdmin: Setting up the MAMP environment

Continuing notes to self. Followed the PHPMyAdmin macports installation instructions here.

I couldn't get logged in to PHPMyAdmin. When I tried to log in I got the message "#2002 - The server is not responding (or the local MySQL server's socket is not correctly configured)"

I googled the error and found this helpful thread in the MySQL forums. Amusingly, I found that I had previously had the same problem and thanked the poster almost exactly a year ago for the solution. Memory is short and technology is a long bizarre road.

yes- this works for me. You just have to go into the config.inc.php file and change:
$cfg['Servers'][$i]['host'] = 'localhost';

to this

$cfg['Servers'][$i]['host'] = '127.0.0.1';

Configuring my new MacBook Pro for development

I'm setting up my new —well, used, thanks JB!— MacBook Pro with Snow Leopard for development. I'm using MacPorts for simplicity, but of course, one always runs into something that baffles and confounds.

For future reference and benefit as I struggle through this:

Setting up the MAMP environment for Apache


  1. Don't forget to install XCode before installing MacPorts.
  2. This MacPorts guide is a good starting point.
  3. My first struggle was to get the right Apache launching, NOT the built-in Mac version.
  4. Make sure that the "web sharing" is off in System Preferences. This should be done before installing the apache2 macport.
  5. To check if you're running the right httpd (Apache daemon process) in terminal:
    ps -ax | grep httpd
    you want to see /opt/local/apache2/bin/httpd

    you don't want to see /private/etc/apache2
  6. To get apachectl commands working in terminal, I couldn't get the alias working, I had to add the path to .profile like this:
    export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/apache2/bin:$PATH
    That includes the paths that MacPorts wrote.
  7. To see if you're going to execute the right apachectl, use this command in terminal:
    which apachectl
    and you'll see which one is first in line to execute. Very handy little command.
  8. I couldn't get my virtual hosts working until I edited /private/etc/hosts to assign them to 127.0.0.1 as described here. It wasn't enough to configure vhosts or my username.conf file and include it in httpd.conf.

Tuesday, October 13, 2009

Temporarily locking submit button

Suggested by this example.
I need a temporarily locking submit button because if there's a validation error on the page, the user needs to resubmit. But I need to stop the clickers (slow response sometimes on this server) and give them some feedback.

$(document).ready(function() {
$(':submit').click(function() {
$original = $(this).val();
$(this).val('Saving, please wait...')
.attr("disabled","disabled")
.fadeIn('slow')
.animate({opacity: 0.4}, 4000)
.fadeIn('slow', function() {
$(this).val($original).removeAttr("disabled")
.animate({opacity: 1}, 2000)
});
});
});

My only problem is that it conflicts with the jquery validation plugin we're using: it prevents the error bubbles from displaying when submit is clicked.
If I can reference a validation value then I can check whether this function needs to execute or not.

Monday, July 20, 2009

Brief display of unformatted text while jquery-ui or yui loads

On our new site I was seeing ugly unformatted text for a second while the jquery or yui widget loads. I didn't find anything about how to deal with that, but Michael of Amptools showed me the light.

1. Add style="display: none" to the element. Not in the stylesheet.

2. In the js for the dom event watcher, after the element loads, make it visible, like so:

(function () {
var carousel = null;
setTimeout(function() {

YAHOO.util.Event.onDOMReady(function (ev) {
var carousel =
new YAHOO.widget.Carousel("carousel-element",{
animation: { speed: 1 }
});

carousel.set("numVisible", 4); // override the default
carousel.set("revealAmount", 0);

carousel.render(); // get ready for rendering the widget
carousel.show(); // display the widget
jQuery("#carousel-element").slideDown();
});
},25);
// timeout is necessary for Safari and Chrome.
// Can be increased.
})();

Eclipse crashing when typing $

Eclipse 3.5 has been hanging almost every time I type a "$" character... and that's quite often. Every time this happened I had to force-quite on my Mac. At least PDT fixed that ridiculous "Selection Job Titile" error with this release.

Michael of Amptools kindly posted this bug to the Eclipse project, too. In the meantime I reverted to writing code in TextMate, no hardship there, but no "intellisense" treats either.

After uninstalling, reinstalling, and much gnashing of teeth, I did some more searching and pondering about this error.

This post gave me the clue I needed to deal with this problem.

The problem is solved by changing the Auto Activation code assist to a longer delay.

Preferences->PHP->Editor->Code Assist->Auto Activation

I'm finding that increasing the auto activation from 200 to 1000 is solving the hangs.

Yay!

Friday, June 12, 2009

Smart columns with CSS and jquery

Could be useful...

Smart columns with CSS and jquery.

The thing is, these are all the same height. These aren't columns. They're bricks.

I'm perplexed about dealing with a bunch of floating items of different heights. I'm using the usual float everything left strategy, but it would be cool to try this approach to resize the widths to fit the window nicely.

the problem arrives when the items sort out awkwardly when the longest element prevents the shorter ones from stacking up to the left. The only approach I've come up with is being sure to put the longest elements first.

If one could truly fill up columns with content, flexibly.

Wednesday, June 3, 2009

jquery to show a div depending on values of two selects

Using Jquery:


$(document).ready(function() {
$('select#article-type').change(function() {
var type = $(this).val();
var section = $('#article_sections').val();
(type == '500') && (section > 20) && (section < 40)
// higher education event
? $('#event-info').slideDown()
: $('#event-info').slideUp("fast");
return type;
}).triggerHandler('change');
});

$(document).ready(function() {
$('select#article_sections').change(function() {
var section = $(this).val();
var type = $('#article-type').val();
(type == '500') && (section > 20) && (section < 40)
// lifenews sections 31, 32, 33, 34, 35
? $('#event-info').slideDown()
: $('#event-info').slideUp("fast");
}).triggerHandler('change');
});


The trick of this is finding the value of the other select and using it in the calculations for the change trigger.

SitePoint Mega Menus: my incarnation

Got a great approach to menus from the SitePoint MegaMenu post.

ugh, I wanted to share some code, but looks like code tags are verboten here. I really need to make myself a decent blog.

sigh.

Well, the javascript shows up, sans whitespace indenting, so here you go: (of course you also need the hoverIntent plugin for jquery -- read the article!)

function addMega(){

   $($(this).find("h2")).addClass("hover");
   $($(this).find("div.menu-div")).slideDown("50"); 
   $(this).addClass("hovering");
}

function removeMega(){

   $($(this).find("h2")).removeClass("hover");   
   $($(this).find("div.menu-div")).slideUp("fast");
   $(this).removeClass("hovering");
}

var megaConfig = {    
interval: 200,
sensitivity: 4,
over: addMega,
timeout: 500,
out: removeMega
};

$("li.mega-menu").hoverIntent(megaConfig);

// need this jquery plugin for IE6 to solve Z-index issues.
$(".menu-div").bgiframe();

I can verify that it works great in FireFox, Safari 3 and even IE6.

Tuesday, February 10, 2009

Turtles all the way down

Explained very nicely on Wikipedia.

Apocryphal quote from Stephen Hawking's A Brief History of Time:
A well-known scientist (some say it was Bertrand Russell) once gave a public lecture on astronomy. He described how the earth orbits around the sun and how the sun, in turn, orbits around the center of a vast collection of stars called our galaxy. At the end of the lecture, a little old lady at the back of the room got up and said: "What you have told us is rubbish. The world is really a flat plate supported on the back of a giant tortoise." The scientist gave a superior smile before replying, "What is the tortoise standing on?" "You're very clever, young man, very clever," said the old lady. "But it's turtles all the way down!"
But I like the reference from William James.
William James published a different version in his book The Will To Believe (1898), specifically in the essay "The Sentiment of Rationality" (p. 104 of The Will To Believe in the Dover reprint):

"Like the old woman in the story who described the world as resting on a rock, and then explained that rock to be supported by another rock, and finally when pushed with questions said it was rocks all the way down, -- he who believes this to be a radically moral universe must hold the moral order to rest either on an absolute and ultimate should, or on a series of shoulds all the way down."
This is about the regressive tendency of thought, and our inability to see to the foundations of our premises. A topic dear to my heart.

Worst passwords of all time!

Weak passwords are one of the greatest vulnerabilities in any application or network environment. Not enough people take it seriously.

Here are the top 500 worst passwords of all time.

Oh, and here's an attack dictionary, kindly offered by a commenter to that blog.