Archive for the 'Programming' category

ape is a PHP editor

published on November 06, 2010.

A week ago I started working on a simple editor/IDE for PHP called ape. That's my weak try on creating a reverse acronym as ape stands for - ape is a PHP editor. This is kind of an introductory post into the whole developing process of it, as my intention is to blog about it a bit more :)

Why?

First, to answer the question everyone is giving me when I mention I'm writing ape:

"Why the hell do you do that (to yourself)?“

Programming is fun. Programming is interesting. Programming makes me learn new things. I like having fun and I do this to learn more about programming and having even more fun. I'm writing web applications each and every day, so writing a desktop app requires a different way of thinking and leaving my “comfort zone” (altho, I'm quite comfortable in front of the keyboard hackin’ away code). ape is written in python and pyqt, but again, it's not about the language used, for me it is about programming.

The idea

Netbeans is my main IDE for quite some time now and I love it. I know my way around vim, too. But, netbeans has too many features for my taste - I use SVN, git, (on rare occasions I write them) run unit tests from the console. As for vim, maybe I just don't get it enough, but I feel less productive with it. Debugging PHP apps ends up var_dump-ing things all over the place. So, basically what I want/need from an editor is grouping files into projects, regex search/replace, code coloring & completion and, of course, file editing.

I plan to write a feature a day. On my personal projects I usually want to push out as much code as I can during one day as I'm highly motivated, but this time want to try a different approach. So far I didn't got far, figured out syntax highlighting, opening files from a file browser widget thingy and things like that, but more on that in other posts.

If anyone wants to take a look, the source code is up on github. It is licensed under GNU GPL v2, as pyqt is licensed under it and I don't want to waste my time on figuring out could I use MIT or some other license.

Happy hackin’!

Tags: ape, editor, ide, php, pyqt, python.
Categories: Development, Programming.

A regional PHP community website

published on October 16, 2010.

This week on Wednesday, finally one of my pet projects has hit the Internets! PHPPlaneta.net is alive!

It's idea is to be a community website for PHP programmers from Serbia and other countries from the region. The idea for this website “hit” me somewhere in April or May I think, while I was lurking the interwebs for some, any PHP communities in the region, user groups, anything really, where local PHP programmers could share ideas, news, interests, etc., but found nothing (well, besides 2 bulletin boards and a few of us on Twitter). So, I decided to try and create one.

Of course, this website is only the first step. The purpose of this website is to share news, articles and whatnot with other programmers, something like Mr. Cornutt does on phpdeveloper.org ;) There's not much up there yet, but that'll change soon :) Altho the functionality of the website is pretty simple and I could've put it out in like 2 hours with wordpress, I wrote it from scratch (using Zend Framework of course!), just, well, because I can :D Once I tidy up the code and maybe refactor here and there, it'll be up on github (multiple reasons for putting it up there, but that's for some other post).

I have other ideas for the future, both online and offline related, but first want to put this website on it's feet.

So, here's to a better and brighter future for PHP communities around here!

Happy hacking!

Loading custom module plugins

published on July 20, 2010.

OK, here's a quicky one from the office :P

I was trying to load a Front Controller plugin which resides in app/modules/my_module/controllers/plugins/ and not in the “usual” lib/My_App/Plugin/. I want this plugin to be called in every request and I want the plugin file to be under it's “parent” module.

Here's what I did: added the path to the plugin and it's namespace to the Zend_Application_Module_Autoloader as a new resource type and then just register the plugin in the front controller in an other _init method.

Code is better, here's some:

<?php
class News_Bootstrap extends Zend_Application_Module_Bootstrap
{
    /**
     * Autoloader for the "news" module
     *
     * @return Zend_Application_Module_Autoloader
     */
    public function _initNewsAutoload()
    {
        $moduleLoader = new Zend_Application_Module_Autoloader(
                                array(
                                    'namespace' => 'News',
                                    'basePath' => APPLICATION_PATH . '/modules/news'
                                )
                            );

        // adding model resources to the autoloader
        $moduleLoader->addResourceTypes(
                array(
                    'plugins' => array(
                        'path' => 'controllers/plugins',
                        'namespace' => 'Controller_Plugin'
                    )
                )
            );

        return $moduleLoader;
    }

    public function _initPlugins()
    {
        $this->bootstrap('frontcontroller');
        $fc = $this->getResource('frontcontroller');

        $fc->registerPlugin(new News_Controller_Plugin_Scheduler());
    }
}

If anyone knows a better way for doing this, please do share it with me.

Now back to work. Cheerio.

Honeypot for Zend Framework

published on April 21, 2010.

I just hacked up a little code snippet based on Matthew's Honeypot Wordpress plugin. It's basically just a Validator for a Zend Form element which is hidden from the user via CSS. Cause it's hidden, users won't see it, but spambots will, well, cause they are bots.

If the element is left empty, it's valid, otherwise it's not.

So, here's the code:

<?php
class App_Validate_Honeypot extends Zend_Validate_Abstract
{
    const SPAM = 'spam';

    protected $_messageTemplates = array(
        self::SPAM => "I think you're a spambot. Sorry."
    );

    public function isValid($value, $context=null)
    {
        $value = (string)$value;
        $this->_setValue($value);

        if(is_string($value) and $value == ''){
            return true;
        }

        $this->_error(self::SPAM);
        return false;
    }
}

I add the element to the form like this:

<?php
$this->addElement(
    'text',
    'honeypot',
    array(
        'label' => 'Honeypot',
        'required' => false,
        'class' => 'honeypot',
        'decorators' => array('ViewHelper'),
        'validators' => array(
            array(
                'validator' => 'Honeypot'
            )
        )
    )
);

There. Done.

Happy hackin’!

Toggler

published on February 04, 2010.

At the office we're starting out on a new project, which will require (thanks to our designer) a lot off divs and images and whatnot to slide up and down. All these elements will of course have it's own ID's and classes, so writing one function to slide/toggle them all is impossible, plus the design of these elements is so weird that the built-in animation effects are of no use. So I hacked together my first! jQuery plugin which will hopefully help us with this task.

As I was more inspired to write code, than to come up with names, I called this little fella toggler, a jQuery plugin for togglering elements around…

What it does is actually calling .animate() on the height the top of the element that is to be togglered.

Setting it up is easy: include the jquery-toggler.js script, call the toggler() function on any clickable element and set the rel attribute of that element to match the ID of the element which is to be togglered (clearly, if you look in the source of the example, you'll understand that better than my jibberish).

The default height when the element is closed (togglered up) is 0px, when the element is open (togglered down) is 200px and the default speed of this magical animation is set to 1000 (1 second). You can of course change these by passing them to the toggler({speed:500}) function.

toggler is available at GitHub: http://github.com/robertbasic/toggler</a>

Example is here: http://robertbasic.com/toggler/</a>

toggler yourself out.

Edit Februray 6th: Apparently I completely misunderstood the designer what kind of effect he wants, thus now I changed the code. The new code is pushed to github and the example is updated.

Tags: jquery, plugin, toggler.
Categories: Development, Programming.
Robert Basic

Robert Basic

Software developer making web applications better.

Let's work together!

I would like to help you make your web application better.

Robert Basic © 2008 — 2020
Get the feed