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.city, obj.state etc. in our templates. I came up with a simple solution for this -

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

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

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

Location.objects.values('city__name').annotate(num_of_events=Count('city__name')

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.

vim.wikia.com, 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.

Friday, January 14, 2011

Wheels in motion again. Back to snake wrangling

After the dull period of two weeks when everything was so confusing and frustrating, happiness arrived at last and it felt food when it finally did. It was definitely one of the darker times in life and thanks to all loved ones for bearing with me. I still don't know whether it was a feeling of uncertainty or lack of confidence or both, but I am happy that it's over now and happier for the transformations it brought with it.

I haven't stopped learning, reading, I pushed hard. Basic terminology in graph theory, traversal algorithms, basics of PyUnit(unittest) were all gulped down one day. os module took most of the next day when I finally grokked fork and exec. The next day was spent on reading about WSGI again. I feel lost when a framework abstracts away most of the things.

I am going to spend more time on Werkzeug, SQLAlchemy and Flask. I want to contribute to one of Pocoo's projects. Some time was spent on HTML5 and CSS3 too. I need to learn some bash scripting and have fun with some GNU utilities.

I am putting some effort into improving my vocabulary. My goal was to learn five new words and copying a well written paragraph into my notebook everyday. However, over the week, I could do one or two a day. This goal needs to pursued in earnest for it's worth every minute spent.

Sunday, January 9, 2011

The first hurdle

Two weeks ago, I just told myself to relax and take a short break. Short didn't stay short. It consumed 2 complete weeks and I couldn't figure out a way out of this rut. It was a forgettable period except for a few highlights. This has been the biggest problem I have faced in my sabbatical yet. It felt like I had hit a wall and couldn't get back to what I was doing. I was so depressed for some time about this. I hope and see signs that it has ended now.

It was not like I was not learning anything in this period. I was reading books on Algorithms, HTML5, CSS, jQuery. I was spending most of my time in front of my laptop reading books or blogs. What really depressed me was that I had consistently been haunted by a feeling that I was going no where. I was reading for the sake of reading. I was still reading because I was afraid of executing, using what I have learned. The continuous chatter inside my brain. Concentration and focus were elusive. I had this drive to create and execute ideas everyday, but never could I start and type one line of code. I should have blogged earlier. It would have helped.

Here is what I have spent the last two weeks on. I have read HTML5 for Web Designers by A Book Apart, 3 chapters from Python Algorithms, 2 chapters from jQuery in Action and a few blog posts about coding, technology and startups. I bought a copy of Don't Make Me Think. The book on HTML5 was good and I did some very simple experiments - audio, video elements etc.. From the algorithms book, I understood that algorithm analysis is not as tough as I thought it would be.

Reading Philosophy is one of my most favorite activities. Most treatments on History of Western Philosophy start with Socrates, Plato and Aristotle. So, I have been introduced to these three giants of Philosophy by different sources. Thanks to all. The Social Network gave me peace and impetus at the same time. Envy doesn't look bad when it is used rationally for the person's improvement. It can be a great driving force and also a reminder that there is no stopping in life, only being left behind.

Wednesday, December 22, 2010

Played with jQuery and spent some time on StackOverflow

StackOverflow is really addictive once you get to the stage where you can help people by answering some more-than-trivial questions. I have been spending a lot of time each day and sometimes it feels like a waste of my time. It probably is, now, when I should be learning more and then think about helping even more. True, it makes me look up stuff I wouldn't have come across if I worked on my own, but moderation is needed in looking for questions to answer. The game mechanics of SO are amazing with all its reputation points and badges. If ever I am going to build an addictive service, SO will be one of the most important case-studies.

JavaScript is such a beautiful language (if you neglect the bad parts). Learning it over a few weeks, I understand how powerful and expressive it can be. It is the browser that made it look bad. Watching the Crockford video on "The metamorphosis of Ajax" has cleared the mist I always used to see on Internet Explorer. Microsoft, in the early years of the browsers, really pushed JavaScript 'in the browser' to newer heights. I will keep on encouraging my friends to move away from the IEs, but will not blame Microsoft as being evil.

I have learned a good amount of jQuery and JavaScript over the week. I am looking forward to put all the learning to use. I have some ideas for small web applications. What better way to test your knowledge and skill than to try and build things using them.

Wednesday, December 15, 2010

Reading books and answering questions on StackOverflow

JavaScript Cookbook appeared to be targeted at beginners. So, I took a break from that book and dived back into jQuery. This time, I chose Manning's "jQuery in action". Even though it is for beginners-intermediate, the writing style was good. Before introducing a selector or method, the purpose it serves, the functionality it can replace and the cross-browser issues with JavaScript implementations (if any) were discussed.

The book was divided into two parts. The first deals with Core jQuery - selectors, DOM manipulations, events, animations etc.. I have read through the chapters till events though it was like a revision. At places, I would have liked the explanation to be crisper, but it was impressive nonetheless.

After a break of 2 months, I have started answering questions on StackOverflow. Gained a lot of reputation points by answering questions on JavaScript, jQuery, Python, RegEx etc. In 3 days, my reputation has grown from 129 to 671. I used knowledge gained in JS, jQ and answering the questions made me revise some stuff and look for better explanations. The sudden overflow of n00bs who didn't even know that they have to search before asking annoyed me a bit.

I have posted quite a few programming answers. Here is some advice I gave to a guy who sounded like he was lost:
  1. Don't give up. Persist. Ask for help if you don't understand something.
  2. Practice deliberately. Practice, keeping in mind that you are doing stuff to get better at something.
  3. Read books, biographies and autobiographies of great people will help. You will realize that there are many people who did great things after starting when they were older than you.
  4. Write. At least, keep track of the things you have done, learnt.
  5. Talk, if possible argue, with smart people.
  6. Keep all forms of stupid entertainment to minimum. TV, chatter, browsing etc..

Friday, December 10, 2010

More reading from JavaScript Cookbook

It's getting tedious now, the book, because of a lot of repetition and too much explanation. It probably has to do with the chapters I have read today - Forms, Debugging and Error Handling, DOM. The debugging chapter was just a bunch of recipes familiarising the reader with development/debugging tools in different browsers. And the DOM chapter was boring because the stuff introduced in the beginning of the chapter is repeated again and again in the recipes. It seems like the books is targeted at absolute beginners.

This is the only thing I am doing now. I need to get more stuff into the day to keep me hustling when this stuff gets boring. I am yet to decide whether I should order a jQuery book or not. I don't even know whether it is wise to get a book on jQuery because any book on the subject becomes more dated everyday and the online documentation is excellent, not to mention the infinite tutorials.

At home, we have been planning to get a puppy lately, mostly a German Shepherd. We need to figure out some issues and take decisions. I could finally do some research about dog breeds, mostly on Wikipedia and AnimalPlanet.

Thursday, December 9, 2010

Continued reading JavaScript Cookbook

The next 3 chapters in the cookbook were about Functions, Events and Browser objects. Most of the recipes were pretty basic but I still read through each of them for the sake of repetition. Three chapters is less than what I have aimed for in the morning, but it's ok. Many recipes talked about cross-browser compatibility etc. while mentioning that most of the JavaScript libraries take care of most incompatibilities. Maintaining the state within page using location object's hash property was new stuff for me.

After a long period of inactivity on StackOverflow (I have been learning a lot of stuff, but never questioned or answered), I have asked a question today. It was about currying in JavaScript. A snippet I posted was not behaving as I expected. It was because I forgot to put a return before a statement. I felt stupid and the guys who answered reassured that it happened with everybody. One commenter mentioned that currying was not the same as partial application. I read about it and this is one kind of hidden benefit from participating in communities like SO. I think I should keep spending some time in StackOverflow.

Having many ideas in mind, but not knowing which is worth executing is painful. I know that I need to prototype but I don't know what's stopping me from taking that step. Anyway, getting up to speed in the technologies I am going to use will be a good intermediate step.

Wednesday, December 8, 2010

Started reading JavaScript Cookbook

I have started reading this book to get up to speed with JavaScript. I have finished the first 5 chapters today which were really basic, after my time with JavaScript over time. Now, I have to pick up more speed and finish this book as soon as possible. The book also deals with the latest technologies introduced with HTML5 which, I hope, is very useful. The first 5 chapters just felt like a revision of the Methods chapter in the GoodParts book. And coming to know about the introduction of map, filter, every etc. in ECMAScript5 through Crockford's video lectures on JavaScript, I was bored with the fifth chapter dealing with Arrays. As a whole, it is a good start and I need to finish the book soon.

I have adopted Jerry Seinfeld's productivity technique "Don't break the chain" and made two sheets to make sure that I keep working towards my goals. I am desperate to be more productive and this is one more attempt at it. I don't understand why I am not spending the whole day learning. I am using about 6 hours a day in learning to code. The remaining time seems to evaporate without me knowing.

The next few days should be spent learning more JavaScript and jQuery. Once I get upto good speed with both, I will make some basic apps on GAE. After feeling comfortable with basic apps, I wish to restart my adventures with Django. All along, I should concentrate on improving my Python skills whenever possible. I just need to get more time out of the day. I don't think I really need breaks during study. I am really feeling down because of all the confusion. I should pick myself up.

Monday, December 6, 2010

Fell ill and starving for Ideas

I have been learning stuff for a few weeks now, but there is a dissatisfaction because I am not really using all that I have learned immediately. I understand that I will eventually put it to use some day or the other, it just bothers me that I am not doing it right now. I have been thinking of some ideas to implement to test my knowledge and skill, but I am stuck at choosing which to execute. A few of them are done to death, but I feel that I can do better or it's worth doing for learning's sake.

I wanted to get started with a micro-framework in Python and Flask seemed to be the new hot choice. The documentation is very good and I have finished the QuickStart and Tutorial sections. I feel stuck now because I really can't understand what to do now except start making something. May be I should do that.

Mind controls the body, but it can be the other way around, ask any unhealthy man. My sitting posture in the new chair has brought pain to my ribs. I couldn't stand the pain for a day, but taking pain killers controlled everything and it was gone before I experienced it again. I need to be careful about my posture etc. and make sure that these things don't get in my way.

Wednesday, December 1, 2010

The basics of WSGI etc.

After reading up on CGI, FastCGI, mod_python for the sake of understanding history, I have started reading about WSGI. It is the current standard interface between servers and frameworks or applications written in Python. There were some great tutorials for learning WSGI here. These introductions were good. I want to read the wsgiref tutorial as well and then probably start exploring werkzeug.

I have little experience with Django and AppEngine and I want to get better at both. Flask is another framework I want to get familiar with. The Web excites me more than other stuff I can do with programming. I should probably write an essay explaining why I like it more than others. Here again, I remind myself to start blogs for coding and opinions. I need to get my own domain and host my personal website soon.

Though this is not the first time I played badminton, I was skeptical about it thinking that it wouldn't be fun, mostly because of my love of cricket. It was foolish to think like that and I am enjoying it now. The other best thing that has happened is that I am waking up at 4.45 a.m. everyday.

Monday, November 29, 2010

Some old technologies that are not preferred now

CGI, SCGI, FastCGI, mod_python are not the preferred ways of serving web pages now. Modern web development almost always revolves around Web Frameworks. But, after listening to the lecture on the history of JavaScript, I felt an urge to have an understanding of the ways people got things done before understanding the vulnerabilities and arriving at better methods. So, before I jumped into the basics of WSGI, I checked the other server-side options with Python.

I prefer articles explaining theory over how-to kind of tutorials. Having the knowledge of what and why makes the how easy to understand. But, it is not practical all the time, to know all the underlying details. Thanks to Wikipedia which has been my go-to for overview on many things.

Waking up at 5 a.m. in the morning makes the day really longer. Though I had a feeling that I was more productive in the night time, I desperately want to play some game for the sake of playing and also fitness. My current work place at home troubles my concentration and focus in many ways and I need to find a solution quickly.

Saturday, November 27, 2010

Douglas Crockford's Javascript vidoes

I have watched two crockvideos (presentation on JavaScript by Douglus Crockford) yesterday. The first video was about the good stuff in JavaScript. He explained how he stopped worrying about the bad parts and how he started loving it by refining the language to have only good parts. Many of the catch phrases, if I can call them so, form the book were there in this video. Though there is no intentional evangelism, he somehow made me want to learn more JavaScript. Overstating the importance of JavaScript for web is impossible anyway.

The next video was the first of a 5 part series on JavaScript. It was all about the history of the language. The presentation was very interesting despite its length (1hr. 42 min.). He touched upon jacquard looms which led to industrial sabotage in the beginning of the 19th century, punch cards that was used in the early days of computer programming, the mother of all demos by Douglus Engelbart. Then, there was the 'brief history' of programming languages till the invention of JavaScript.

I have printed out the first two chapters from JavaScript Cookbook. Rereading The Good Parts book has been as enjoyable as the first reading.

My brother and I have been planning to go to the indoor stadium in our town to play badminton daily. Badminton is such a good choice to get fit. So, I have bought a cheap Yonex racquet to start playing after a long time. Lately, my productivity has been effected by my sitting posture owing to my chair. I have finally bought a chair which lets me sit upright and comfortable. I have called almost every one of my college friends in the last two days. Everybody is doing well and I wish them all the best.

Friday, November 26, 2010

Douglas Crockford's JavaScript: The Good Parts

My plan for the week was reading this book. I have read it once, as a comprehension or a story and loved it. I am reading it again slowly while trying out the methodologies promoted in the book, and a good book stays enjoyable no matter how many times you read it. I have also started watching the videos by Crockford on YUI theater.

I have finally started learning touch-typing. I have decided to stop hunting and pecking with my right index finger though I am quite accurate and fast with that. After looking for some typing software, I chose GTypist and KTouch. GTypist has been very good. I am spending an hour or more everyday on this.

Once I feel that I have comprehended the Good Parts book, I will read more about JavaScript and do some small projects. I feel an urge to buy the JavaScript Cookbook, but that's on the back burner for now. Next week, I am going to revisit jQuery and learn as much as possible and make some stuff with it. Making a good, useful jQuery plugin will be a great thing to do.

Tuesday, November 23, 2010

A short break and back to work

These are the things that contributed to the two day break -- a friend's visit that's long awaited, an engagement ceremony, an accident to my grand parents and a feeling of burnout. I have gone 42 (wow! what a coincidence) consecutive days reading and learning stuff before breaking on Sunday. I didn't spend the day contemplating, but spent well, talking to Rahul. We bought a bat and played cricket after a very long time, nearly 2 years.

I finished reading Harry Potter and The Deathly Hallows just a day before the movie was released, as wished. I enjoyed the book because of my long time association with all the characters. I have started reading Robinson Crusoe by Daniel Defoe. It has been very good. Happy that I am back to reading fiction, I should read some non-fiction as well -- Autobiographies, History, Philosophy etc. are among my favorites. There's no shortage of books and audio books.

Today, I have started reading JavaScript: The Good Parts by Douglas Crockford. I don't remember reading any programming book which expressed syntax and semantics more crisply and clearly in a straightforward way. I have just read the first 4 chapters and it was a breeze probably because I have already read a guide and a book on JavaScript. Looking forward to finish this book before the weekend. I don't mind rereading it later.