Doubling My Stackoverflow Score

On May 3rd, I set myself a goal of doubling my SO points by trying to answer Python/Django related questions everyday in a bid to level up my knowledge. Thought I check out my progress before the year closes.

On May 3rd, I was at 1183 points, this is me now:

profile for super9 at Stack Overflow, Q&A for professional and enthusiast programmers

Well, in the end, I didn’t answer a question everyday. Maybe 2-3 times a week on average.  Took about 7 months in all.

Next goal: 5000 points.

Recently started a new project and ran into this error while installing pycrypto. Every single post seems to just say: install command line tools with the latest version of Xcode and your problems will magically go away!

Well, if that works for you, great, if not, let’s get down to the root of the matter.

(greedychimp)nai@nyc:~/Work/greedychimp(develop○) » python                           18 ↵
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

For some reason, my virtualenv was using Apple’s version Python which was compiled with llvm-gcc. We don’t want that, we want the clang compiled version of Python to get this to work.

(greedychimp)nai@nyc:~/Work/greedychimp(develop○) » port select --list python         1 ↵
Available versions for python:
	none (active)
	python25-apple
	python26-apple
	python27
	python27-apple

Seems like I had the clang compiled version of python already but hadn’t set it as default.

(greedychimp)nai@nyc:~/Work/greedychimp(develop○) » sudo port select --set python python27
Password:
Selecting 'python27' for 'python' succeeded. 'python27' is now active.
nai@nyc:~ » port select --list python
Available versions for python:
	none
	python25-apple
	python26-apple
	python27 (active)
	python27-apple

Great, now when I type Python in my terminal outside my virtualenv, I should see a clang compiled version of python which I do.

nai@nyc:~ » python
Python 2.7.3 (default, Oct 22 2012, 06:12:32) 
[GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.58)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

However, my virtualenvs are still using the old version of Python. So I have to recreate the virtualenv and specifically tell virtualenv which Python to use.

nai@nyc:~ » mkvirtualenv --python=/opt/local/bin/python2.7 greedychimp
Running virtualenv with interpreter /opt/local/bin/python2.7
New python executable in greedychimp/bin/python
Installing setuptools............done.
Installing pip...............done.
virtualenvwrapper.user_scripts creating /Users/nai/.virtualenvs/greedychimp/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/nai/.virtualenvs/greedychimp/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/nai/.virtualenvs/greedychimp/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/nai/.virtualenvs/greedychimp/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/nai/.virtualenvs/greedychimp/bin/get_env_details
[8] 37201
/Users/nai/.virtualenvs/postactivate:disown:15: warning: job is suspended, use `kill -CONT -36852' to resume
[8]  - 37201 done       ctags -f $VIRTUAL_ENV/tags -R $VIRTUAL_ENV/lib/python2.7/site-packages ${PWD}
(greedychimp)nai@nyc:~/Work/greedychimp(develop⚡) » python
Python 2.7.3 (default, Oct 22 2012, 06:12:32) 
[GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.58)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

So running pip install pycrypto should work now.

Explain It Like I’m 5: What is SQL Injection?

It’s mutton time!

One fine Sunday morning, your beloved mother says to you: “Son, could you be a darling and run to the supermarket to get some eggs?”

“Ok Mom!”, you reply and off to the supermarket you go.

Half way there, you spot your Mom and she comes over to you a little awkwardly.

“Son, I’ve changed my mind” she says in a weird sounding voice.

“Forget the eggs, get some baby diapers instead” and as quickly as she appears, she disappears.

So, this all sounds a little weird to you. Why would Mother ask me to get diapers? There isnt’t a baby in the house! In fact, Mom looks kinda weird too. She’s not her usual self.

Something seems a little off but you don’t question wisdom of your mother and happily you get the diapers and return home.

Upon, reaching home, your Mother looks at you and wonders: “Son, where are the eggs? And why on earth did you buy baby diapers?”.

This is exactly what an SQL injection does: it takes the original instructions given by the computer, intercepts it with new instructions. If it’s an malicious SQL injection, the mysterious person masquerading as your Mom might have even told you to buy the eggs and then smash it. But as my friend eloquently put it: SQL injections are by definition not malicious but anecdotally, they almost always are.

Explain It Like I’m 5: What’s a database?

In layman terms, a database is a place where information is stored. If you are familiar with Microsoft Excel, a database is conceptually the same thing. In Excel, each worksheet contains a logical set of information presented in columns and rows. So if you have an employee worksheet, the first column could be Name, the second column Age and so forth. The rows will then represent individual employees.

This is exactly what a database does except it stores these information much more efficiently and effective. So, once you have about 100,000 rows in Excel, it starts to get slow. A database allows you to store millions of records without making it slow for you to retrieve data.

My Top 6 Productivity Tips for Developers or People Who Spend a Lot of Time on the Computer

Top Hit for 'Dilbert Productivity'

Top Hit for ‘Dilbert Productivity’

Every developer has their own little ‘secret’ cache of productivity tricks. Here are some of mine that I use every single day.

Cinch

Cinch is an awesome free app that allows you to snap your opened windows to the side of the screen. This feature is first introduced in Windows 7 (I believe) as Snap and it’s probably one of  the best UX features that have been introduced by the Windows team. My typical setup is to have my browser on snapped on the left side and my terminal screen on my right.

Clip Menu

There are quite a few clipboard managers around, the one that I use is called Clip Menu. If you’re not using a clipboard manager, you’re seriously under-changing yourself. cmd-1 brings up a history of my recently copied items and pressing the corresponding number allows me to paste the contents.

zsh (not applicable for non-developers)

I discovered zsh and oh-my-zsh recently and boy oh boy, am I loving every minute of it. Essentially, it’s gives you all the power of bash but with autocomplete goodness on steroids. Depending on your development setup, you will need to install the relevant plugins by modifying the .zshrc file which replaces the your bashrc/bash_profile settings.

Cloudapp

Does your work involve you needing to share an image/document/anything? I guess most of you would answer ‘yes’. Cloudapp enables you to do this by dragging and dropping the item you want to share onto it’s icon. It uploads the file and spits out a link which you can share immediately. A nice touch is that you get to see the number of times that file has been accessed.

Hot Key Your Mouse

I use two different mice. At home, I have a Razor Naga which I have configured the side buttons to do the following:

  • next/prev tab in chrome hotkeyed to numbers 1 & 2
  • back/forward in hotkeyed to 4 & 5
  • open/close tabs to 3 & 6

At work, I use a Logitech M705. The two side buttons I’ve set to back/forward. I’ve not had to change the batteries in this baby since I’ve gotten it 2 years ago (roughly). Logitech isn’t joking when it says its the ‘Marathon Mouse’.

Also, as any gamer would tell you, a good mouse pad helps.

Always Be Learning While Travelling

You can only do that many days of people watching and blanking out on your commute to work. Why not learn something new everyday instead? Two of my favourite podcasts that I like to tune in to work are: Radiolab and 99% Invisible.

Bonus Hack: Conversation Starter

One of my favourite questions to ask a newly acquainted friend or someone whom I haven’t met for a while is this: what’s the most interesting/meaningful thing that has happened to you since we last met/this year. It’s an awesome starting point to start a conversation as it gets the person talking about something close to his/her heart.

Do you know any good productivity tips? Do share!

Django Create Session Variables in Unit Test

Came across this snippet some time ago but I can’t remember the source. I’ve since used it quite extensively.

def stuff_session(client, dictionary):
    from django.conf import settings
    from django.utils.importlib import import_module
    engine = import_module(settings.SESSION_ENGINE)
    store = engine.SessionStore()
    store.save()
    client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key
    session = client.session
    session.update(dictionary)
    session.save()

To use simply

stuff_session(self.client, {'customer_session_id': '0ABAA842-7E77-2591-3B02-162716195AD6'})

Games will be the death of you

https://i0.wp.com/upload.wikimedia.org/wikipedia/en/0/03/Aybabtu.pngSaw this post on hackernews and the top comment reads:

Giving up video games in my 20s.
If I hadn’t done that, I’d still be stuck in front of a game somewhere.
Those things will eat your life.

 

Games. A huge part of my life revolved around games. I’ve played them all and to some extent, got mostly good enough to pwn noobs in game. As any gamer can tell you, pwning someone, AI or human, is a very addictive feeling. To pwn someone, you need the best gear, the highest EXP, the most organized guild and so on and so forth. It’s a perfectly designed feedback loop.

 

This is my EU League of Legends profile. I’ve clocked about 800 games in 2010 when it first launched. The average length of a game is about an hour so thats 800 hours or 33 days worth of time I spent on that game that year alone. That is also the last game in which I’ve dropped serious time commitment on. Having said that, I have an 80 Engineer in GW2 and a 80(11) Monk in D3 but those were attained casually over many many weeks. Before LoL, I’ve spent countless hours on the Civilisation series, Warcraft 3 (I was ranked on the ladder), Counterstrike (back when AWP had zero recoil)  and so much more.

 

I think playing games in moderation is fine. Nothing like blowing off steam in pub games in TF2 after a long day. Couple of frags bound to make you feel better. However, like most others, I took gaming seriously. Which self respecting gamer didn’t?

 

Looking back now, getting off the hardcore gaming routine must surely be the best thing I ever did.