Monday, 1 April 2013

Editing the code with the speed of thought


I changed my code editor from Textmate2 to Sublime. A friend of mine told me about it and I was so curious that I needed to try it. I started to love it right in the first moment mainly because of the existence of the command palette and its modular feature approach and the multiple editing feature.

The command palette was for me like some sort of help combined with a quicksearch-autosuggest menu. When I thought to something I would do I typed in and if I had luck then the feature was already there. If not then I needed to search for a suitable package which did the desired functionality.
I saw a huge potential in this approach because I always wanted to edit my code like the code editor would be a extension of my body. In other words I wanted to edit code with the speed of my thought.
By default the desired functions were not there. I needed to search for some packages and even edit those packages to achieve my desires. I wanted to toggle between quote types 'a', "a". I wanted to convert a string to a symbol and vice versa "a", :a. I wanted to toggle the do end blocks with the braces blocks. I wanted to convert amongst sneak_case, pascalCase, dash-case,, slash/separated

So by using it continouosly for more than half year I installed these packages:

          For converting each other from any of them:
    • "sneak_case"
    • "pascalCase"
    • "dash-case"
    • ""
    • "slash/separated"
  • Clipboard History - for using multiple history feature
  • CoffeeScript - syntax for coffee script
  • Cucumber -  syntax for cucumber
  • Eco - syntax for eco template
  • ERB Insert And Toggle Command
          For toggling amongs these
    • <%= %> 
    • <%-  -%>
    • <%  %>
    • <%=  -%>
    • <%#  %>
  • Gist - I like to store my snippets on gist and access them from sublime
  • Missing Palette Commands
  • Plain Tasks - For storing my tasks in plain text format but nicely formated, like the below list
    • ✔ task 1 @done (13-04-01 21:28)
    •  ☐ implement sorting
  • RSpec - syntax for my specs. I am a TDD advocate. It saves me a lot of time.
  • Ruby Block Converter - for toggling amongst {} block and do end blocks.
  • SFTP - for editing remote files.
  • Toggle Symbol To String for toggling between "symbol"and :symbol
  • Toggle Quotes for toggling between 'string' and "string"
  • Advanced New File for creating deeple nested directories when I place a file into them.
  • Nettuts + Fetch for fetching the latest jquery.js or jquery-ui.js or backbone.js libraries.

Often the commands were missing from some of these packages. So when I searched for 'toggle block' then no result was shown however I wanted to convert a block from "{}" style to "do end" style. This was a bottleneck in my speedy coding... In these cases I needed to open the package add the command to the Default.sublime-commands file and then make a pull request. This way if I eventually forgot the key combination of a feature I could search for it in a command palette.

May I ask any developer who makes a sublime package to add this file to the package and enlist the commands there.
There is the multiple editing feature I like the most... :)
And it is a very fast editor.
I also like the snippet feature of it.

Overall all I can say s that it is a very handy code editor and it worth the money for buying it and spending time to learn it ;)

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