Categories
post

My First Experience at the @OrlandoPHP Coding Dojo

I attended my first coding dojo last night for our Orlando PHP Meetup.

Boy was I confused. In my mind I was thinking the javascript library Dojo. I thought maybe they used Dojo as a front end to a PHP backend, and just did some coding samples. I have been wanting to use Dojo (the javascript library) lately, so that is why if was top of mind.

The coding dojo is interesting. Simply put, it’s like a karate dojo, in the sense that it is a programming practice. Pick a simple problem, lay the groundwork, and start developing. Not start coding. They guys running the group stress good TDD (Test Driven Design) practices, which was great. I heard many people last night say something to the effect that the project will take twice as long, because you are writing twice as much code.

While I feel I am a decent programming and make a living, I realize that there are many new programmers that come to these meetups. It was nice to feel like I was contributing to someone else’s learning. I was able to relay some of my personal experience with spaghetti code that I am working on untangling now. TDD is the best way for me to untangle the mess.

All in all, I prefer the presentations when they have them. I have volunteered to do one (I want to improve my speaking skills). I may not make all the dojo’s, only because I drive an hour each way, however I will definitely contribute to others learning when I can.

Thanks #OrlandoPHP

Categories
post

PHP Fatal error: Call to undefined method PHPUnit_Util_Filter::addFileToFilter() in /usr/local/bin/phpunit

I all of a sudden started receiving this error with no clue why. Numerous posts I read told me that I should downgrade from 3.5 to 3.4, which turned out to be a huge P.I.T.A.

The solution, look for the reason on the system. Turns out, my older version was installed in /usr/local/bin/phpunit, w here as the new version was just /usr/bin/phpunit.

Simply delete the old one, and if necessary, symlink the two together.

Categories
post

Getting Counts For Groupings From Mysql

My dad “beto” asked me about a topic he would like to use on his website.  I decided to share it publicly.

He has a simple select box that stores a “Yes/No/Maybe” option in a table.  He wants to include the results on a webpage.

I have to assume his Mysql table (let’s call it ReunionAttendance) has at least two columns (SelectBoxValue, GuestsAttending).  Adjust the field names for the actual table columns in your table.

There are many ways to do this.  I am going to do it this way for a demonstration:

<?php
/*  Steps needed
1) Get data from table
2) Put data into a variable
3) Display the table via HTML
*/

/* 1 */
$result = mysql_query(“SELECT SelectBoxValue, SUM(GuestsAttending) as Attending FROM ReunionAttendance GROUP BY SelectBoxValue”);

/* 2 */
while (list($comingValue, $comingCount) = mysql_fetch_row($result)) {
$list[$comingValue] = $comingCount;
}

/* 3 */
?>
<div id=”WhosComing”>
<table>
<thead>
<tr>
<th>Coming?</th>
<th>Total</th>
</tr>
</thead>
<tbody>

<?php
foreach ($list as $comingValue => $comingCount) {
?>
<tr>
<td><?php echo $comingValue?></td>
<td align=”right”><?php echo $comingCount?></td>
</tr>

<?php
}

?>

</tbody>
</table>
</div>

Categories
post

BugZilla should be renamed

We use bugzilla internally for so much more than a “bug” reporting system. I have done internal presentations about the product and have jokingly called it OrganiZilla or TicketZilla.

The software offers fantastic Organizational qualities to help us stay on top of tasks. And once you get past the idea of bugs and call them tickets, you realize that there is a much broader use of it.

From updates on a website to telling someone to take out the trash, it works! But only if everyone is on board.

Categories
Programmer's Mindset

PHP User Groups (Orlando and Daytona Beach)

I am a member of two PHP user groups.  Each one runs a little bit differently.  I am looking for feedback from other people in other PHP user groups to find ways we may be able to make these better.

The East Central Florida PHP User Group (Daytona Beach area) is new/restarting.  They have only had one meeting so far, and finally scheduled another a few months later.  They seem to be more geared towards teaching new PHP developers.  While we haven’t done anything so far, they are leaning towards a mentor/student type of group.

The Orlando PHP User Group is quite different.  They lean towards more presentation style meetings.  Someone proposes a topic, and then someone volunteers to be the presenter.  If there isn’t a presentation, then they do some coding in DjangoDojo.  I have not been to a meeting without a topic yet, so I am not sure how those go.  I probably should since I am not very familiar with Django (or Dojo for that matter) at all.

Of the two, I prefer the Orlando version because I am growing my skills.  However, I may like the mentor version because I feel I am a decent programmer and love teaching.

I am looking forward to doing a presentation sometime, because I really want to improve my speaking skills.

How does your user group run?  What is your preference?

Categories
post

Multiple WordPress Blogs in One Installation

I have been hosting multiple wordpress blogs in one installation for a few years now. I like that I can upgrade one installation, and they all upgrade. I don’t have to go through 10 different installs/upgrades.

There are a few things that can be considered either a pro or a con based on your point of view. If one blog uploads a theme or a plugin, it is available to all the others. This doesn’t mean that if one enables it, they all have to have it enabled. It’s just there, so each can install if they need to.

One serious downside is customization. If one blog customizes a template, another blog can’t use it unless they too want that customization.

On to the nitty-gritty, all I do is change the wp-load.php file and copy the wp-config.php file. I copy the wp-config.php to wp-config-DOMAINNAME.php (example wp-config-www.johncongdon.com.php). Each config file changes the database table prefix.

Here is a diff for the wp-load.php file. It just changes an if statement to load our individual config, if it doesn’t exist, it loads the original wp-load.php.

--- wp-load-orig.php	2011-03-07 15:18:12.000000000 -0500
+++ wp-load.php	2011-03-07 10:30:04.000000000 -0500
@@ -24,7 +24,12 @@
 else
 	error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
 
-if ( file_exists( ABSPATH . 'wp-config.php') ) {
+if ( file_exists( ABSPATH . 'wp-config-'.$_SERVER['SERVER_NAME'].'.php') ) {
+
+  /** The config file resides in ABSPATH */
+  require_once( ABSPATH . 'wp-config-'.$_SERVER['SERVER_NAME'].'.php' );
+
+} elseif ( file_exists( ABSPATH . 'wp-config.php') ) {
 
 	/** The config file resides in ABSPATH */
 	require_once( ABSPATH . 'wp-config.php' );

Categories
post

Patching osticket for PHP 5.3

OSTicket is a decent piece of software for customer service. I upgraded to PHP 5.3 and had some problems because they are trying to keep it working all the way back to PHP 4. 🙁

Here is a patch to fix the eregi_replace deprecated errors.

diff --git a/osticket/include/class.format.php b/osticket/include/class.format.php
index 6cbb414..0380268 100644
--- a/osticket/include/class.format.php
+++ b/osticket/include/class.format.php
@@ -78,10 +78,10 @@ class Format {

     //make urls clickable. Mainly for display
     function clickableurls($text) {
-        $text=eregi_replace('(((f|ht){1}tp(s?)://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)','\\1', $text);
-        $text=eregi_replace("(^|[ \n\r\t])(www\.([a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+)(/[^/ \n\r]*)*)",
+        $text=preg_replace('#(((f|ht){1}tp(s?)://)[-a-zA-Z0-9@:%_\+.~\#?&//=]+)#','\\1', $text);
+        $text=preg_replace("#(^|[ \n\r\t])(www\.([a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+)(/[^/ \n\r]*)*)#",
                 '\\1\\2', $text);
-        $text=eregi_replace("(^|[ \n\r\t])([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4})",'\\1\\2', $text);
+        $text=preg_replace("#(^|[ \n\r\t])([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4})#",'\\1\\2', $text);

         return $text;
     }

diff --git a/osticket/include/class.validator.php b/osticket/include/class.validator.php
index 284d7c7..697d99c 100644
--- a/osticket/include/class.validator.php
+++ b/osticket/include/class.validator.php
@@ -126,15 +126,15 @@ class Validator {

     /* Functione below can be called directly without class instance. Validator::func(var..); */
     function is_email($email) {
-        return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$",trim($email));
+        return preg_match("#^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$#",trim($email));
     }
     function is_phone($phone) {
-        $stripped=eregi_replace("(\(|\)|\-|\+)","",ereg_replace("([  ]+)","",$phone));
+        $stripped=preg_replace("#(\(|\)|\-|\+)","",preg_replace("/([  ]+)#/","",$phone));
         return (!is_numeric($stripped) || ((strlen($stripped)<7) || (strlen($stripped)>13)))?false:true;
     }

     function is_url($url) { //Thanks to 4ice for the fix.
-        $urlregex = "^(https?)\:\/\/";
+        $urlregex = "#^(https?)\:\/\/";
         // USER AND PASS (optional)
         $urlregex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?";
         // HOSTNAME OR IP
@@ -149,9 +149,9 @@ class Validator {
         // GET Query (optional)
         $urlregex .= "(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?";
         // ANCHOR (optional)
-        $urlregex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?\$";
+        $urlregex .= "(\#[a-z_.-][a-z0-9+\$_.-]*)?\$#";

-        return eregi($urlregex, $url)?true:false;
+        return preg_match($urlregex, $url)?true:false;
     }


@@ -161,7 +161,7 @@ class Validator {
             return false;

         $ip=trim($ip);
-        if(ereg("^[0-9]{1,3}(.[0-9]{1,3}){3}$",$ip)) {
+        if(preg_match("#^[0-9]{1,3}(.[0-9]{1,3}){3}$#",$ip)) {
             foreach(explode(".", $ip) as $block)
                 if($block<0 || $block>255 )
                     return false;

Categories
post

LESS CSS Strings

I saw a tweet about LESS CSS today that I was able to answer with some simple trials. The question came from @funkatron: “Can any LESS.js nerds tell me how I could use a variable to set a base path for various `url()`s? like `background: url(@BASEPATH/foo.png)`”

The solution was quite simple after some trial and error.

@BASEPATH: ‘/PATH/TO/BASE’;
#element {
url({@BASEPATH}/foo.png);
}

Turns out it doesn’t work in lessc. I use PHP Less CSS. (plessc)

Categories
post

Mobile Website Design

What is mobile web design today? Is there a standard? Or is it just about smaller pages with less images? I don’t do mobile sites very often. With smart phones today, I personally expect the full version. I know I will have to zoom in and out, but I am usually looking for specific information. Do people really do much shopping on mobile?

So many questions. Time will tell.

Categories
status

Git is back in my life to stay this time…

Git is back in my life to stay this time. I have started and stopped using GIT on the same project numerous times. Each time I felt I was using it incorrectly or effectively and in the end I would just stop.

I have picked it back up, and this time started using a script that would take my ‘git log’ entries and put them into MySQL. I then created a report for my boss to be able to see every change I make.

I am the only “tech” here, so nobody has held me accountable in the past. I need to do it myself.