Setting up KeePassX on Mac OS X Lion

There are many prerequisites in order to build KeePassX on Mac.

Install GnuPG libraries

First download and install libgpg-error.
http://www.gnupg.org/download/#libgpg-error

Build and install. (Should go to /usr/local/*.)

./configure
make
sudo make install

Then, download and install libgcrypt.
http://www.gnupg.org/download/#libgcrypt

Build and install.

./configure
make
sudo make install

Install Qt4

Download and install Qt4 from http://qt.nokia.com/downloads.

Note that in order for me to get the installer to work, I had to install to a subdirectory of my home directory, not in a global location. I think this is because the post-install scripts don’t ask for the proper permissions. They’ll fail if you don’t have write permissions to a directory.

After it was installed, I had to add the Qt utilities to my ~/.bash_profile. For me, these were located in ~/QtSDK/Desktop/Qt/474/gcc/bin.

Build KeePassX

In order to build KeePassX, I had to add a “bundle destination” to src/CMakeLists.txt.

$ diff src/CMakeLists.txt.old src/CMakeLists.txt
  add_executable( ${PROGNAME} WIN32 MACOSX_BUNDLE main.cpp )
  target_link_libraries( ${PROGNAME} keepassx_core ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${GCRYPT_LIBRARIES} ${ZLIB_LIBRARIES} )
- install(TARGETS ${PROGNAME} DESTINATION ${BIN_INSTALL_DIR})
+ install(TARGETS ${PROGNAME}
+     BUNDLE DESTINATION .
+     RUNTIME DESTINATION ${BIN_INSTALL_DIR} COMPONENT Runtime)

Then, as the INSTALL file says, run

mkdir build
cd build
cmake ..
make

Notes

For this project, I thought I had to tell configure to use the 32-bit architecture, since it couldn’t find symbols when I tried the default 64-bit. (It turns out that I just hadn’t installed the libraries in the correct order.)

For future reference, if you need to force a 32-bit architecture, do this.

./configure CC="gcc -arch i386" CXX="g++ -arch i386"
make
sudo make install

Gravity v0.1 released.

I just put a new version of Gravity (beta) on Kongregate.

Changes

I added support for multiple masses and also obstacles. Also, I fixed a bug with the physics system. The physics are much more “realistic” now. Force actually decreases with distance now!

Lessons Learned

When I added support for multiple masses, I noticed that the physics were acting “funny”. It seemed like the little boxes were being more attracted by masses on the opposite side of the map than the to ones they were near.

It turns out that AS3 does not have an exponentiation operator. My late night coding resulted in the following mistake.

// I don't think I ordered an XOR.
var dist:Number = Math.sqrt((massPt.x - object.x) ^ 2 + (massPt.y - object.y) ^ 2);

// this is what I should have said.
var dist:Number = Math.sqrt(Math.pow(massPt.x - object.x, 2) + Math.pow(massPt.y - object.y, 2));

Also, it turns out that Flixel makes the nice memory-saving optimization of reusing graphics of the same size when you do makeGraphic(). I had to tell it to make a unique version so that I could change the background color on my buttons for add / remove.

Gravity for the 0h Game Jam

gravity screenshot

Gravity Screenshot

Last night was the 0h Game Jam, since it was daylight savings. You can play my game at Kongregate.

I decided to make a very simple physics game, where you place a mass in order to make the little “crates” hit a target.

Overview

The main idea of the game is that it is a puzzle game build around Newton’s gravity equation. Force = G * Mass1 * Mass2 / Distance^2

Lessons Learned

Most of my time was spent just getting Flash Builder to compile a template project. I should have created an ActionScript project instead of a Flex project.

Once I got going, I think I did the right thing by not worrying much about making it have just the right architecture. Instead, I created one FlxState and did all the game logic there. For a simple game like this, there wasn’t much need to to make things object-oriented.

Plans

I hope to make more levels and add obstacles to make this more of a puzzle game. Also, I’d very much like to port this to mobile devices.

Python String Formatting

So, say you had a console Python application where you are trying to print a table of numbers as your output. You could just say

print label, number_1, number_2, number_3

and your table would end up looking like:

The first row 1.001 2.0983 10.12 Another row 11.4 3.144 35.973 Look! Yet another row 12.6 99.72 1.892

Yikes, that table is a bit on the ugly side! There must be a way to get Python to create a better looking table of numbers. Good for us, there is. Batteries are included, after all. A quick Google search yields us a handy page in the docs saying we can use c-style string formatting, but it is a bit light in the examples department. Hopefully, I can shed some light on the issue.

Read more

More fun with Python (the ternary operator)

The ternary operator is one of those things that’s not really necessary, but can make code quite a bit shorter when put to good use. For those of you who don’t know, the ternary operator is a way to evaluate one thing if a condition is true, and a different thing if the condition is false.

C and it’s relatives have had this for quite some time in the form:

(condition) ? (evaluate when true) : (evaluate when false); 

Python users, on the other hand had to resort to cryptic uses of the ‘and’ and ‘or’ operators. See, Python boolean operators don’t need to act on a boolean like those in Java/C# they’ll happily accept most everything and do the following:

(evaluate this first) and (return this if the left was true) (return this if it's true) or (return this if the left was false) 

Luckily, although you can construct a ternary looking statement from the way ‘and’ and ‘or’ work, there is a better way–or at least a way that is easy to understand without know how the and/or operators work behind the scenes. It was added as PEP 308 after all voting took place and there was no preferred syntax, Guido used his position as Benevolent Dictator for Life and chose the following syntax:

(expression one) if (condition) else (expression two) 

Where expression one is returned when condition is true and expression two is returned when condition is false.

Python List Comprehensions are Easy!

I’ve know about list comprehensions for a while now, but I never really bothered learning how to use them. Today, I found that they really aren’t that bad. In fact, if you already know how to populate a python list inside a for loop, you’re 95% there already.

Read more