I’m probably late, but I just discovered the last.fm app for my Blackberry. I’ve discovered a perfect harmony across several of my devices thanks to last.fm. The first step has been to setup your iTunes to scrobble all your songs to last.fm every time you listen to something. Also, when you connect your iPod to your computer, make sure all those songs you listened to get scrobbled to last.fm. If you’ve got that set up, you can access “Your Library” on last.fm anywhere – any PC, your iPhone, Blackberry, whatever. “Your Library” basically consists of the songs you’ve scrobbled.
So to make a long story short, I’ve got a nice little shuffled list of all the songs I listen to streaming to me on my Blackberry. And there’s no possibility of them giving me a crappy recommendation like Pandora or Slacker Radio can possibly do. If you’ve got everything synced up correctly, you will be on your way to success.
If you want to add me on last.fm: http://last.fm/user/frankspastic
In one of my recent projects, I’ve had to write a ton of recursive functions to iterate through tables whose foreign key references the same table. I’m sick of writing them, but I’ll have to say I’m pretty decent at writing them now.
I almost forgot about this, but I just found out about the Austin Javascript meetup… Thanks to @andyhite for the heads up. I’m pretty excited about meeting some people to discuss this stuff because I’ve been having some pretty bad issues with my applications which are heavily reliant on javascript. The bigger it gets, the slower it gets. Especially with pages that have an incredible amount of DOM elements. I’ll probably update after the meetup to talk about how it went
For those of you who like to see things visually, the newest release of MySQL workbench enables you to connect to your existing MySQL database and reverse engineer it so that you can see the full ERR (Entity Relationship R_____) Diagram in all its glory. For me this is helpful to see when I’m taking over a project I know nothing about. As long as the foreign keys are set up correctly, the tool should be able to do all the work for you. You can also make changes to the Diagram and then have it synchronize with your development/production database. This feature used to be some sort of premium feature that you had to upgrade and pay for, but I just discovered that it’s all included in the free download. I like free stuff. http://dev.mysql.com/downloads/workbench
Screenshot:
After reverse-engineering the existing MySQL database, you can get an ERR diagram that looks like this. Now your job is to nicely organize the tables.
The fact that you don’t have to initialize your variables in PHP makes me a very lazy programmer. With a large scale project that I’ve been working on for the past 6 months, I’ve really paid the penalty for dumb mistakes like not initializing and resetting my variables. So just because PHP doesn’t make you do that stuff, it’s always best practice to do so.
I’m not sure if this is totally correct and I have no fixed way of measuring this (other than that I don’t get any timeout errors anymore) but I’ve noticed a significant difference when choosing between two different methods of string concatenation:
Slow way:
foreach($oranges as $orange){
$orange_str = $orange_str . $orange;
}
Better way:
foreach($oranges as $orange){
$orange_str .= $orange;
}
This is obviously simplified for example’s sake, but I had a situation where I was concatenating several hundred (maybe a thousand) elements to a string and I was receiving a “Fatal error: Maximum execution time of 30 seconds exceeded…”. My best guess is that with the first method, an actual copy of that string is being made in memory so you’re probably taking up twice the amount of memory than you should be. That’s just my guess.
Probably the best example of form validation comes from Jeremy Keith’s DOM Scripting, which is probably the best book I’ve ever picked up. Ever since I read it a little over two years ago, it definitely got me into the loop as far as modern-day javascript is concerned… But anyway, he shows you how to create an unobtrusive way of doing form validation.
Basically all you gotta do is give the field you want to be required a class of “required”. Then in your javascript, you iterate through all the inputs and search for anything with a class of “required”. If the contents of that field are empty, then you put up an alert and stop the form from being submitted. I put my own little twist on it by coloring the border of the field red and alerting the user of how many fields need to be filled in. Since I’ve been a big fan of jQuery lately, i’ve re-done the function in jQuery…
Javascript:
$('form').submit(
function(){
$(this).find('.required').each(
function(){
if($(this).val().length < 1){
$(this).css('borderColor','#ff0000'); counter++;
} else {
$(this).css('borderColor','#ffffff'); } } ); if(counter > 0){ alert("There are "+counter+" fields that need to be completed."); return false; } } );
HTML:
Name*:
Email*:
Sorry the formatting sucks, but I haven’t figured out how to make things look nicely with this Wordpress Code Plugin. In any case, you can totally copy this exact function and use it for your purposes.
So this is pretty straightforward, but the only reason this function has come to my attention lately is because if you’re working on a webpage with oh…. 200+ input fields (i’ve got a page that looks like a spreadsheet), this function is RIDICULOUSLY slow in Internet Explorer 6 and 7. In fact, IE tells me “Are you sure you want to keep running this script?”. The reason it takes so long is that i’m using the class selector $(‘.required’) which actually goes through every single input and checks for the class “required”. It’s nowhere as fast as using the ID selector (an alias of document.getElementByID). So i dunno, I haven’t yet figured out a solution to this. I could definitely narrow down the fields that I’m going through but that seems kind of a hack. I want to be able to say “required” on any field I want to.
Without saying… it’s pretty clear how much faster my page with 200+ input fields performs on Firefox or Chrome… IE sucks. I should re-title my blog to the IE Sucks blog.