Tuesday, January 12, 2010

Count number of files of certain size


find ./ -size 0k | grep "sess_" -c

This finds the files and directories matching a path and matching a size.
Can use -size +[number]k (above a certain size) or -size -[number]k (below a certain size), or a size match.
Then it pipes that to a grep for the word "sess_" and returns a count.
Helps us count the enormous number of blank sessions that our app is generating on OSX.

Friday, January 8, 2010

Selecting non-distinct rows in MySQL

Got this here.

SELECT *, COUNT(*) AS count FROM tablename GROUP BY fieldname HAVING count > 1

Wednesday, December 23, 2009

To count the number of session files in a directory

count number of session files in a directory:

ls -l | grep "sess_" -c

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.