Posted: May 26th, 2011

fizz buzz test.

Category: technical
Tags: , , ,

I ran across this post on reddit.com about some developers who have had some school learnins’and things, they couldn’t even do a fizz buzz question. Now I never heard of this so I decided that I write up some thing that did it. I wrote it up in php and javascript. the javascript portion wasn’t tested though. HA

here is the question they asked on http://www.codinghorror.com/

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

kinda simple I guess. all in the modulus i spose.

php:

echo "<pre>";
$i = 1;
while ($i < 101) {
if($i % 3 == 0 && $i % 5 == 0) {
echo '--FizzBuzz'."\n";
}
elseif($i % 3 == 0) {
echo 'Fizz'."\n";
}
elseif($i % 5 == 0) {
echo 'Buzz'."\n";
}
else {
echo $i."\n";
}
$i++;
}
echo "</pre>";

javascript:

        for(i=1; i<101; i++) {
if (i % 3 == 0 && i % 5 == 0 ) {
document.write('FizzBuzz
');
}
else if (i % 3 == 0) {
document.write('Fizz
');
}
else if (i % 5 == 0) {
document.write('Buzz
');
}
else {
document.write(i + '
');
}
}
Posted: February 2nd, 2011

Zend_Navigation and Routes

Category: technical
Tags: ,

now here’s my take on the Zend_Navigation and routes. Normally you can set a resource class to do this, but I rather do it in the bootstrap. kinda the same thing in my opinion, i decided not to use a xml config but a ini config type, this way you don’t have to worry if your tags are closed properly. if it works for you awesome.


protected function _initNavigation() {
// set up navigation
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/navigation.ini','navi');
$navigation = new Zend_Navigation($config);
$view->navigation($navigation);
return $view;
}


protected function _initRoutes() {
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/navigation.ini', 'routes');
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$router->addConfig($config,'routes');
$front->setRouter($router);
return $router;
}

sample ini file

;put routes here.
[routes]
routes.dashboard.route = "/dashboard"
routes.dashboard.defaults.controller = index
routes.dashboard.defaults.action = dashboard


;navigation
[navi]
dashboard.route = "dashboard"
dashboard.controller = index
dashboard.action = dashboard
dashboard.label = dashboard
dashboard.class = dashboard

Posted: June 12th, 2010

Zend Framework redirect within plugin

Category: technical
Tags: , , ,

if you ever need to redirect w/in a plugin

$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper(‘redirector’);
$redirector->gotoUrl(‘url’);
Posted: November 28th, 2008

php-take 2 dates and find out the rest of the dates in between with do-while loop

Category: technical
Tags: , ,

need a way to find all the dates in between? well this currently works with months. but can be adjusted to do days, years, etc. all you need to do is supply a begining date and an end date. it returns an array which can be used for anything,

function between_dates($begin_date, $end_date) {
    $t = date("Y-m",strtotime($begin_date));
       
    $i=0;
    do {
    $my[$i] = date("F Y", (strtotime("{$end_date} +$i months")));
    $mys = date("Y-m", (strtotime("{$end_date} +$i months")));
    $i++;
    }
    while($mys < $t);

    return $my;
}
Your Ad Here