Category Archives: Musings

Practical tips & tricks in the Linux shell

I put together this simple presentation about a few simple but very effective practical tips that should make you lightning fast on the command line. I use these literally every minute I spend in the shell. All the tips should work in Linux, UNIX, BSD and similar.

  • I used many tips from Zach Holman’s blog to “design” the slides.
  • I created the presentation using Google Docs, but it was not really a great experience:
    • The dotted green line you see under headings is not intentional, it appears only after exporting to PDF. I don’t know why. I would prefer it without the line as shown correctly in Google’s viewer, but I want to use Speaker Deck as it is not blocked at my workplace and has a better WordPress plugin.
    • The JavaScript seems to go crazy in the presentation editor. The longer I use it, the heavier it gets, until I do a clean fresh reload.
  • I used the Speaker Deck Embed plugin to embed the presentation here. Oh and Speaker Deck is really awesome.

Computer and IT Quiz

Recently I started contributing to this fun Computer and IT Quiz app on Android:

Android app on Google Play

Mike Heyworth created the original app, I contributed mocks and elements for the new design, which Mike incorporated in the latest version of the app released just a few days ago. If you are in IT, do try it out, challenge yourself, test your skills, and just have fun with it!

If you like this FREE app please do buy the PRO version and support us!

More usability and design improvements will be coming soon (1-2 months), so stay tuned!

 

Capture the Flag 2.0

Another nicely put together hacking challenge by @stripe.

https://stripe.com/blog/capture-the-flag-20

Flex your hacking muscles in 8 increasingly difficult challenges. This time the challenge is more web oriented. What? You think just because you’re not a web programmer you don’t need to know this stuff? Oh I think you do mister! Now get your ass over there and put some effort in it. The contest ends on August 29, 2012.

You can skip the intro and dive right in on this page:

https://stripe-ctf.com/account

How to get involved in an open-source project?

Obviously everybody has a different approach to this. Mine involves these main elements:

  1. Find a project you like
  2. Find a project that needs you
  3. Jump in

How to find a project you are interested in?

Ask yourself:

  • Is there a particular open-source software that you just love so much?
  • Is there an open-source software that is almost what you want but just almost?
  • Is there an open-source software where somebody you admire is involved in?

How to find a suitable project that needs you?

Based on your answers above, get on Google and find the website of a suitable project. Some additional factors to look for:

  • When was the last commit? (i.e. recent enough?)
  • How many active committers are there? (i.e. more than one, less than 10?)
  • Which VCS do they use and how can you submit branches? (i.e. a VCS you don’t mind using)

How you evaluate these factors is entire up to you. Personally I prefer small-ish projects where my work will be noticeable, but not too small where the developers might not be too welcoming to new faces.

How to get involved?

Please, please suppress your inexplicable desire of sending an introductory mail saying “hey I’m here I want to work on X”. Do NOT send such rubbish. Also do NOT brag about your past projects either.

The only meaningful introduction is contributing code, period! Just pick something you can improve in the project. Anything! Preferably something small, and indisputably an improvement. Your first commits should not be about showing off your genius. Your first commits should NOT be a big refactoring that makes more sense to you. Your first commits should be small, rock solid and easy to accept. In the beginning keep doing small things, gradually bigger and bigger.

Coding style: in the beginning you just have to adopt the coding style used by the others. Make sure to spend some time on observing the coding style of the core contributors, and adopt the same style in your own contributions. If you disagree with it you can propose an alternative later after you are already a recognized member.

Caution!!!

Be patient. Don’t get your hopes high early. It takes time to get to know the members, and it is impossible to know in advance if your personalities will be compatible or not.

If for some reason things don’t work out with the project you picked, don’t let that bring you down. There are plenty of fish in the ocean of open-source projects, don’t expect you’ll find the right one for the first try. Be patient and keep looking. As long as you learn something from the experience, your efforts will never be wasted.

From zero to Django: get Django going in windows within minutes

My 5-step banana ice cream recipe got more reaction in one hour than my usual geeky posts in years. Maybe I should combine the two concepts! Or maybe not. Heck, I already like this title so here’s the geeky recipe: a decidedly imperfect recipe for getting my django project up and running on a fresh new install of windows.

Preparation time

minutes!

Ingredients

Preparation

  1. (optional) Install putty, create ssh key with puttygen, save private and public keys, add to authorized_keys on repository server, start pagent, add the key to it.

  2. Install python, install setuptools

  3. Edit environmental variables:
    1. Append to PATH: c:\python27;c:\python27\scripts
    2. Set BZR_SSH=c:\program files\putty\plink.exe
  4. (optional) Install git

  5. Fire up the bash terminal (git bash or DOS command prompt)

  6. easy_install pip

  7. (optional) Install Bazaar, bzr co bzr+ssh://myserver/~/repos/project

  8. Install Django using pip: pip install django==1.4 (use the version you need!)

  9. Install dependencies of the Django project, typically listed in a file: pip install -r requirements.txt

  10. Run in Django’s local server: python manage.py runserver

Best served in a modern browser like Chrome at http://localhost:7000/ Enjoy!

Variations for the more adventurous

  • Screw putty, use the openssh that comes with git bash
  • pip install virtualenv, create a virtual env and run Django inside it.

How can I decide which permissions to allow or disallow to an Android application?

As far as I know, I cannot. When you install an Android application you get a list of “permissions” the app wants to use, but you have only two choices, all or nothing: allow all permissions and install the app, or don’t install at all.

A few days ago I needed a random number generator, basically to simulate a dice. Sounds simple enough, I thought there must be an app for that. So I tried a couple, but they all require some permissions I really don’t want to give, for example:

  • Random Number Generator #1
    • Network communication – full internet access
  • Quick Random Number Generator
    • Network communication – full internet access
    • System tools – prevent phone from sleeping
  • Random Number Generator #2
    • Network communication – full internet access
    • Your location – coarse (network-based) location
  • Random Number Generator #3
    • Network communication – full internet access
  • Dice
    • Network communication – full internet access
  • Dice Me Online Free
    • Network communication – full internet access
    • Phone calls – Read phone state and identity
  • Simple Dice (Free)
    • Network communication – full internet access
    • Storage – modify/delete SD card contents
    • Your location – coarse (network-based) location, fine (GPS) location
    • Phone calls – read phone state and identity

At this point I give up. It’s too hard to find an app that just generates random numbers without requiring any permissions. I get it, many of the above apps are free, and probably it’s because of the in-app advertisements that they require internet access.

Wouldn’t it be great if instead of just getting a list of permissions an app wants, I could select with checkboxes the permissions I’m willing to allow? Apps could query if they have some permission and handle it gracefully if not. That would be great. Wonder why they didn’t make it work like that in the first place. Advanced search where I can specify permissions I’m willing to allow would be nice too.

Installing Subversion plugin in Eclipse

Sometimes Eclipse really sucks. Today I wanted to upgrade my subversion plugin and ended up wasting a lot of time on it.

How to upgrade a plugin in Eclipse?

  • Help / Check for Updates
    • This will scan all your plugins, taking a long time, when I want to upgrade one specific plugin
    • In this case it’s also pointless (as I found out later), as the Subversion plugins are on separate upgrade sites per version (different site for 1.6, 1.8, etc)
  • Help / Install New Software
    • It seems this is the way to go, but why so non-intuitive name?

Well this didn’t work. I got all kinds of errors that didn’t make much sense:

  • “Cannot install XYZ plugin because it already exists. Upgrading instead.”
    • Except it could not upgrade, due to some conflicts in dependencies which again, didn’t make much sense.
  • Next I tried uninstalling all Subclipse related plugins to resolve the conflicts.
    • The uninstall seems to work successfully, but when I try again the install, it still complains that XYZ plugin is still installed.
  • Next I tried removing all the files in ECLIPSE_HOME/plugins that seem related.
    • Then I get stuck when downloading the new jars, ”read timed out”
      • … despite the fact that I can download those files in a browser
      • … despite the fact that some of the mentioned files are already downloaded in the plugins directory
      • … same result even if I manually download the jars and put them in plugins directory

The final solution was to download the ZIP file from the Subclipse site and install locally, from here:

http://subclipse.tigris.org/servlets/ProjectProcess?pageID=p4wYuA

Eclipse is (usually) pretty great. If only they could iron out these kind of issues already. They existed for as long as I can remember…

Why use git with the centralized Subversion repository at your workplace

Subversion is pretty mainstream these days. Luckily, git can work with a Subversion repository just fine. So, just because your workplace is using Subversion as the central repository, you can work with it using git if you want. Using git you can checkout from Subversion, use it locally enjoying all its benefits, and occasionally commit your work back to Subversion.

Let me give you some real practical reasons why you absolutely should use git instead of Subversion on the client side:

  1. With git you have the complete revision history locally. History operations do not need network access, and are therefore very fast. (You do know that git is the fastest version control system out there.)
  2. All commits are local, not automatically applied to the central repository. This way you can break down large tasks to several smaller commits which, being local only, will not have side effects on others. Temporary instabilities introduced by your changes as you make progress will never affect your coworkers. After your feature is completed and stable, you can push your local commits to the central Subversion repository.
  3. Creating local branches is easy and efficient. In git you can have multiple branches living inside the same working directory, and switch between them easily. This makes it very easy to switch between different tasks, or trying different implementations of the same task, without creating unnecessary copies of the project’s workspace. Subversion handles branch operations very poorly, so you might not be used to using a lot of branches. Git handles branch operations very well, and you once you get used to branching often, you will benefit greatly from it.
  4. Subversion litters all sub-directories of the project with .svn directories. Git works differently, there is a single .git directory in the project’s root directory. Among other things, a nice side effect of this is that you can easily do things like grep -r.

In short: if you are using a Subversion client instead of git, you are really missing out on a lot of benefits git could bring to you.

Btw…

  • Git is cross-platform (works on Linux, Windows, Mac)
  • There is a nice plugin for Eclipse, and probably most other major IDEs as well
  • On Windows it comes with a superb bash terminal and other core unix tools, which is a lot leaner than a cygwin beast when all you need is bash, awk, sed and perl…

What’s the catch?

  • Eclipse integration does not work as well as Subversion:
    • The Team Synchronization function may not work well, depending on the repository. In particular if the line endings in the project are not consistent, using a mixture of windows-style and unix-style line endings.
    • I don’t know how to do git svn rebase and git svn dcommit from Eclipse itself, so you might need the command line for that.
  • You really have to spend some time to learn it properly. Git has a unique way of thinking which is different from Subversion. You will need to understand git before you can use it effectively.
  • The first checkout takes a lot longer compared to Subversion, because git gets the entire repository history. But this is something you only need to do only once. As a nice side effect, you will have a backup of the central repository. Should the central repository die a horrible death, it could be rebuilt from a git checkout.

Links

Start a local repository and push it to a server later with Bazaar and Git

Once you get comfortable with distributed version control, this probably becomes a habit: whenever you start hacking on something new you create a local repository right away, and only later on you push it to a server (for backup). With Bazaar you can even switch to a centralized workflow (the server becomes a master) at any time (and switch back).

With Bazaar

To push a local repository to a server, the bzr command must be installed and on the $PATH of the user.

cd /path/to/your/new/project
bzr init
bzr add
bzr commit -m 'first commit, added all files'
bzr push bzr+ssh://username@server/home/username/path/to/repos/bzr/project

Extra tips:

  • If the parent directories don’t exist on the  server, then use –create-prefix to create all parents
  • To switch to a centralized workflow where your local commits will be automatically pushed to the server do “bzr bind”, and to switch back do “bzr unbind”

With Git

To push a local repository to a server, the git command must be installed and on the $PATH of the user.

cd /path/to/your/new/project
git init
git add .
git commit -m 'first commit, added all files'
git clone --bare . project.git
rsync -a project.git username@server:path/to/repos/git/project.git
rm -fr project.git
git remote add origin username@server:path/to/repos/git/project.git

The step of pushing to the server is less intuitive in Git compared to Bazaar, but I am still new to Git so there might be a better more elegant way. (Please comment if you know!)