Recommend: DBMS By Johannes Gehrke

Hi, I just thought of sharing this book with you all for DBMS concepts. I keep reading this book to keep my basics on track and occasionally use it as reference as well. Here is the link to buy the book on amazon.

For a free e-copy drop a mail to [deepak at decentmind dot com] requesting the same.

-deepak

Posted in General, book | Tagged | View Comments

What am I up to …..

Hey All

all these days, since quite a few months, I have been busy in to things. Things Things and these things. Its proving out to be a introspection period for me.

Realized… how much, is there to learn. Be it programming language, Algorithm or any other technology which I love or the normal human stuff. So much …. phewwww

Apart from usual stuff I have been playing around with latest symfony versions, jQuery and few unconventional stuff , not much of interest. Lately I have developed interest in other frame works specifically ROR, which is quite similar to Symfony in some aspects.

Don’t know why, but these days I think of starting a project every second day, New ideas come to mind and in day time they don’t seem to be valid one. Continue reading

Posted in General, Gyan By Me, developer | Tagged , , | View Comments

Use Javascript/JQuery to Rewrite Amazon Affiliate Links

Just put following javascript at the bottom of the html page on which you would like to re-write/add the Amazon Affiliate ID to all amazon products.
What it simply does is, searches for “tag” in the url and adds the affiliate id to it.

<script type="text/javascript">
$(document).ready(function() {
 
    $('a[href*="amazon.com"]').each(function() { this.href = this.href.replace(/\?.*$/,"") + $.query.load(this.href).set("tag","Your-Affiliate-Id").toString();});
});
</script>

NOTE: Don’t forget add following jquery plugin JS in the header section of your page

As this code chunk is based on jQuery you have to include jQuery library as well on the top.

Put comments if you have any doubts or need help in the implementation.

deepak

Posted in Javascript, Technology | Tagged , , , | View Comments

Doctrine: Magic Finders

Doctrine offers some magic finders for your Doctrine models that allow you to find a record by any column that is present in the model. This is helpful for simply finding a user by their username, or finding a group by the name of it. Normally this would require writing a Doctrine_Query instance and storing this somewhere so it can be reused. That is no longer needed for simple situations like that.

The basic pattern for the finder methods are as follows: findBy%s($value) or findOneBy%s($value). The %s can be a column name or a relation alias. If you give a column name you must give the value you are looking for. If you specify a relationship alias, you can either pass an instance of the relation class to find, or give the actual primary key value.

First lets retrieve the UserTable instance to work with:

// test.php
// ...
$userTable = Doctrine_Core::getTable('User');

Now we can easily find a User record by its primary key by using the find() method:

// test.php
 
// ...
$user = $userTable-&gt;find(1);

Now if you want to find a single user by their username you can use the following magic finder:

// test.php
 
// ...
$user = $userTable-&gt;findOneByUsername('jonwage');

You can also easily find records by using the relationships between records. Because User has many Phonenumbers we can find those Phonenumbers by passing the findBy**() method a User instance:

// test.php
 
// ...
$phonenumberTable = Doctrine_Core::getTable('Phonenumber');
 
$phonenumbers = $phonenumberTable-&gt;findByUser($user);

The magic finders will even allow a little more complex finds. You can use the And and Or keywords in the method name to retrieve record by multiple properties. Continue reading

Posted in Doctrine, ORM, Symfony, Technology | Tagged , , | View Comments

Doctrine ORM : Transitive Persistence

Doctrine offers both database and application level cascading operations.This section will explain in detail how to setup both application and database level cascades.

Application-Level Cascades

Since it can be quite cumbersome to save and delete individual objects, especially if you deal with an object graph, Doctrine provides application-level cascading of operations.

Save Cascades

You may already have noticed that save() operations are already cascaded to associated objects by default.

Delete Cascades

Doctrine provides a second application-level cascade style: delete. Unlike the save() cascade, the delete cascade needs to be turned on explicitly as can be seen in the following code snippet:

// models/User.php
 
class User extends BaseUser
{
    // ...
 
    public function setUp()
    {
        parent::setup();
 
        // ...
 
        $this-&gt;hasMany('Address as Addresses', array(
                'local' =&gt; 'id',
                'foreign' =&gt; 'user_id',
                'cascade' =&gt; array('delete')
            )
        );
    }
}

Here is the same example in YAML format. You can read more about YAML in the YAML Schema Files chapter:

# schema.yml

# ...
User:
# ...
  relations:
    # ...
    Addresses:
      class: Address
      local: id
      foreign: user_id
      cascade: [delete]

The cascade option is used to specify the operations that are cascaded to the related objects on the application-level. Continue reading

Posted in Doctrine, ORM, Symfony, Technology | Tagged , , | View Comments

And I woke up from dream

Sun Nov 21, 2010 7:16 PM : I woke up all of sudden sweating and I can recall saying something, but don’t know what. It was evening time sky was red/brown like any of the summer days. All of sudden meteorite rain started. And meteorites were as big as we could have seen in famous Hollywood movie 12 Dec,2012. The only thing I can recall is my parents were holding my hand and running towards a wall to hide there. At that very moment I could see only few faces coming to my mind. It was all scary.

Then suddenly I received a SMS saying “Talk to kareena kapoor. charges Rs 6/min”, And woke up from dream. What crap some stupid message from service provider.

But I was still lying on the bed and thinking how foolish we are, that we keep running to achieve something in life. I am not saying we should not. When I was in dream I thought of confessing few things to very few people. Like most of us would have to. At that moment I dint feel lonely or helpless as I was with my parents. Now I think what that single thing which gave them so much of courage to save us. And yes with us we had very beautiful little girl just an year old she was standing in between us having no exposure to those silly meteorites. She was smiling then. Wish I could be like her.

I had so much to write but, I have so much to finish off here in this real world of no dreams or only dreams if we agree! :)

deepak

Posted in General, Gyan By Me | Tagged | View Comments

Doctrine YAML Schema Files: Abbreviated Syntax

Doctrine offers the ability to specify schema in an abbreviated syntax. A lot of the schema parameters have values they default to, this allows us to abbreviate the syntax and let Doctrine just use its defaults. Below is an example of schema taking advantage of all the abbreviations.

The detect_relations option will attempt to guess relationships based on column names. In the example below Doctrine knows that User has one Contact and will automatically define the relationship between the models.

---
detect_relations: true
 
User:
  columns:
    username: string
    password: string
    contact_id: integer
 
Contact:
  columns:
    first_name: string
    last_name: string
    phone: string
    email: string
    address: string
Posted in Doctrine, ORM | Tagged , , | View Comments

Symfony Exceptions

In case of error or unauthorized access to, for example, it makes sense to throw an exception. In order to react to the error conditions better, should throw it back on the correct type of the exception and not always a sfException.
symfony offers a lot about this, namely:

  • sfCommandException
  • sfCacheException
  • sfConfigurationException
  • sfControllerException
  • sfDatabaseException
  • sfError404Exception
  • sfFactoryException
  • sfFileException
  • sfFilterException
  • sfForwardException
  • sfInitializationException
  • sfParseException
  • sfRenderException
  • sfSecurityException
  • sfStopException
  • sfStorageException
  • sfViewException
  • sfPluginException
  • sfDoctrineException

If you want then check these exceptions in a functional test, it is not enough to simply write the following:

<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">[...]</span> [...]</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">-&gt;with('response')-&gt;isStatusCode(500);</span> -&gt; With ('response') -&gt; isStatusCode (500);</span>

symfony criticized then the following:

<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">last request threw an uncaught exception EXCEPTIONTYP</span> last request threw an uncaught exception EXCEPTION TYPE</span>

Can avoid this error test, the test criterion “throwsException”

<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">[...]</span> [...]</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">-&gt;with('response')-&gt;isStatusCode(500);</span> -&gt; With ('response') -&gt; isStatusCode (500);</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">-&gt;with('response')-&gt;throwsException('sfSecurityException');</span> -&gt; With ('response') -&gt; throwsException ('sfSecurityException');</span>
Posted in Symfony | Tagged , | View Comments

symfony form field without a label

I was standing in front of the problem that I have a form with only one field. In this case the label of the field has shown no sense. For this reason, it had gone – but how?
The solution is simple. In the configure function of the form add the following:

<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">public function configure() {</span> public function configure () (</span>
  <span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">[...]</span> [...]</span>
  <span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">$this-&gt;widgetSchema-&gt;setLabel('content', false);</span> $ This-&gt; widget schema-&gt; setLabel ('content', false);</span>
  <span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">[...]</span> [...]</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">}</span> )</span>

Where of course “content” is replaced by the name of the corresponding field must be. Even the box is displayed without label.

Posted in Symfony, Technology | Tagged , , | View Comments

Symfony2 WebProfiler

Symfony2 just introduced its WebProfiler, the utility will soon be the favorite of all programmers. Most veterans will recall that five years ago was the first Symfony framework to include a web debug toolbar. This bar displays useful information for debugging applications and provides access to all logs with a single click:

Symfony2 presents its WebProfiler as the great evolution of the web debug toolbar. Whenever you view a page, Symfony2 generates a unique token debug (pictured above, the token is 4c7e59811509c). By clicking on that token, it shows the WebProfiler with all the debug information:

In the menu on the left side you can see the five main sections to the Profiler which now has:

  • Request: displays information about the request and response (parameters, cookies, headers).
  • Exception: if the request has caused an exception, it shows the type of exception, the message from the server and the whole execution trace.
  • Events: Shows the events raised during execution of the application (along with their event listeners) and the events that have been identified but have not come to run.
  • Logs: Displays the same information to log the original debug toolbar.
  • DoctrinePropel: shows the queries to the database and the time taken for each.

Another great features of the Profiler is that it keeps all your information in a database called SQLiteprofiler.db and stored in the directory cache/ in your application. With this database, you’ll be able to consult the entire execution history of your application, which will facilitate the clearance of projects:

If you want to try the Profiler, you need version of the sandbox Symfony2 PR3, which has not yet been published as a downloadable file. Therefore, when you can only download via git:

  mkdir sandbox
 git clone http://github.com/symfony/symfony-sandbox.git sandbox
 cd sandbox /
 git checkout PR3

Now you can try accessing http://localhost/sandbox/index_dev.php

Posted in Symfony, Technology | Tagged , , , | View Comments