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 :)

    Wednesday, 23 May 2012

    Installing Ruby On Rails in windows machines

    I dedicate this post to my friends who can't afford to buy a mac or not experienced enough to work on Linux machines

    In my virtual box I tried to reproduce the installation of Ruby on Rails on Windows XP.
    Because the framework evolved from my last windows installation I realized that some things have become simpler to install and additional things needed to be installed.

    Here are the steps which are needed to get a ready to enjoy Ruby On Rails environment on Windows machines:

    Download ruby:
    Install it. (The default instalation directory will be C:\Ruby193)

    Download devkit for ruby form this location:
    Install it to c:/Webkit (important that the directory can't contain spaces)
    Put C:\Ruby193\bin and c:\Devkit\bin in your path. (My computer -> properties -> 'environmental variables')

    Run these commands from a newly opened command prompt:
    cd c:\Devkit
    ruby dk.rb init
    ruby dk.rb review
    ruby dk.rb install

    Now you can install rails by doing "gem install rails". (If you previously tried to install anything without having the devkit installed then please empty your ruby gems directories. Usually they are here: C:\Ruby193\lib\ruby\gems\1.9.1)

    gem update --system
    gem install rubygems-update

    rails new hello_world