Integrate GameCircle With an Ant Project

I was integrating an Android game with GameCircle by following Amazon’s documentation, and I eventually arrived to “Initializing GameCircle in Your Game”. The documentation instructs to import GameCircle SDK into Eclipse’s workspace and add it as a dependency. Since I wasn’t using Eclipse, I had to setup the dependency using Ant.

GameCircle SDK looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
GameCircleSDK/
├── AndroidManifest.xml
├── bin
│   └── placeholder.txt
├── gen
│   └── placeholder.txt
├── jni
│   ├── includes
│   │   └── ...
│   └── libAmazonGamesJni.so
├── libs
│   ├── AmazonInsights-android-sdk-2.1.16.jar
│   ├── gamecirclesdk.jar
│   └── login-with-amazon-sdk.jar
├── project.properties
└── res
    ├── drawable
    │   └── rounded_corners.xml
    ├── layout
    │   └── modal_overlay_container.xml
    ├── raw
    │   └── amazon_gc_prototype.zip
    └── values
        └── amazon_gc_styles.xml

The obvious and easy solution is to merge all these files into my project. It would work, but I would prefer to keep the SDK external to my source tree to make updates easier. It can be done in two easy steps.

Step 1 – Add GameCircle as a reference

In my project, I first added the SDK path to local.properties:

1
sdk.gamecircle=../../../tools/Amazon-SDK/Android/GameCircle/GameCircleSDK/

This file isn’t checked into source control, so it’s a good place to put a machine-specific path. The path must be relative, because Ant treats / as the base of the project and not the root of the file system. Then I referenced the SDK in project.properties.

1
android.library.reference.1=${sdk.gamecircle}

When I tried to compile, I got an error:

1
2
BUILD FAILED
/.../tools/ant/build.xml:601: Invalid file: /.../GameCircleSDK/build.xml

Step 2 – Prepare GameCircle for Ant

In GameCircle SDK, generate build.xml:

1
android update lib-project --path /path/to/gamecirclesdk

Still one error remaining:

1
2
BUILD FAILED
/.../ant/build.xml:659: /.../GameCircleSDK/src does not exist.

I just created an empty directory named src, and the project compiled successfully.

Done! I could continue following the documentation.

Compressing PDFs With Ghostscript

Previously, I was using Photoshop to processed scanned documents, convert them to PDFs and compress the PDF. The resulting PDFs were usually less than 800KB and that was OK for me. Lately I started using GIMP instead of Photoshop for this task and the PDFs that GIMP produced were a few megabytes in size. I looked for a way to compress them and found a nice utility called Ghostscript that processes PDFs and PostScript files. Here’s a script I found to compress PDFs using Ghostscript:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh
set -e

if [ "$#" -ne 1 ]; then
  echo "Usage: $0 pdf-file" >&2
  echo "Compresses a PDF file using ghostscript" >&2
  exit 1
fi

TMP_FILE=/tmp/$(basename "$1")
mv "$1" "$TMP_FILE"
gs    -q -dNOPAUSE -dBATCH -dSAFER \
    -sDEVICE=pdfwrite \
    -dCompatibilityLevel=1.3 \
    -dEmbedAllFonts=true \
    -dSubsetFonts=true \
    -dColorImageDownsampleType=/Bicubic \
    -dColorImageResolution=72 \
    -dGrayImageDownsampleType=/Bicubic \
    -dGrayImageResolution=72 \
    -dMonoImageDownsampleType=/Bicubic \
    -dMonoImageResolution=72 \
    -sOutputFile="$1" \
    "$TMP_FILE"
# rm "$TMP_FILE"

The last line that removes the temporary file is optional because I would like to have a copy of the original file if the compression ends up looking too bad.

Powerline Segments Not Showing Up in Tmux

Note to self.

When I set up a new Mac, I like to install Powerline for tmux. Powerline documentation recommends installing using:

pip install --user git+git://github.com/Lokaltog/powerline

This install Powerline into the user directory, to ~/Library/Python/2.7/lib/python/site-packages/powerline. When I fire up tmux I don’t get the “segments” that are usually found at the bottom right of the screen. This happens because they rely on the powerline executable, which was installed to ~/Library/Python/2.7/bin/. This path isn’t in my $PATH by default.

Solution: Add ~/Library/Python/2.7/bin/ to $PATH.

Testing Octopress

Blog running on Octopress running on Jekyll running on Github Pages sounds like fun.

1
2
3
4
def add(x, y):
    print 'Adding numbers %d and %d' % (x, y)
    result = x + y
    return result