Monday, March 7, 2011

Symfony2 (first) impressions

tldr: Symfony2 is a good 5.3 php mvc framework which is yet to gain dev buzz


I started using it around PR2/3, wanted to learn something new, had a side project for it, so gave it a try. The catchy & humble sentence “were standing on the shoulders of giants” on dev Symfony2 homepage (http://symfony-reloaded.org/, removed by now :(), which resembles the philosophy behind it, should add that those freaking giants were running at times in my case :) Here are my impressions in a Mind\Dump() manner:



  • twig, like a lot its blocks/extensions. Overall is extendible & a solid template
    engine, would use it without Symfony2 as well

  • asset management is nice, powerful filters

  • once I got used to Services Container & Dependency Injection, it was much easier to develop with it (havent written a singleton since:)

  • Doctrine2 based model layer , upvote

  • powerful debugging features in Profiler yet you will need a php debugger, easier to see what happens under the hub

  • form component: I gave it hell, implemented a multi page wizard form for a rather complicated object model (still need to finish validation tho), its insurance stuff so you can imagine. Once I figured out how it is meant to be used in complicated scenarios (sub-sub forms & request objects), I became a great fan of it.

  • symfony-bootstrap should get more love / awareness

  • if you are into Symfony2 on Debian/Ubuntu

  • community & contributors are the strong side of the project, code lives on github which provides a healthy ecosystem for open source projects.

  • Symfony2 console is handy for development / deployment / maintenance

  • documentation / tutorials are improving lot lately. I got an interesting browser url shortcut while it was located under http://docs.symfony-reloaded.org/master/ it was simply “master”, Symfony2 teaches you to be humble :), it can beat Google Analytics shortcut tho...

  • I learned a lot from FOS/UserBundle , Lichess , ForumBundle to name a few. These bundles can be as good as any cookbook / reference.

  • if you used an mvc framework ever before there wont be big surprises



Symfony2 is a strong contender for “next generation php framework” tag. Will be interesting to see its bundles in 6 month from now when more developers adapt it . Would definitely use it in future projects.


p.s.Its good to see activity in php world that couldnt be made fun of on reddit/hackernews

Sunday, February 13, 2011

Few thoughts on #elopocalypse

It was interesting to see how Nokia partnered with Microsoft few days ago on using Windows Phone 7 on their next generation smartphones instead of their homegrown (well almost as they partnered with Intel on it, but Maemo, its foundation, is theirs) MeeGo platform. There was instant community uprising (look at #elopocalypse & #feb11 tags on twitter). 1000+ Nokia devs hit the streets of Tampere (quite unusual behaviour for geeks)

Why is it a big deal?



Microsoft buys a potentially large market share for Windows Phone 7 by knocking out a potent competitor MeeGo. With this move Nokia degrades itself to pure hardware manufacturer (with a strong patent portfolio), giving up its Ovi store and other aspirations.
It will be rather cold out there for them (just look at competition Samsung, HTC, ZTE, LG to name a few), and we saw how successfully they coped with them earlier... I am sure Windows Phone 7 is a usable platform & Microsoft will do everything doable to make it even better to be able to catch up with Android. On the other hand MeeGo is a linux based OS where you could reuse the linux stack (like install a webserver on your phone if that is what you need), backed by excelent Qt, technically the most advanced stuff in mobile atm.

How miscommunicated by Steven Elop & his team



I mean seriously, you dont mention any words that can even be even associated with "disaster" to be able push trough a deal you made. I think he is simply not competent enough to lead a company level of Nokia, regardless of how good/bad the deal itself is.

Consequences



The price of Nokia shares went down by 13.97% instantly (almost 5B $). Guess it will be even harder to communicate to shareholders, really hope that Mr. Elop will prepare better this time. Nokia receives a yet undisclosed amount of cash from Microsoft measured in billions of USD. Microsoft has started seriously investing in mobile, and their war chest is not small. Nokia holds lot of patents in mobile arena, is still a strong brand so from Microsofts side perfect strategic partner.

Community?!



When Google released Android they did everything possible to attract 3rd party developers & make them adapt their platform & write apps for it (copy-paste idea from Apple). These developers are early adopters, show their phones & apps to friends, they blog about it etc. & the whole thing will get traction soon. So in short a valuable asset.

What Nokia did? They encouraged thousands of devs that MeeGo is the way to go, the guys invest serious time in it and suddenly burning platform & cold sea. Now if you invested & lost time on Nokia lie would you be early adopter in second round/any rounds. Thats just bad karma which I dont think Nokia needs.

Sunday, October 3, 2010

jQuery webcam plugin


Because of finds like this jQuery plugin is worth `wasting` so much time on reddit.


With jQuery Webcam plugin, a global object window.webcam is available, which provides the following methods:



  • capture()

  • save([file])

  • getCameraList()

  • setCamera([index])



Cant wait to test it with red5 stream capture stuff.

Wednesday, February 24, 2010

PHP: __get && isset


Encountered strange behaviour with php today. If __get is implemented in a class (to provide some properties that are calculated on the fly for example), isset returns false for mentioned calculated properties.



Check out this simple example


class exampleA
{
    __get($property)
    {
        return ($property == 'calculatedProperty')
            ? 42 //do some resource heavy calculation, like meaning of life
            : false;
    }
}
isset($exampleA->calculatedProperty) === false


This is not a bug but a feature according to PHP staff. Btw there is rationality behind it, as there is a __isset in place.

This should work


class exampleB extends exampleA
{
    __isset($property)
    {
        return ($property == 'calculatedProperty') ? true : false;
    }
}
isset($exampleB->calculatedProperty) === true


Maybe this is obvious to everybody, it surprised me at first run, but its correct behavior.

Tuesday, February 2, 2010

Debugging PHP with NetBeans & Xdebug & Ubuntu

It was almost impossible with my config to get working Zend Studio debugging, I think I achieved it once over the years, but it crashed my apache often, so wasnt that good solution neither. For development environment I use ubuntu/debian, vhosts with mod_rewrite, therefore need remote debugging.

Useful links info :

* Configure Xdebug in NetBeans
* Netbeans debugger in general


I had Xdebug set up and NetBeans fully supports it so gave it a try.

in Project Properties->Run Configuration, advanced button

- added Server path/Local path mappings for project ,
- debug Url set to "Ask every time", because I was about to debug remote mod_rewrite urls

For some odd reason, it wasnt working out of the box, Xdebug and NetBeans wasnt communicating well (it probably will work for you out of the box, my machine is cursed :), nothing "easier" that debug the debugger... needed some info

Edited /etc/netbeans.conf and changed php dbgp debug level:

netbeans_default_options="-J-client -J-Xverify:none -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J-Dsun.java2d.noddraw=true -J-Dorg.netbeans.modules.php.dbgp.level=400"

IDE debug log is accessible at (with output from dbgp): View->IDE log,

Xdebug logs location is at xdebug.remote_log defined in your php.ini

It turned out that it had something to do with my xdebug settings in php.ini. My final settings are:

zend_extension="/usr/lib/php5/20060613+lfs/xdebug.so"

xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_log=/var/log/xdebug.log
xdebug.extended_info=1

And it finally found my break point, on custom remote url, hurray :) Long live NetBeans & Xdebug

PHP IDE: NetBeans 6.8 vs Zend Studio 7.1

Little bit of background: I use Zend Studio since version 5.5 and it was released long time ago, I dont even remember the year :). Main point of sticking with Zend was that I am used to eclipse, how it works & its shortcuts/shortcomings. Its a good IDE although it has its dark sides.

It was "interesting" from Zend that with every new major release you got a worse product, until the first minor releases fixed up the bugs (do they even have QA?). Same was with version 7. I got to the point that even autocompletition wasnt working, indexing was still slow as hell, not to mention "luxury" of debugging ... Was thinking is this really that much better than vi :)

Looked around and installed NetBeans 6.8, because read good things about it. Will try to cover my impressions in order of appearance.

  • Marks svn changeset in editor : it has a green bar beside line numbers that shows changes done to working copy, usefull little feat
  • Fast : indexing is remarkably fast (have I mentioned that I come with Zend Studio background :)
  • Code completition working: shouldnt be that big of a feat, if it was working correctly in Zend Studio 7.1, this is what differs an IDE from a really complicated text editor.
  • Eclipse keymapping as option. pleasant surprise, obviously they have encountered similar people as me :)
  • Search & Replace: more convenient on multiple replace runs on same selection (no direction problems like in Zend Studio), was minor but annoying, who encountered it will know what I talk about :)
  • Syntax checks in HTML/JavaScript are better in Netbeans (spotted quite a few errors made in Zend Studio), especially with non standard markup (like Flexy templates)
  • Double clicking selection of strings sometimes selecting slowly/rarely not selecting/sometimes need multiple double clicks in Netbeans, minor but this is better in Zend Studio
  • PHP source formatting is more customizable in Zend Studio, HTML/JS formatting was better in NetBeans
  • Working debugger in NetBeans (details of setup)

Summary


I am using Netbeans 6.8 as my PHP IDE, have I mentioned that it is free?

Saturday, August 29, 2009

Welcome back gift for a colleague :)

My brother and some of his friends prepared a nice welcome gift for a colleague while he was at holiday. It took few hours of fun, 90m of aluminium foil and a good idea.

The stage is set and a webcam is installed to record his reaction when he arrives (will post the url once it happens).











Saturday, April 4, 2009

Solution for content duplication

The content your site publishes are often reachable trough multiple urls. It happened to me while using Horde_Routes (which is really nice way to organize your urls with Seagull), and there weren't easy workarounds (http redirect is not a too nice solution)

This could cause you problems with search engines, because "score" of that particular content are spread trough multiple urls. Your content gets lower relevance in search results which is definitely not what you want.

Now there is a nice solution for this issue called : cannonical URL link

Basically you just have to add
<link rel="canonical" href="http://someurl/comes/here" />

to HEAD section and you are done. It will tell the search engines which url to associate with content. All major search engines support canonical url links.

With Seagull you have to modify www/yourtheme/default/header.html and add a line like

<link flexy:if="canonicalUrl" rel="canonical" href="{canonicalUrl}" />

which means that if you set $output->canonicalUrl in your controller it will find its way to search engines

Monday, March 23, 2009

Mysql spatial extension

I must be the only one around who didnt knew that mysql spatial extension exists... It is a life saver if proximity based search is to be implemented. Without it you would have to calculate lat/lang ranges that are within some distance of base point (was there, you dont want to), which is rather costly operation, not to mention that this stuff allows to tell if points are inside a polygon or whatever, so good to know its out there, wont forget it next time I encounter some google maps/kml related stuff...

Has anyone used it? Performance?

Thursday, October 23, 2008

Remove index.php from urls in Seagull with mod_rewrite

To make Seagulls urls even more SEO friendly, you can "remove" index.php from them. It could be done relatively easily with Apache`s mod_rewrite module.

Example of functionality:

http://www.example.com/index.php/default/maintenance/
=>
http://www.example.com/default/maintenance/

Apache configuration

You need to enable mod_rewrite module first. Then you have to make decision where to keep your rewrite rules. Options are : global httpd.conf, virtualhost or .htaccess files. I dont suggest .htaccess files as apache should check them for every request, and with higher load you dont want it. I keep rules in virtualhost files. Lets see an example:

/etc/apache2/sites-available/www.example.com

<virtualhost *>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/example.com/www
ServerName www.example.com
<Directory /var/www/example.com/www>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [L]
</Directory>
# RewriteLog /var/log/apache2/example.com-rewrite

ErrorLog /var/log/apache2/example.com-error_log
CustomLog /var/log/apache2/example.com-access_log common
</virtualhost>

The rewrite rules are set on same directory as document root.

For each request:
- check if the requested url is an existing file
RewriteCond %{REQUEST_FILENAME} !-f

- If its not a file, prepend index.php.
RewriteRule ^(.*)$ index.php/$1 [L]

Save config file & reload apache in order to use newly set up rules

You can test if the rewrite rules function properly by simply typing in few in your browser without index.php.

Seagull configuration

Next step is to change how Seagull generates links because we dont want index.php in our links any more. You have to edit Seagull config file located in <install_dir>/var/www.example.com.conf.php , and set frontScriptName to an empty string:

$conf['site']['frontScriptName'] = '';


You can find out more about this at:
Seagull Wiki

Monday, September 8, 2008

Move made, Ubuntu hardy heron installed

Finally switched from Win XP to Ubuntu, and got around with it. It was a long delayed step because most of my stuff worked nicely with Win Xp, but lets admit other OS`s handle better scripting :) OS install went fine, and the core system was in place really soon. Had some hard times with downloading medibuntu packages, but mostly because of my ISP i guess.

Most of my dev environment up and running, with minor fixes.

ZendStudio for Eclipse produced some nice error message when it was trying to build a Seagull based project but there is a RC of editor (ZendStudioForEclipse-6_0_1_1RC1) that has fixed cause of it.

Have set up apache for my existing vhosts for apache2, mysql. Made Navicat running trough wine along with Safari. Havent had problems with wine, no freezes. But firefox 3 produces really strange behaviours like 100% CPU usage, and show big apetite for memory, could be caused by firebug tho.

What still remains to be done is getting IE browsers running for testing purposes, trough ies4linux . Should install some Photoshop as well, hope that there are no problems with it.

More or less everything is working in order, and can use my existing data from ntfs partitions.

Interested to see how we will get along :)

Tuesday, June 24, 2008

jQuery form plugin data manipulation

jQuery form plugin is a great piece of code, and if you are working with ajax forms its your best friend. The basic usage of it is excellently explained of their site.

It happens from time to time that you have to serialize/create some values into a hidden form field and extract the data on the server side. I came up with a solution to avoid this unnecessary serialization/deserialization.

You can provide your custom code in beforeSubmit callback. It works like this:

beforeSubmit: function(formData, jqForm, options) {
jqForm.find('select[@name=listItems]')
.children()
.each(function(){
formData.push({
name: 'aListItems['+$(this).attr('value')+']',
value: $(this).text()
});
});
}


This code snippet would find a select field named 'listItems' within the posted form and convert all of its options into an array that gets posted to server side (and there easily accessible trough $_POST from PHP).

formData parameter of beforeSubmit callback is an JS array that contains all the fields of the form, and as it is passed by reference you can add your custom fields to it, and form plugin will see them as parts of the form. jqForm parameter is a reference to jQuery ajaxForm object, so you can use it to extract data.

This solution should work for any type of data manipulation before the form submit.

Saturday, June 14, 2008

Moving select options with jQuery

I wanted to move select options up/down on a click of a button. The following jQuery snippet does exactly that, if you want to put in some moveby variable (delta) execute this stuff within a for loop

#UPDATE My implementation was valid ages & jQueries ago, thanks to imants.horsts for updated solution

$.fn.moveSelectedUp = function() {
var selectedOptions = $(this).selectedOptions();
var prev = $(selectedOptions).first().prev();
$(selectedOptions).insertBefore(prev);
}

$.fn.moveSelectedTop = function() {
var selectedOptions = $(this).selectedOptions();
var first = $(this).children("option").not(":selected").first();
$(selectedOptions).insertBefore(first);
}

$.fn.moveSelectedBottom = function() {
var selectedOptions = $(this).selectedOptions();
var last = $(this).children("option").not(":selected").last();
$(selectedOptions).insertAfter(last);
}


This solution is tested in FF3 & IE6/7, should work elsewhere as well

Thursday, June 12, 2008

My Grandmother

My Grandmother (aged 83) today gave me a call. Nothing special, from her mobile phone (she prefers large letters, and better display because she sends SMS`s daily). The interesting thing is the she saw the german army occupying Serbia from her workplace, the time when only few of them had radios and tv sets (with sometimes watchable single demo channel) were a rarity. She called to alert me on a new virus on the Internet?! I wonder about what is left for us to see

Saturday, June 7, 2008

indexOf function JavaScript arrays & IE6/7

Here is a hidden gem : Javascript in IE6 & IE7 DOESNT support Array.indexOf function

So if you are getting some "unknown property or method", open the script debugger (a joke for itself :)) and it hangs on a line with call to indexOf dont despare here is the fix (even better joke that is comes from Mozilla :)

add Array.indexOf for IE6 & IE7

Wednesday, June 4, 2008

JSON embedded HTML in TBODY

This is a short one but really odd.

Scenario:

Have a table with tbody element, have an ajax provider that dynamically generates rows for this tbody, pretty simple.

Ajax request (jquery), expecting JSON result with embedded HTML in an array. If there is comment in HTML, jQuery produces unexpected behaviour (strip some unnecessary tags like tr`s, td`s which is really really ugly). Solution is to remove comments from HTML that you plan to deliver this way.
The optimistic programmer thinks the hidden traps are found, but IE6 produces 'unknown error on line 11' with code

$('#id_of_tbody').html(ajax_response);

After some desperation found out that according to msdn some elements are read-only for IE, among them tbody (nice DYNAMIC Object Model), so .innerHTML is not usable, my guess is that jQuery`s .html() function uses it in background.

The solution is

$('#id_of_tbody').empty().append(ajax_response);


What a nice day to be a programmer :) My mother told me I should be a fisherman, but they have to wake up early (and protest on the streets against high prices of fuel)...

Monday, May 26, 2008

Seagull Vote module

Just a few toughts about coming Vote module for Seagull

- handle various voting capabilityes of Seagull php framework.
- support/accept votes from users || other modules
- every voting can be executed within different context like grouping by module ('cms','publisher',... )
- support for implentation of custom voting strategies
- ip && user based logging of votes
- a basic voting algorithms (OptionSelect and Bayersian avarage ratings)
- blocks for displaying voting results (support for jQuery)
- voting results retrieval trough XMLHttpRequest calls (template based results)

Currently I am almost finished with DAO part and Voting strategies, thinking about JSON like configuration parameters for voting strategies. But back to work :)

Tuesday, April 29, 2008

jQuery UI tabs and jMap with Seagull

Today I came accross a weird problem while tried to put together a pimped-up profile page with jQuery tabs and a google map inside one of tabs.

jMap is a jQuery plugin for handling Google Maps.

UI is user interface plugin for jQuery which among others handles tabbed controlls.

Problem :
If you embed a jMap map inside a UI tab the map wont be rendered correctly (it isnt centered correctly, some sections of map wont be loaded). When you place the div containing the map out of the tab it loads just fine. Obviously jQuery magic goes wrong somewhere, as the map is functioning correctly, you have controlls and if you move it around it loads some (not all visible) sections so it must be some width/height/padding/margin but I wasnt able to debug what is going on in the background, too much things happen at once.

Solution:
It DOES matter in which order you set up jQuery objects. First you have to set up the map, then set up UI Tabs and it works like a charm.

The code should be something like this (if you wander about {} enclosed stuff which are not JSON notation, its how you can reference php variables in JS with Flexy in Seagull):

{scriptOpen:h}
$(document).ready(function(){
$('#map').jmap('init', {
mapCenter:[{aGeoCodes[longitude]},{aGeoCodes[latitude]}],
mapZoom: 15,
mapShowjMapIcon: false
});
$('#map').jmap("addMarker", {pointLatLng:[{aGeoCodes[longitude]},{aGeoCodes[latitude]}]});
$("#tabbedProfile > ul").tabs();
});
{scriptClose:h}


Hope this helps to someone suffering from same (d)effect to save a bit of debugging.

Thursday, April 17, 2008

Seagull CMS first impression

Today I gave a Segaull CMS module (1.3) a try. Was interested about its features, and what benefit it has over Publisher module, which is a bit aged cms solution for SGL, and is it ready for production use without any tweaking.

CMS beats Publisher in almost every aspect (faster, smarter,more configurable), so it could be a solid solution if you dont need multilingual support (although it could be around the corner, but I dont know how far the corner is :). Publisher has multilingual support on the other hand.

CMS supports: types & attributes of content (nice feature), versioning (although I couldnt figure out how can I select the version of the published content, but maybe that is my bad). Give the wiki a try for more details.

Found a small bug in category management (images for TreeView are not referenced correctly) nothing serious, another one in navigation (add a page that is link to content, save and try to edit it, it doesnt fill the edit form correctly) more serious a bit, but there is workaround, fill everything again on edit :).

It has some really nice AJAX interface, so things are kept simple yet usable.

The next step will be to use CMS functionality to store user generated content like CV-s etc, interested in how it could be used along with other modules, but I am sure that it will perform well.

Only few things are there that are making me to stick with Publisher:
- the code comes obfuscated with community version, and sooner or later I will need some customization (though that can be done by extending cms classes),
- multilingual support (most of sites done are not english on my side), lack of it is showstopper atm
- still have some environments with php4 installed, and CMS requires 5.2, but if I make serious threats to root on host he will upgrade for sure, as all such upgrades have to be done sooner or later as php4 is not supported any more, and I am the root...

So Demian and Julien did a great job as CMS module is getting mature CMS solution. Cant wait to see how it develops further.

Friday, March 28, 2008

Milestone achieved finally...

After some heavy coding finally put together a Seagull based Feeder module`s first milestone (will publish it soon somewhere), it is working on RSS atm, but soon it will evolve to other feeds as well. It has autoUpdate where updateable feeds are ordered by bayesian rating, with limits etc. It maps discovered Items to a generic Content class, so it will be a great content provider. I am really excited about it, and cant wait to see it in production which is yet to come. Next steps include caching, and a bit refactoring, as the project evolves. It should be a news aggregator service, with some fresh ideas, but basics should be done first :)