To Learn, Must One Always Be In A State Of Discomfort?

Mind the Knowledge Gap

Mind the Knowledge Gap

I’ve been coding Django apps for about 2 years now. I can initiate a server running Arch Linux, get it up and running and deploy my Django app in a couple of hours. I code using Vim. I use zsh as my default terminal. I know enough unix commands to perform the usual sed/ack/grep (or Ag if you’ve downloaded Silver Searcher). Conceptually, I can explain most web development concepts (although I stil have trouble understanding exactly what a reverse proxy does). In two years, I’ve also had to learn HTML/CSS/Javascript. It’s kinda taken for granted that and self-respected web developer would auto-learn that along the way. Understanding the subtleties of Git (merge vs. rebase) and how to use it (git flow) is also one of those ‘taken for granted’ knowledge grabs. My Python isn’t the most elegant, but give me a couple rounds of refactoring, I would have spotted and corrected most of the low hanging fruit ‘mistakes’.

There were a couple of months I felt my rate of learning wasn’t improving as quickly as before. I had become somewhat comfortable in the daily routine. This didn’t last long of course. Recently, I had to build a realtime map app for one of my products,  TripEvent. To do so, I had to use gevent-socketio. Diving into this triggered a whole chain of questions that exposed my lack of understanding about what really goes on under the bonnet.

I’ve relied heavily on my pattern recognition skills (and slavish hours just practicing, building) but there is not escaping the fact that some key computer concepts still eludes me. For example: when a user lands on my website, this generates a GET request that is processed by my reverse proxy (nginx in my case) which is somehow handed off to uwsgi which then hits my django app which finally hits my database (postgres). Is this all happening on 1 process? What happens when there are 2 requests at the same time? How does tweaking my nginx worker settings affect this? How this Python’s GIL come into play? How is multi-threading or multi-processing con-currency relevant? In the context of Python, how does gevent and its greenlets overcome this? I think you guys can see where I’m getting at.

Why is it that there isn’t any resource that explains such concepts from a web developer’s point of view? Especially one that doesn’t have formal computer science training. I imagine there must be many more people like me out there, all self taught, all wondering what really goes on under the bonnet! The information as always, is all out there. It’s piecing it together and make it conceptually sound in the context of my job (web developer) that’s hard.

I am in a major state of discomfort but this is forcing to learn and read more and ultimately plug the missing knowledge gaps. I think one always needs to be in a slight state of discomfort to improve. To be comfortable and not have questions gnawing at the back of your brain is a submission that you’ve not doing anything interest or new.

Posted in lessons, musings | Leave a comment

Some Lessons Learnt from Messing with Django and AngularJS

squaredjango-logo-negative

  1. You can only use one ng-view per page
  2. If you skipped reading the conceptual overview, it’s a critical document that will help you wrap your head around the angular concepts so don’t.
  3. Angular disables form submissions without an action attribute. If you’re using django-crispy-forms (there’s not reason not to. it’s an excellent form library) to render your form, simply add self.helper.form_action = ‘#’ to fix this.
  4. If you’re wondering why your url end point is getting called twice, its probably because django is redirecting the url with a trailing slash to a url that does. To fix this, simply escape the backslash like: /custom_api/get_nearest_hotels/:eventId\\/
  5. Loading templates are a bit of a hassle. There are a few ways to solve this. This guy’s method.
  6. Tricks and tips
    1. http://gpiot.com/angularjs-useful-tips-to-get-started/
    2. http://deansofer.com/posts/view/14/AngularJs-Tips-and-Tricks-UPDATED
  7. Angular and SEO
  8. Get the correct angular folder structure from angular seed
  9. Check out angular-ui
  10. AngularJS in 60 mins
  11. If you see your page flash with angular template tags and then reload again to show the actual content, you need to apply ng-cloak.
Aside | Posted on by | Tagged , | 2 Comments

event_bindings error in Chrome console

If you have an error for event_bindings in your chrome console that looks something like this:

Error in event handler for ‘undefined’:

Unexpected token u SyntaxError: Unexpected token u at Object.parse (native) at chrome-extension://hobijieodegdbpakkfiopclcljnomfnj/ylc.js:120:23 at miscellaneous_bindings:288:9 at chrome.Event.dispatchToListener (event_bindings:390:21) at chrome.Event.dispatch_ (event_bindings:376:27) at chrome.Event.dispatch (event_bindings:396:17) at Object.chromeHidden.Port.dispatchOnMessage (miscellaneous_bindings:254:22)

 

It is most likely due to a rogue chrome plugin. In manage extensions, search for the one listed in the error message. In my case, it is hobijieodegdbpakkfiopclcljnomfnj and disable it. Restart your browser and all should be well again.

 

Posted in Uncategorized | Tagged , | Leave a comment

Shell Plus, iPython or Shell Prompt Looks Screwed Up

If your prompt ever looks like this:

Python 2.7.3 (default, Oct 22 2012, 06:12:32)
Type "copyright", "credits" or "license" for more information.

IPython 0.13 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
[0;34mIn [[1;34m1[0;34m]: [0m

To fix, simply run: easy_install -a readline

Posted in Uncategorized | Tagged , | Leave a comment

Django Crispy Forms Add HTML5 Data Attributes to Button

Add HTML5 data attributes directly to the button like this:

self.helper.layout = Layout(
                'first_name',
                'last_name',
                'email',
                FormActions(
                    Submit('add', 'Add', css_class="btn-primary"),
                    Button('cancel', 'Cancel', css_class="btn-danger",
                        data_dismiss="modal", aria_hidden="true"),
                    css_class="form-actions form-custom"
                )
            )

instead of this:

HTML('<input type="button" name="cancel" value="Cancel" \
                            id="button-id-cancel" \
                 data-dismiss="modal" aria-hidden="true">'),
Posted in Uncategorized | Tagged | Leave a comment

13 SEO Tips for Django

This is mostly an on-site specific guide
  1. Use the redirects app to manage url changes Django documentation
  2. Use post save signals to handle slug/url changes in your models Link
  3. Use sitemap The sitemap framework
  4. Use slugfield Model field reference
  5. Use cached template loaders to reduce page load times The Django template language: For Python programmers
  6. Use a css/js compressor to reduce page load times django_compressor
  7. Use django-robots to manage your robots file django-robots
  8. If you’re rolling an e-commerce site, don’t reinvent the wheel, just go with The Best Django CMS. It’s the best code and seo friendly cms framework for django
  9. Manage object level meta data with django-seo
  10. Not django specific but submit your site to google webmasters Webmasters – Google. For bing: Bing – Webmaster Tools
  11. Not django specific again but load your page using Make the Web Faster and make all the recommended changes
  12. Crawl your site content to find broken links using Xenu or Integrity for Mac
  13. To generate image sitemaps, use Django Image Sitemaps

Other Stuff

Posted in django | Tagged , | Leave a comment

Mac Trash Hanging on Delete

If you try to clear your trash and it progress bar seems to hang, it’s probably due to a locked file. A few recommendations on the internet requires the user to mess around in terminal and creating a new .Trash2 folder in your home folder and than doing a mv and then delete again.

There’s an easier way to accomplish this. Simply go to your Trash, hit cmd-a, move all the files out into a temporary folder. The remaining ones in Trash will be the locked files.

To unlock, simply right click, Get Info, there should be a small lock on the bottom right of the pop up. Click on it to unlock the file. You should be able to delete it now.

Posted in Uncategorized | Tagged | Leave a comment