How I learn new Framework/Language/Library/Tools

Frameworks come-and-go. There’s nothing you can do. But one thing you can do is – adapt. And if you don’t, you’ll be forgotten like your framework/tools. Most of us fear new stuff. We fear change. Adaptation is very easy if you can overcome the fear of it. It is not only true for the framework but also for programming languages/libraries/tools etc. I will refer all these together as “X” in this writing.

Step 1: Quick Start
My first step is to read and to go through quick start/first step guide. Generally, all major official documentation provide this type of quick start guideline which also includes example code. I start implementing (coding) right away with a small application that pops up into my head at that moment and tries out some features of the X.
Doing this gives me an idea of X am trying to learn. Moreover, it gives me confidence that I am “making” things with this new X. I am like – “WOW!!! Cool it is working!” which eventually helps me to go forward. It takes me a couple of hours to get familiar with the X.

Step 2: Dive In
After spending a couple of hours of basic quick start, I START DOING real project/task…

I do not try to learn everything before I start. While following quick start guide, I try to understand why and what am doing each thing mentioned there. I do not write any single character of code that I do not understand. I think it is one of the essential things. Initially, I do not copy paste code, instead try to write, reason and modify it as I go.

Additional Tips:
Follow Convention: I’m very strict about the convention and best practices. Hence, I read and follow their best practices and convention guideline as I start coding. However, that does not mean that you should never go off the book. But that should be very rare and exceptional case, and you will know when you have to do that.

Read Documentation: I read official documentation. It becomes my bible while I code. I try not to watch video tutorials. To my observation, tutorial helps you to learn quickly and easily but kills your technical reading capability. It affects severely when you try to develop advanced stuff since that advanced stuff is not available in tutorials. On the other hand, if you are familiar with the documentation, you will be able to figure out how to do that or where to look at for that. You will know how to use resources like Google search, stack overflow and online articles quickly when you are stuck.

To sum up, I do not restrict myself to any language/framework/tools/library. I try to adapt, and I feel these tricks help me to set off efficiently.

Lastly, one of the keys to Apple Inc.’s success is – adaptation. They not only adapt but also frequently kill their own popular product and present newer one. Apple killed their Macintosh, killed iPod, even killed headphone port! Here is a video from PolyMatter which describes this matter quite adequately. They know – technological changes are inevitable. So, they bring the changes themselves instead of following the trends. They become the trendsetter and not the trend follower.

languages

Like
Like Love Haha Wow Sad Angry
2
image manipulation with cache facility in nginx

Manipulation like resizing to cropping, rotating an image is very easy through image_filter module of nginx. In addition we can cache this manipulated images.

We will need 2 nginx server.

  1. original server [ i,e, http://mysite.local:80 ]
  2. media server. [ i,e, http://media.local:80 ] This server will be used to deliver the desired resized or cropped images.

Here is the configuration for the servers:

Like
Like Love Haha Wow Sad Angry
Solution of infinite digest loop for ng-repeat with object property filter in AngularJS

Few months ago I wrote a code in AngularJS which was something like this:


<ul ng-repeat="course in courses|filter:{is_taken:true }" >
<li>{{ course.name }}</li>
</ul>

 

It was generating a digesting loop error. Though the data was showing correctly. Soon I realized that it was generating because for each turn in ng-repeat loop, courses are filtered up. So, it was watched and digest by default characteristics of angular Scope. In this situation the easiest solution to me was following:


<div ng-init="filteredCourses=courses|filter:{is_taken:true }">
<ul ng-repeat="course infilteredCourses" >
<li>{{ course.name }}</li>
</ul>
</div>

 

What I did was I initiated a new object using ng-init which contains the filtered objects. Then use that newly created object to loop on. And all those errors are gone… 🙂

Like
Like Love Haha Wow Sad Angry
AJAX requests in CakePHP without disabling SecurityComponent

Security is always a big deal for a software specially for web app where you don’t know your users’ intention. To ensure some common security measure, CakePHP provides SecurityComponent with its core.

Let’s come to the point. If you try to POST any request through AJAX, you will get Bad Request exception and your request will be Black Holed.

So, how do you prevent this without disabling the SecurityComponent for the action(many online resources do this. But this is not what we want, right?)? Well, you need to do 2 things to do in your beforeFilter to achieve that.

$this->action == 'add') {
    $this->Security->csrfUseOnce = false; // We will use CSRF token for more than one time
    $this->Security->validatePost = false; // Disabling form POST validation
}

Why these two:

  1. Since we may do the request several time from different parts of a single page, we will use same CSRF token. Though there is a complex way to update CSRF token of the page after the ajax request processed, but lets stick with the easier way.
  2. Also, SecurityComponent require you create your form using FormHelper shipped with CakePHP core. I’m assuming the form is not built with the FormHelper. You can ignore this if you generate your form using FormHelper.

If you do not using FormHelper to ensure CSRF protection you will need to post CSRF token with your post data in specific format. Here is how the CSRF token should be in post data.

array( 
'_Token' => array(
    'key'=> $this->Session->read('_Token.key');
    ),
'ModelName' => array(
    // modeldata
    )
)
Like
Like Love Haha Wow Sad Angry