Category Archives: Hacks

Building reputation on Stack Exchange sites

Gamification… is ADDICTIVE! I got hooked on basically “collecting meaningless points” on the Stack Exchange sites. As I was building up a “know-how” of doing this, I started drafting this post. Then I gave up actually posting it, thinking “what the hell do I know about this stuff anyway with my puny reputation”?

But then, what do you know, @DuncanLock who has similar reputation as me has posted his own take on the subject, and guess what, he got literally hundreds of good reactions, including high-profile Stack Exchange users, moderators, and even @codinghorror himself:

The Smart Guide to Stack Overflow: Zero to Hero

I commented on his blog a few extra tips of my own, but later I realized I still have some more to say. So here we go, my follow-up tips for building reputation on the Stack Exchange sites, on top of what Duncan already covered nicely.

Get the basics down first

informed1. Do read the entire About page. Carefully. It’s really important to understand the site. Plus you get the Informed badge as a reward! This page is also important to understand the counting of reputation: http://stackoverflow.com/help/whats-reputation (especially the daily max 200 limit!)

2. Be patient. It takes time to build reputation. If this was easy within a matter of days the system would be meaningless.

3. Be civil and professional. Don’t lash out on poor quality questions/answers/comments. Vote down if you don’t like something and move on. Don’t take anything personal, be cool.

4. Be a good sportsman. If somebody else posted a better answer than yours, admit defeat and move on. If somebody answered first something just as good as yours, vote it up and move on.

Finding questions to answer

1. Look for questions in your favorite areas of expertise. There’s much more than stackoverflow.com, take a look around the many other Stack Exchange sites. If you’re a programmer, check out http://programmers.stackexchange.com/. If you’re more of a sysadmin dude, head over to http://serverfault.com/ or http://askubuntu.com/. If you’re a UNIX/Linux expert, you will enjoy http://unix.stackexchange.com/. There’s probably something for everyone.

2. Be selective when you pick a question to answer. Figuring out what the heck a poorly written question is supposed to mean might not be worth your time and effort. And if you are not 100% sure you have a great answer immediately, then somebody else will probably beat you to it. It’s often better to just move on.

3. Devise question hunting strategies and combine them efficiently. I use the following basic strategies:

  • Fast-read the newest tab (click on Questions if you don’t see it), fishing for easy questions and try to be the first to answer. New questions are very visible because they are on the front page. That also means you don’t have much time to research to give a good answer.
  • Search by tags to find questions in your strongest subjects. Sometimes there are easy questions that dropped off the front page of newest questions. This can be very lucrative, as you are looking at questions in your strong area, and you have more time to research and give a good answer.
  • Only open questions with 0 or 1 answer. Often the first answer is not that great, and it’s quite possible that you can do better. When there are 2 or more answers it becomes less and less likely that you can give a better answer.
  • If you are tired of one site, or while waiting for a new set of questions to accumulate, switch to another site.
  • Setup filters on http://stackexchange.com/filters/new and email notifications of new questions in your favorite areas. This is most useful for tags with only a few questions per day or less. This is not useful at all for highly active tags with many questions per hour.

Typically I quickly scan the new questions. Usually I find a few I might be able to answer, read them properly, and if enough time passed, then if I reload the page I see a completely new set of questions. If I don’t see anything suitable, then I check on my favorite tags for a few minutes, and switch back again to the first strategy. Or instead of checking on favorite tags, I can switch to another stack exchange site.

4. Something that helps me a lot answering questions well (= actually getting rewarded for it) is to hunt questions when I’m deeply into something. For example, after about a week of Android hacking, suddenly I can answer many questions well and fast, because I’m just really right in the middle of it. Not to mention that when deep into something I usually have my own questions, and very often find answers that almost work but not quite, which is another good opportunity to post my own.

Drawing attention

Sometimes your otherwise great answer might not be getting the attention it deserves… Luckily there are quite a few things you can do to improve that.

1. If you intend to answer or already answered a question, don’t vote it up immediately. After answering, give it a few days, and if there is no reaction on it, then come back to it and vote it up. Such activity will bring the question up to the front page again, becoming more visible again, especially to the poster who will receive a notification in his Inbox. And if your answer is accepted, then be a good citizen and vote up the question. (You should not answer questions you don’t like anyway.)

2. Share your answer (or question) on your social networks. It’s very easy to use the [share] link right under the question/answer. Same with voting up the question, do this after a few days if the question is inactive.

3. Improve your answers. From time to time review your answers with zero upvotes and see how they can be better. Perhaps they were not clear enough, or maybe you answered too quickly and misunderstood the question. If the answer is not something you can proudly show to your friends, then maybe it’s better to delete it.

Collecting badges

Badges are cool goodies, but they don’t get you any reputation. They sure look good in your profile though 🙂

civic-duty1. Personally I don’t hunt badges. I think you can just let them come to you naturally. For example, you get the Civic Duty badge if you voted 300 times. That’s so cool, I didn’t even know it existed, and one day I just got this in my Inbox, yeay!

electorate2. Some badges reward you for using the site in a sort of “balanced” way. For example, you get the Electorate badge if you voted on 600 questions and 25% or more of total votes are on questions. The site also warns you if you vote mostly on answers only, saying that questions need loving too 🙂

Becoming a seasoned veteran

profile for janos on Stack Exchange, a network of free, community-driven Q&A sites

1. Once you have built up some reputation, embed “a piece of valuable flair” on your website, for example: http://stackoverflow.com/users/641955/janos/flair

2. Check out the Stack Overflow “leagues”:
http://stackexchange.com/leagues/1/alltime/stackoverflow

You can see the heaviest hitters by week/month/quarter/year/all-time on all Stack Exchange sites, as well as your own rank.

Another interesting thing on your profile page on stackexchange.com (different from stackoverflow.com) is the reputation tab shows a graph of your reputation score changes, for example:
http://stackexchange.com/users/322516/janos?tab=reputation

By the way, on your Stack Overflow profile homepage (not Stack Exchange), in the Reputation section you can see a link to the leagues, in a format like “top 3% this quarter”. The value shown can be about the quarter, week, month or year, depending on whichever is highest for you, and it takes you right to your position in the leagues.

rep-top-info

3. See what privileges you can unlock by earning higher reputation:
http://stackoverflow.com/privileges. It’s really cool how more and more interesting features of the site start opening up gradually. In a way it’s like going deeper down in the rabbit hole. For example, after about 2000 you can start moderating various types of posts (new users, low quality, etc), which reward you with new badges.

4. It seems that if you are active on a Stack Exchange site, sooner or later you get invited to http://careers.stackoverflow.com/. It’s a very cool site where you can list your competencies much better than on LinkedIn, for example. Not only you can showcase selected high-scoring questions and answers from Stack Exchange, you can also highlight your most interesting open-source projects on GitHub or other code hosting sites. (You can check out mine here for example: http://careers.stackoverflow.com/janosgyerik)

Conclusion?

At the end of the day, I’m not sure how much effort is worth investing in reputation building, so I leave that up to you 🙂 Answering questions is probably similar to teaching: you always learn something even while you teach, so if nothing else, at least you have that!

Add Disqus to your WordPress or other blog

I’ve seen a couple of blogs using Disqus to show comments, but never really cared enough to check it out. Until now, and it looks like a pretty good idea!

  • Readers can “login” to comment using their Twitter or other social accounts. They don’t need to enter the usual boring stuff like name, email, website address anymore.
  • It gives you much more granular control for managing your comments compared to native WordPress, and in general it’s jam-packed with features.

Mainly I’m counting on that switching to Disqus will attract more comments. I myself feel it off-putting when a website is asking my name and email instead of letting me authenticate with an OpenID provider or Twitter. Sadly this blog was doing that too… Not anymore! This is definitely a good improvement.

I’m still discovering this thing, but it looks really useful. I might post more details later to highlight the best features that really work for me.

To get started using Disqus on your blog:

  1. Create an account if you don’t have one already
  2. Register your site on https://disqus.com/admin/signup/ and follow the steps for WordPress or whichever other publishing platform you use. At least with WordPress, the steps were very accurate and easy to follow, a smooth process. Disqus gives you a pretty cool dashboard with many interesting settings.
  3. You can import your existing comments, Disqus reminds you of this during setup

By default Disqus shows ads, supposedly for your benefit, which is not so cool. Luckily it’s easy enough to switch it off on the Disqus admin. In case Disqus doesn’t really work out, you can export comments and import to something else later (or back to your WordPress).

ImproperlyConfigured: The SECRET_KEY setting must not be empty

I hit by a strange issue with Django. If I try to use a local configuration with

./manage.py shell --settings=myproject.local_settings

I got the error:

ImproperlyConfigured: The SECRET_KEY setting must not be empty

Strange because SECRET_KEY is certainly set. No stack trace, just a single line of error.

The cause turned out to be that in the main settings.py file I imported a method from one of my apps like this:

from accounts.views import render_failure
OPENID_RENDER_FAILURE = render_failure

I don’t understand why exactly this is a problem, but removing the import solved the issue. On the other hand, I needed that import as the OPENID_RENDER_FAILURE setting of the django-openid-auth package takes a callable, giving it the absolute function name accounts.views.render_failure as a string doesn’t cut it. I worked around that like this:

def render_failure(*args, **kwargs):
    from accounts.views import render_failure
    return render_failure(*args, **kwargs)
OPENID_RENDER_FAILURE = render_failure

Now everything works fine.

Deploying new releases using Git and the post-receive hook

I used to deploy new versions of my websites like this:

  1. ssh to the server
  2. cd to the website project directory (under version control)
  3. Update from VCS to the latest version

Doing this a few times is ok, but if you want to release frequently it’s better to automate these steps. One way to do that is using the post-receive hook of Git like this:

  1. Setup a mirror repository on the server called “releases”, with a branch called “beta”
  2. Make the deployment directory track the “beta” branch of the “releases” repository
  3. Setup a post-receive hook in the “releases” repository to trigger a script that updates the deployment directory (perform a git pull or git checkout -f)

The goal of this setup is to simplify the deployment steps to a single git push command from my local development/test environment to the releases repository. Then thanks to the post-receive hook, the pushed changes will be automatically propagated to the deployment directory, without manually logging in to the server.

First I created the releases repository from my deployment directory:

Next I created the post-commit hook:

(Hook scripts are in the hooks/ directory of a Git repository, and must be executable.)

I typically use two branches: “beta” and “prod”, and reuse the same “releases” repository for these. The above hook script checks the branch that is being pushed to, and checks if an upgrade script exists with the filename in the format “upgrade-BRANCHNAME.sh”. The real upgrade scripts exist in my deployment directories, because I don’t want to have too much logic inside the Git repository directory, I prefer that to be together with the project itself. In the Git repository root I put only symlinks to the real upgrade scripts.

Writing an upgrade script depends on your project. Here’s an example from one of my Django sites:

The script is written in a way to be reusable in multiple of my Django sites, but you may need to adjust to match your typical deployment. The unset GIT_DIR is necessary, because it seems the variable is automatically set when the hook is executed, otherwise the git pull operation would result in the error:

remote: fatal: Not a git repository: '.'

Finally, I setup the releases remote in my local Git project:

# go to the directory of my local project
cd ~/project/dir

# add the "releases" remote
git remote add releases ssh://user@example.com/home/user/path/to/project.git

With this setup in place, deploying a new version is as simple as:

git push releases master:beta

To make it even easier, I created aliases in my .gitconfig:

deploy-beta = push releases master:beta
deploy-prod = push releases master:prod

Using XBMC with an external player

First of all, XBMC looks really awesome:

I’m using XBMC mainly to watch my favorite internet streams, such as TED and vimcasts.

I’m not using it yet for my movie collection, because I have some issues with its built-in player:

  • Adjusting the volume is not easy enough: in VLC I can just use the mouse scroll
  • Adjusting the aspect ratio is not easy enough

Finally I figured out how to use an external player. I created a configuration file in ~/.xbmc/userdata/playercorefactory.xml like this:

This way it will use VLC for local video files only, and continue to use the built-in player for others.

For more information on hacking the configuration, see the docs.

Using custom fonts on Android

The default fonts you can choose from when developing for Android are not very interesting. Normally they are OK for my simple purposes, but for once I wanted something a little bit prettier for my new app, Happy Moments.

I found this tutorial very useful for using custom fonts on Android:

http://mobile.tutsplus.com/tutorials/android/customize-android-fonts/

And I found some pretty nice fonts on this site suitable for the concept of my app:

http://www.fontsquirrel.com/fonts/list/category/Handwritten

Here’s the gist:

Step 1: Find a nice font and put it in your assets/ folder

Step 2: Set the custom font in code (which is the only way to do it), like this:

TextView message = (TextView) findViewById(R.id.message); 
Typeface font = Typeface.createFromAsset(getAssets(), "Chantelli_Antiqua.ttf");
message.setTypeface(font);

And voila, the result in the app itself:

Fixing system date out of sync in Debian

I started using my old-ish Debian server again and realized the system date is off by 20 minutes…

The solution is to install ntpdate, which automatically synchronizes the clock at certain system events, for example when the network interface comes up.

To force synchronizing now, you can run ntpdate manually, but you must specify the NTP servers to use as reference on the command line, otherwise it will give you an error like this:

14 May 06:53:06 ntpdate[6505]: no servers can be used, exiting

An easier way is to run ntpdate-debian without arguments, which will use the NTP servers configured in /etc/default/ntpdate, which is a Debian-specific setup.

Viewing old revisions in the web browser interface of Subversion

If Apache is configured to browse a Subversion repository, its files and directories are shown as of the latest version by default, for example:

http://svn.apache.org/repos/asf/subversion/trunk/

If you want to browse the content of older revisions, there is a non-trivial way by inserting /!svn/bc/REVNO between the base URL of the repository and the path component of the target directory inside the repository, for example you can browse the contents as of revision 1234123 like this:

http://svn.apache.org/repos/asf/!svn/bc/1234123/subversion/trunk/

Hacking contest on a Live CD

I built a remastered Linux Live CD that should be interesting, educational, and highly entertaining for any self-respecting programmer: a security challenge with 6 levels based on the online contest created by Stripe in early 2012.

The CD contains a very light Linux system (based on Tiny Core), the ISO image is less than 30 megabytes. You can download it from here:
https://sourceforge.net/projects/ctfomatic/files/

The easiest way to use the Live CD is with a software like VirtualBox: create a virtual machine with no hard disk and 256MB memory and point the CD device to the ISO file and that’s it, start the VM! The Live CD uses US qwerty keyboard by default, you can change that by passing a boot parameter at the boot prompt, for example:

boot: kmap=azerty/fr

Alternatively you can use the shortcuts frjp or hu for French, Japanese or Hungarian keymap, respectively.

When the system starts you are logged in as user level00. You will be presented with a hint that should help you gain access to the password of user level01. Your mission, should you choose to accept it, is to find and exploit the vulnerabilities presented at each increasingly difficult level, advancing forward until you reach level06 (and celebrate!)

By completing this challenge you will become a better programmer:

  • You will increase your awareness of the importance of security, and probably write more secure, more robust code in the future.
  • You will improve your skill of finding problems and weaknesses, which is the critical first step in optimization tasks.
  • You will have a wonderful time, and come out enlightened!

The source code of the scripts used to build this CD is available on GitHub:
https://github.com/janosgyerik/capture-the-flag

Have fun!

Gource is a cool VCS visualization tool

Gource is a really cool open-source software to visualize the revision history of your projects, whether you’re using Git, Bazaar, Mercurial or Subversion.

https://code.google.com/p/gource/

The project website has many cool example screenshots generated from the repositories of famous projects such as the Linux kernel or Git.

Here’s what some of my projects look like in gource:

1. Revision history of Bash One-Liners:

2. Revision history of the RecipeNotes App:

To generate these videos I used the following commands on Mac OS X:

gource --file-idle-time 0 --seconds-per-day .3 -640x480 -o gource.ppm
ffmpeg -y -r 60 -f image2pipe -vcodec ppm -i gource.ppm -vcodec libvpx -b 10000K gource.webm