Website Update

I am currently in the process of posting all my projects and try to organize them here.  I also realize the documentation of most of my Sublime Text plugins is lacking, so I will try to update this as well.  Bear with me during this process, if you stumble upon anything broken, feel free to contact me!

Thank you for your support and your understanding!

C++11 and Sublime Text 2

Wanting to test out C++11, I first tried using Visual Studio 2012 hoping they would have implemented most of the standard. I first started with the literal operator, and apparently it’s not implemented yet, bummer.

Since I love Sublime Text 2 and I hadn’t tried the build system on it yet, I decided to try it out with gcc.

Unfortunately (on Windows), when using Tools -> Run, you will be greeted with:

[Error 2] The system cannot find the file specified
[cmd:  [u'bash', u'-c', u"g++ 'C:\\Development\\C++11\\helloworld.cpp' -o 'C:\\Development\\C++11/helloworld' && 'C:\\Development\\C++11/helloworld'"]]
[dir:  C:\Development\C++11]
[path: ... my path ... ]
[Finished]

This is simply because the platform doesn’t provide bash and g++. It can easily be fixed though.

This MinGW distro provides you with everything you need to compile (gcc 4.7.2) and this port of bash does a pretty good job. You simply need to add the path where you put these files to the Environment Variable PATH.

After restarting Sublime Text 2 so it gets the new environment variables, you should be able to compile and run your file, giving you an output similar to:

Hello World.
[Finished in 2.7s]

Hashids for Python

Just a quick post to let you guys know that I ported the hashids library to Python. This is an initial submit but more docs and examples are coming soon!

I’m not a Python expert so feel free to contact me if you know ways to improve the code!

Embedding Python and Boost.Python

I recently decided to revamp an old 2D engine I wrote ages ago.

Before writing new code (for one, I wanted to convert the 2D blits to OpenGL and use textured quads), I decided it would be wiser to integrate Python to quickly write scripts to

  • Define Levels
  • Define Sprites and Animations
  • Script enemies
  • etc…

Unfortunately, integrating Python proved to be a harder task than I expected. I first took a look at SWIG but I didn’t like that it required conversion files… Boost.Python seemed a bit better as it seems to handle all the glue code internally so that you can simply build your C++ and automatically have your classes and functions available in Python.

After following the advise of Jon Skinner I decided to go with the “latest” builds of both Python (3.3.0) and Boost (1.52.0). This meant that I couldn’t use prepackaged versions of Boost, I would have to build it myself.

Building Python was a charm, it’s a very simple process.

Boost on the other hand, is not so simple. After fighting a lot with bjam to compile Python using the instructions in this tutorial, I decided to try a few things and simplify the problem. As described in the stack overflow question, things got hairy, but I decided to simplify things even more. I would pass as little arguments as bjam as possible and see what would happen. To my surprise, simplifying my user-config.jam to:

using python : 3.3 : C:\\Development\\Python-3.3.0\\PCBuild\\python.exe
    : C:\\Development\\Python-3.3.0\\Include C:\\Development\\Python-3.3.0\\PC
    : C:\\Development\\Python-3.3.0\\PCBuild : ;

And changing the command line to:

bjam --user-config=user-config.jam --with-python

simply rebuild all the targets and gave me what I was looking for!

Now, with Python and Boost.Python built… I was ready to write a test project to make sure everything worked as I expected.

Starting with the simplest program I could have, I went with:

int main(int argc, _TCHAR* argv[])
{
	Py_Initialize();

	Py_Finalize();
	return 0;
}

Unfortunately, I didn’t get the results was expecting…

Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'

What is this ‘encodings’ you are talking about? Unless I skipped it while reading, I only realized while looking at my Sublime Text 2 install that Jon had a python26.zip file in the main folder of the application… after further inspection, this zip file contained all the core Python scripts. I therefore created a python33.zip containing the contents of my Python-3.3.0\Lib folder and it worked without a hitch!

I decided to follow SiCrane’s article on gamedev.net to have a simple example to follow. I simply added the two following lines to my very simple program:

char const* greet()
{
	return "hello, world";
}

BOOST_PYTHON_MODULE(hello_ext)
{
	using namespace boost::python;
	def("greet", greet);
}

And bam! Access violation when detaching the boost python dll…
To fix this, I simply add to define

BOOST_PYTHON_STATIC_LIB

for my project.

I’m continuing my experiments and will keep you posted with my progress.

Volume Control on the Keyboard

I used to use a Logitech G11 keyboard which had a useful Mute and Volume +/- buttons on it but I recently switched to a Das Keyboard which I love, but has no gimmicky buttons.

Since I like being able to control the volume without having to open the Volume Panel, I looked for a software solution.  I decided to opt of AutoHotKey and create a very small script that does the job nicely:

#WheelDown::Volume_Down
#WheelUp::Volume_Up
#MButton::Volume_Mute

I can now control the volume Up / Down by pressing the Windows key (#) and toggle the mute by clicking the middle button (MButton).

You can get the script here.

Keeping Console Open

Recently I had to launch “command line” applications quite often. I was very annoyed by the fact that the Window closes itself automatically if you simply double click on the .exe.

I was about to go the “hard way” by creating a Windows Explorer Shell Extension to add a “Launch and Keep Open” option when a friend suggested that I create a batch file and add a Shortcut to the “SendTo” folder in Windows. To quickly access this folder, simply use

%APPDATA%\Microsoft\Windows\SendTo

in the Address Bar of Explorer, it will bring you directly there.

Here is the listing of the batch file I created and called keepopen.bat

CLS
@ECHO OFF
%1
PAUSE

I then created a shortcut that I called Keep Open in the SendTo folder and here’s the result:

Keep Open Menu

and instead of having a Command Prompt window that closed automatically, I was greeted with:

Keep Open Result

Hope this helps!

Mac OSX, p4 command line and Sublime Text 2

Last week I received a message from one of my Perforce plugin user who had issues on Mac OSX. It seemed like p4 was not found on the system. After some reading and changes to the plugin, I’m glad to say it works now.

I am not a Mac user, never owned one, so my knowledge of OSX is very limited. The solution I’m exposing here might not be the right, if you have better ways to solve this please comment or contact me directly.

First, lets start by installing p4. Since p4 isn’t released as a dmg, I wasn’t sure where to install it. /Applications/Utilities seemed to be a good choice as Terminal was there too. After copying the file, you must make it executable:

sudo chmod +x /full_path_to/p4

You also want your PATH to include the directory where p4 resides. You can do this by modifying your .bash_profile. While adding the p4 path to your .bash_profile, you can also add the variables required to properly use p4 which are P4PORT, P4CLIENT and P4USER (change the values based on your setup):

export P4_HOME=/Applications/Utilities
PATH=${P4_HOME}:${PATH}
export P4PORT=perforce-server:1666
export P4CLIENT=myclientspec
export P4USER=myuser

We’re almost done!

The last part required changes in the code calling p4. For some reason, the environment variables from bash_profile were not propagated when calling the subprocess from Python, adding a call to

source ~/.bash_profile &&

whenever calling p4 fixed the issue, thanks to Phillip Koebbe!

Sublime Text 2 Stack Overflow Plugin

Since I was finding myself doing quite a lot of searches on Stack Overflow recently, I decided to write a real simple plugin for Sublime Text 2 that would allow me to do queries using the current word/selection or user input. It is available on GitHub and will be shortly available through Package Control.

The available commands are stackoverflow_search_selection and stackoverflow_search_from_input which are self-explanatory.

You can trigger them from the Command Palette:

Or through the Tools menu

This is definitely not the most complex plugin ever, but it does save me some time!

Hope this helps someone.

Sublime Text 2 + Perforce

After shopping around for a new text editor, I decided to stick with Sublime Text 2. While the editor is still in Beta, it is very fast and stable. See this video review at HeyBigName.com for a more detailed review.

Even for home projects, I tend to use Perforce (the licence is free if you have 2 users max). While Sublime Text 2 didn’t support a perforce integration, it was pretty easy to add a small python plugin to allow

  • User command to be bound on a menu item or keyboard shortcut
  • Call to p4 edit when a file is read only and about to be saved

I think the longest part was understanding that to call my PerforceCheckoutCommand I had to write perforce_checkout (no caps, _ added and command removed) in the config file.

For those of you who would be interested in using it, it’s available on GitHub

https://github.com/ericmartel/Sublime-Text-2-Perforce-Plugin

Edit: The plugin now supports auto checkout, auto add, checkout command and add command. I’m waiting for Sublime Text 2 to support delete and rename callback to add those. The plugin was also submitted to be part of Package Control (another useful plugin for Sublime Text 2) to ease its integration.

Edit: It is now part of Package Control, just use Package Control: Install Package and type Perforce and you’re all set!

Working NumberPicker and Android

For the last few weeks, I’ve been working on and off on a small android project. For number selection, I wanted to use something similar to what’s in the Alarm Clock that ships with most Android phones… a simple control made out of 3 elements, a text field, an “increase” button and a “decrease” button. I was really surprised to see that this is not part of the SDK. After checking on the net, I found this site:

http://www.quietlycoding.com/?p=5

It seemed to work well most of the time, but I had a strange behavior that I thought was coming from my side… After displaying the NumberPicker in a Dialog, I was using an OnClick on some button in this dialog, and sometimes the number I was getting from the picker didn’t correspond to what was on screen. Also, after seeing the application running on my phone, I decided to show it to my fiancée, and her first try at it broke the NumberPicker! If you hold one of the buttons, the picker will loop infinitely increasing or decreasing the value.

There might be other issues but here’s my fix to the two of them:

First, the infinitely increasing value problem, it appears that the code that’s constantly run does not have exit conditions, here’s how I fixed it:

private final Runnable mRunnable = new Runnable() {
    public void run() {
    boolean repost = false;
    if (mIncrement) {
        changeCurrent(mCurrent + 1);
        if(mIncrementButton.isPressed())
        {
            repost = true;
        }
    } else if (mDecrement) {
        changeCurrent(mCurrent - 1);
        if(mDecrementButton.isPressed())
        {
            repost = true;
        }
    }
    if(repost)
    {
        mHandler.postDelayed(this, mSpeed);
    }
}
};

I simply check if the button is still pressed before reposting the “increase” callback.

As for the value, if the text edit was currently being edited and the value was fetched before it lost focus, it was still returning the old value… the fix is quite simple:

public int getCurrent() {
    validateInput(mText);
    return mCurrent;
}

Here’s the modified NumberPicker.java to be used with QuietlyCoding’s package, feel free to comment if you have any questions!

Thanks