What am I doing?
Little update in regards to what I've been up to, if you're interested!
It's fairly general knowledge in PHP that if you want the first item of an array, you can use array_shift. However, this also removes the element from the array and this may not be the intended functionality of the developer. Introducing: array_first.
After having dealt with some directory-creation lately based on user input, I decided to safe-guard the creation of directories with the following function: directorize().
Having now had some experience with a multitude of programming frameworks, including CakePHP, Codeigniter, Ruby on Rails, amongst various others, I'm beginning to see a pattern develop within the development community. This pattern involves the seductive nature of well-written frameworks pulling the developer in to it's curvaceous body, so much so that the developer becomes blinded by the possibilities before it.
Always something new to do. This is something I've been wanting to do for quite some time, I'm just finally getting around to doing it as I seem to have a little bit of free time at the moment, which is always good for getting personal projects done.
I had a bit of a stint recently developing some pseudo-theme functionality for a project here at Westfield. During that time, I've discovered a few "gotchas" relating to the view_paths variable within the controller.
After delving around in ruby for a little and finding the magic that is the Array.collect method, I decided to write one for PHP, considering how much I use it in Ruby. Hopefully others will find some use in this function.
<?php
function array_collect($array, $params)
{
$return = array();
if (!is_array($params)) {
$params = array($params);
}
foreach ($array as $record) {
$rec_ret = array();
foreach ($params as $search_term) {
if (array_key_exists($search_term, $record)) {
$rec_ret[$search_term] = $record[$search_term];
}
}
if (count($rec_ret) > 0) {
$return[] = $rec_ret;
}
}
return $return;
}
?>
Basically, what this allows us to do is extract information from an array and have it stored in another array. For example, we may only want a few select fields as a subset of data, we could do this by doing:
$records = array(array('a' => 'y', 'b' => 'z', 'c' => 'e'), array('a' => 'x', 'b' => 'w', 'c' => 'f'));
$subset1 = array_collect($records, 'a'); // $subset1 will be: array(array('a' => 'y'), array('a' => 'x'));
$subset2 = array_collect($records, array('a', 'c')); // $subset2 will be: array(array('a' => 'y', 'c' => 'e'), array('a' => 'x', 'c' => 'f'));
Both in part due to the traffic coming to my blog via the subject line, and also my want to learn a bit more about RSpec model tests, I thought maybe it would be a good idea to throw together a more complicated model test, using RSpec. In this article, we'll look at the various methods you might have as part of... let's say... a vehicle model.
When first learning how to write tests for rails applications (or anything for that matter), using RSpec, probably my biggest stumbling block, was mocking and testing my controllers. There was just so much to take in it was hard to make sense of it all. But, little by little I made progress. In this article I'll go over writing some basic tests for your controller and offer some of the methods you can use to write your tests.
Teachmate.org has open up it's doors and made the website's code opensource. Teachmate is about offering your knowledge to become and online teacher and/or to find people who would be willing to train you in a particular field, check it out: Teachmate. As far as I'm aware, this is one of the few actual websites where they have made their code opensource - this can only be a good thing for the web community! I found this through the ruby on rails google group.
This is part of a 4-part series which will go over the various tests you can write for your models, controllers, views and acceptance using RSpec. My first article will begin with our application models and testing with and without database connectivity.
Don't-repeat-yourself is a common practise amongst developers in order to extend maintainabiliy of their code. However, this usually isn't so straight-forward for CSS. In this article, I explore the various ways we can practise DRY techniques with CSS.
It's a rather convoluted way of getting a blog going, but in an attempt to learn more about web infrastructure and environments, I now own my own server, configured it for web requests and setup Ruby on Rails, along with related software, all just to get Mephisto running. And I'm not done there. This box will now be used for all my personal projects, including running as a UAT/Systest box for my more commercial projects. This is also my first blog post here and will most certainly not be the last, as I write about my frustrations and victories in learning new and wonderful technologies (and some old), as well as tutorials and articles regarding PHP, Ruby, Rails and setting up a web server.