Thursday, April 26, 2012

fugitive.vim is awesome. So is git interactive rebasing

I have finally started forcing myself to use vim-fugitive. I have to agree that it is "so awesome, it should be illegal". I ran into a problem within the first hour and vim was shouting This is not a preview window everytime I wanted to :Gstatus. I couldn't find a solution for this on the internet and after a few experiments and reading docs, fixed this with :set previewwindow in the Gstatus window. I have always used windows instead of tabs in Vim. But, I started seeing a big use-case for tabs - being able to edit some file without disturbing the existing windows.

I have tried git rebase --interactive ID for a very short time when I was playing githug. Today, I had to use it to remove a change accidentally added in a commit. Interactive rebasing was fun and all I had to do was running the command. Didn't need to read tutorials or go through man pages.

In our custom CMS, we had location details as text fields on multiple models. This has led to fragmentation of city, state, region names. So, we had to convert these text fields to FKs so that the new ones will be through look-up but not manual entry. We have gone one step further and created a Location model which has FKs to City, State, Country and other models and added a reverse generic relation to Location from our models. The immediate problem with this approach was that we had used, obj.state etc. in our templates. I came up with a simple solution for this -

    class Base(models.Model)
        // model code here

        def location(self):
            "caching location as it will be needed by 6 properties"
                return self._location
                self._location = self.locations.all()[0]
                return self._location

        def city(self):
City's __unicode__ method returns its name. We were also getting annotated list of cities and the number of events in the city.


returns dictionaries with city__name key when I wanted those with city key. This was solved by looping through the queryset and processing those dictionaries. I wish I could do something like SELECT name AS city FROM locations_city.

Wednesday, April 25, 2012

Waking up early and some django templating stuff

Ah, another long break. I have been waking up at 7am and reaching office before 9am. This gives me a lot of time to finish my day job. I have a feeling that it is easier to incorporate new habits one or two at a time. Earlier, I used to try to bring too many changes to the daily routine. That never worked and made me feel like I lacked the will to change. This time, I am not biting off more than I can chew. So, for the next month, the resolution is -
I will wake up at 7am and hit the pillow by 12pm
I have been writing a lot of Django templates at work. Recently came across firstof which is a good way to avoid the if-else-endif template. I have always wanted to have a neater way to add context to include templates. So, I used to surround include templates with the with tag. I found that the include tag takes arguments which will be added to the context.

{% include "templates/search_form.html" with placeholder="Search projects.." %}

looks much cleaner than

{% with placeholder="Search projects.." %}
    {% include "templates/search_form.html" %}
{% endwith %}

My ordered-lists were showing with bullets instead of numbers. Learned about list-style css property. I need to understand list styling better.

Phaneendra gave a talk introducing Sencha for mobile app development. Thanks to the framework, he had been pulling his hair almost everyday since he started using it. After the talk, Theju demoed kvm and discussed the problems he had faced getting git and a django project working on Windows. We discussed several ways to make it easy for new people to get started with an old project, but couldn't come to a good conclusion.

Thursday, March 1, 2012

LESS feature request and Zepto

LESS made writing CSS easy. There is a feature I wish were present in the framework. If the feature is already present, I couldn't find it. I want to be able to easily add properties which are common to parents and children without duplicating code. For example, I keep writing stuff like this -

aside {
  float: left;
  color: #666;
  font-family: serif;
  span, a {
     color: #666;
     font-family: serif;

It will be great if we can write

aside {
  float: left;
  &, span, a {     color: #666;
     font-family: serif;

There is another way to do this, but I don't like that very much.

aside {
  float: left;
aside, aside span, aside a{
  color: #666;
  font-family: serif;

Some time ago, I have tried Zepto for the mobile website expecting that it would let me add effects like fading. I had to fallback to jQuery for such effects. I wanted to write vanilla JavaScript for such effects, but left it for some other time. I don't think simple effects like fade are difficult to do. There was an fx.js in the Zepto repository and it had fadeIn, fadeOut etc., but those weren't implemented yet.

I have seen JavaScript libraries (tinymce, Zepto) using constants to specify what functionality is allowed. I found this annoying because you won't be able to know that unless you step through code. I really wish that something like console.log is as standard as printing to the stdout/stderr. That way these libraries could have printed a message saying fading is not yet done. Or is there some other reason there are no log messages in most of the libraries?

Thursday, December 29, 2011

Back after a long time

No idea why I stopped logging my learning activity here. Luckily, I didn't stop learning altogether. Over the last few months, 7 to be exact, I have worked on real Django, JavaScript applications, two routine webapps and a CMS. I have added a lot to my knowledge and I am sorry now that I didn't keep a record of what I have accumulated in my skill bank.

So, from today, I will be maintaining a developer dairy again. For the last 2 weeks, I have been working on the mobile version of a big website using django_mobile for detecting the user-agent and delivering the appropriate version. The good thing about this project is that I have also taken up the responsibility of styling the website. I am pretty satisfied with the way it is coming up.

Today, I have added PhotoSwipe, which is a good javascript library for showing neat slideshows on mobile devices. Just put your images in anchors and attach photoswipe to the selected anchors. I have fallen in love with LESS CSS. It would have been repeatedly frustrating had I not made the decision to switch to LESS early. Also read about cookies from quirksmode and used the scripts from there to get, set and delete cookies using JavaScript.

Saturday, January 29, 2011

Random reading. RSI threat. Should have short-term goals.

After spending 3 days making comps for a fun project, I was very tired and had to rest for a day. Then, I had spent the next 3 days reading without any short-term goal which is not a good idea. I spent the last 5 days reading random stuff about Git, Vim, AppEngine, Python, Bash, RSI , and whatnot. I know that it all helps, but I will like to be more focused and have specific goals for each week and (even better) for each day.

I got Git Community Book printed long ago. Reading that has helped me understand how Git stores the snapshots and commits etc. I got a github account recently and created my first public repository today. Generating SSH key and pushing code was a nice experience. gitimmersion was also useful to get a feel of the work-flow. Committing frequency is a personal preference, I guess.

I have been suffering from serious pain in my arm, shoulder and neck. Though I haven't found the best posture at home, I think the major reason is hunting and pecking with my right hand. I have to learn touch typing, seriously. As I type very fast already, forcing myself to touch-type hasn't been possible because it slows me down considerably. I need to get an ergonomic {chair, table, keyboard} when I move to a new place., Vimcasts are brilliant. I have learned some cool tricks and am already putting them to use. Learning vim scripting (with and w/o Python) is definitely on the list. I knew very little bash scripting, have read a basics tutorial and need to explore more. I understand that "regret for wasted time is more wasted time", but I couldn't help regretting having wasted all those days in college and after that. I could have learned and enjoyed so so much. It's never too late and those days are not going to come back anyway.

Monday, January 24, 2011

Realized the importance of tools

I was sad after spending three days on mocking up one of the simplest web pages possible. But, in retrospective, I am happy that I could learn some new things and understood the importance of a few widely used tools. Tools like Photoshop, firebug, jsfiddle are popular for a reason. They are designed to save you a lot of time and effort. Using them to do what they are best at doing can boost productivity greatly.

For a while, I was coding up a web page the very old way - going back and forth between vim and Firefox/Chrome. Vim is a great text editor, but not designed keeping front-end web development in mind. The words mockup, psd2html, photoshop appear all over web design blogs. Having a visual goal documented as a psd, before coding HTML and CSS, definitely helps. After the initial structure is decided upon, an in-place editor like firebug can save you a lot of window and context switches. Jsfiddle, some online css3 tools for gradients, border-radius etc. were helpful as well.

Monospace is good for programming, but it strains my eyes for some reason. After searching for a better alternative, I liked Droid Sans Mono. Its 0 and O look very similar, but the increased line-height improves readability. I haven't found a vim color scheme as likeable and currently switch between a lot of them. My hand has been hurting very badly and I code for longer periods. Learning to touch-type is very important, I understand now.

Sunday, January 16, 2011

I pick up speed but slow down again

I have spent some time on reading about decorators in Python. The name always sounded as if it was a novel concept and would take time for me to understand. But, it is just one of those obvious features in functional languages. Functions being first-class objects in Python, they can be passed to and returned by functions. I have found that looking at the docs before reading tutorials will help for understanding language features and syntax. We can't always say that for libraries though.

CSS3 for Web Designers is a well written, short, good book. I understood some terminology that appears on almost all design websites when they talk about css3. Transitions, transformations, multiple backgrounds, animations are all simple but powerful tools in any designer's arsenal. The way some powerful features like these silently seep into the current front-end technologies is what impresses me most in HTML5.

I suddenly find myself spending more time on front-end design and development. I haven't done a single photoshop mock-up yet. It depends on what you are going to make. I feel more comfortable marking up straight away, but I understand the importance of mock-ups in web design. It's time to start hustling.