Saturday, 16 June 2012

Leting your vital javascript functions to do their job when the content changes

Hi Fellow Programmers

In this post I will show you one way to let your pages work as intended even if they are manipulated dynamically.

The problem: When the content of the page changes dynamically, those items are not listened by those javascript functions which were initialized at the time when the page loaded.

At the very first steps every programmer reinitializes only those handlers which are needed by the dynamically reloaded partial. This has some disadvantages. One of them is that if the initialization changes then it is very painful to track back the partials where the initialization need to be changed. Plus, the whole thing need a babysitting process...

I don't want that...

What I want is a structured way, in which is agile and robust enough to handle these issues... :)

Let me show you by code:
window.problemOrNot = { 
  vital_functions: [
      $(".cancel").click ->

  run_vital_functions: ->
    $.each problemOrNot.vital_functions, ->

jQuery ->
And then in your partial, which obviously modifies your dom:
  • <%=j render :partial => 'form' %>
  • "); ... ... ... $('#comment_operations').hide(); problemOrNot.run_vital_functions();
    That's it... The first code was in cofee script, and the partial was a rails .js.erb partial. :) Enjoy

    Thursday, 7 June 2012

    Full Text Search Feature Of Postgresql


    I was using mysql for my development for a long-long time. But I decided to try postgresql as I watched Ryan Bates screencast which showed the fullt text search capabilities of postgresql.

    I was motivated to try postgresql since heroku added a new addon which enables any application to use the lastest(9.1.13) postgresql. And as a bonus the capacity of that DB is unlimited... However I can hardly believe that it will remain free forever...

    I created a new DB on my heroku account for my application and I followed the migration manual and voila. It took me about no more than 15 minutes to transition to a new DB.

    It was a nice experience. :)

    Tuesday, 5 June 2012

    Navigating from controllers to .haml type views in Textmate

    Hi, I made a fix which enables your Textmate to navigate from your controller to your haml type views, using the ruby on rails bundle. Enjoy

    Monday, 4 June 2012

    Advanced git features

    Hi everybody,

    I am using git as source control for a long time ago, and I am happy with what it offers. I presume that the basic git commands are clear for everyone. So in this post I will write about some more advanced git commands which aren't used so frequently but they are invaluable when they are needed.

    -Nice Git log which contains a lot of usefull info:
    git log --graph --all --decorate=full --abbrev-commit --pretty=short
    -Delete the branch 'staging' on remote 'staging':
    git push staging :staging
    -push the branch "newfeature" to the remote "origin":
    git push origin newfeature
    -create a remote branch:
    git push  :refs/heads/new_feature_name
    -list remote branches:
    git branch -r
    -diff between two branches:
    git diff <branchone>..<another branch>
    -create a branch wich tracks a remote branch:
    git checkout --track -b <new_feature_name> <origin>/<new_feature_name>
    -track a remote branch:
    git branch --set-upstream <local_branch> <remote>/<remote_branch>
    -push to a remote:
    git push <remote> <local branch name>:<remote branch to push into>
    -configuring to push automatically to a certain remote branch, without specifying the local branch and the remote branch:
    git config remote.<remoteName>.push <localBranchName>:<remoteBranchName>

    Enjoy and easy your life :)