As a programmer you're going to be asked to deal with other people's data. Hopefully, it's in a nice easy to use format like JSON, XML, or properly normalized SQL tables. Occasionally, some asshole is going to do something lazy like create a single field that contains multiple values in the same field (I ran into this problem this week) using some kind of delimiter.
PHP has the function explode
that allows you to take an arbitrary piece of text and break it into an array based on a delimiter. For example, if we had the text value1_value2
and we wanted it broken based on the _
we would write.
$values = explode('_', 'value1_value2');
This works well, but if you have to keep referring to those values you either have to use $values[0]
over and over again or save it to a variable. Saving it to the variable is the cleanest solution because it would create an easy to remember name and therefore produce easier to read code. This means our example looks more like this:
$values = explode('_', 'value1_value2');
$values1 = $values[0];
$values2 = $values[1];
This works and it works well but PHP has an even better way to do this in a single line.
list($value1, $value2) = explode("_", 'value1_value2');
It may not make a huge difference in this example but having that one line is a lot better than having line after line of $valuesn = $values[n-1]
.
A cool article about a guy who was able to work for free for a year and travel the world working for different companies. I liked how he was able to distill what he really needs down to just a few things.
http://codeofrob.com/entries/working-for-free-and-what-it-taught-me.html
Due to some issues we had with WP Super Cache not updating our RSS feed we've moved TPT to W3 Total Cache.
Leave us a comment if you run into any problems.
I've been working with using Vagrant on my test Zend Framework 2 project and I was having horrible performance problems that caused my very basic site to take more than three seconds to generate. I did some testing and the same site took a hundredth of the time if I ran it using MAMP. It turns out that VirtualBox's shared folder feature has some performance problems in OSX when there are a lot of files in the directory. Their solution is to switch over to using NFS.
This changes this line:
config.vm.synced_folder "../", "/var/www", id: "vagrant-root"
to:
config.vm.synced_folder "../", "/var/www", id: "vagrant-root", :nfs => true
After I changed this the performance got much better. It didn't match the same page load times as MAMP but it was actually a speed that I can work with. :-)
This isn't supposed to be a problem on Windows but I haven't been able to test this.
In a ZF1 project I'm working on I needed a way to use the same view script for two separate actions. I could have added a second copy of the file to the application but then I would have had to maintain both. ZF has a quick way to switch out the view file inside the controller so I could reused it.
$this->_helper->viewRenderer->setRender('reusedviewfile');
I've been slowly learning out to use Zend Framework 2 and while I was working through some examples I learned there is a cool module called the Zend Developer Tools which adds this really nice bar at the bottom of you screen with information about the page load.
It also adds the database queries but I haven't gotten that far yet.
This is an interesting article about how our brains release Dopamine as we solve problems as we program and how that effects our work.
I found this passage to be very interesting because I have such a hard time doing the boring work at the end of the project like documentation. I now know it's because it doesn't have that puzzle solvingness to it that gives me the Dopamine release like programming a complex algorithm.
This might just be a measure to separate the addicts from the team players: their willingness to do the "boring stuff" that gets the project done vs. their zeal for the "hard stuff" that makes it interesting. Obviously, few people like to do the "boring stuff" involved in any endeavor, but to the programming addict, it's almost unbearable.
http://virtuecenter.com/blog/the_effects_of_computer_programming_on_the_brain.html
There have been a couple cases where I wanted to provide default values to my users on a form and I didn't want to post them in and then have a bunch of validation errors displayed. The quick fix for this is to get an instance of the Zend_Controller_Front
and then you can access the parameters you want.
Zend_Controller_Front::getInstance()->getRequest()->getParam('paramName')
Another excellent post by Scott Hanselman about shit we web programmers do that mess up the way people interact with the internet.
http://www.hanselman.com/blog/StopDoingInternetWrong.aspx
My personal favorites in this list are the giant Interstitial ads, not linking labels to inputs, and the banner that asks you to install the ad (that's actually a "feature" of Mobile iOS). The giant image thing is annoying as well but not something I usually notice on a high speed connection. I actually had a project I took over once where someone used three 2 MB pictures (not much now I know) and the client was confused on why the page loaded so slowly...
I've been trying to embrace the new HTML 5 input types. The one I really love is the date input type. It forces the user to select a valid date and when it posts to the server it's already in the yyyy-mm-dd format so I don't have to do any backend processing to get it into the database.
The downside to this is that it doesn't work in most browsers but it turns out we can easily create a fallback for this using the jQuery UI's Datepicker control. The code below tests to see if the browser supports the date input type and if it doesn't it creates a shadow element that acts like the data input type.
var check = document.createElement("input");
check.setAttribute("type", "date");
if(check.type === "text"){
$('input[type="date"]').each(function(){
var input = $(this);
var newInputId = input.prop('id') + 'Shadow';
input.before('<input id="' + newInputId + '">');
var newInput = $('#' + newInputId);
newInput.datepicker({
altField:'#'+input.prop('id'),
altFormat: 'yy-mm-dd'
});
var split = input.val().split('-');
newInput.val(split[1] + '/' + split[2] + '/' + split[0]);
input.hide();
});
}
subscribe via RSS