Filed under Software

Shush! Release

For months now I’ve been running Shush! at work, and given its usefulness I decided to share it with the world!

Shush! is a simple software that mutes your PC when you lock it and then unlocks it when you sign back in. This is very useful in workplaces where people work with headphones, as it can be quite annoying to hear your coworker’s music when they step away and leave their headphones on their desk blasting music.

Shush! is free and feedback is welcome! Enjoy!

Shush Icon

Shush!

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.

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!

There is no source code available for the current location

If you’ve happened to use a lib with debug information, chances are that you’ve tried to step into a function and was greeted with a pop up similar to (I’ve compiled real quick FreeImage, which is an awesome library available here, to have a lib with debug information, then moved the source elsewhere because the pdb contains the original path the source was built from):

If at this point, you press “Cancel”, you’ll be prompted with a pop up saying:

Sure, no problem.

The thing is that once this is done, anytime you’ll try to step into a function coming from the same cpp file you just canceled the look up, you’ll be prompted with the message without being able to select the file.

This is really easy to fix actually.  This setting is stored in the Solution, under the Debug Source Files panel:

Simply removing the file from the “Do not look for these source files” will re enable the file selection dialog.

Visual Studio Commands and Aliases

A while ago I received the visit of two programmers from a middleware company at work.  They were showing me how to properly use their software, so they had to integrate it in our solution.  The more senior one was typing while the junior was learning from him.  I saw him use something I’ve never seen before so I guess I learned something too!

He used “>” followed by “of” in the search tab, and as he typed, the drop down menu was populated by files matching his filter… hum!  I didn’t know Visual Studio had this built in, I thought you had to use Workspace Whiz or Visual Assist!

Here’s an example:

(screenshot taken using the BWAPI solution)

The prefix > tells Visual Studio to interpret the rest as a command.  The actual Command Window is accessible using Ctrl-Alt-A (default binding) for those who don’t want to use the mouse  to select the “Quick Find” text box.  You can either use an Alias (such as of for Open File) or the actual command (such as File.Open).

Microsoft lists some commands and aliases available here but using >Alias will list all the set aliases.

http://msdn.microsoft.com/en-us/library/c3a0kd3x.aspx

You can create aliases and remove aliases using the alias command:

http://msdn.microsoft.com/en-us/library/xasxzd71.aspx

Given that most people don’t use them at all, it is pretty standard across all PCs, so if you have to work on other people’s PCs, you should be able to use aliases instead of relying on an installed plug in!

Visual Studio Plugins

There’s a new programmer on my team and today I was reviewing his code.  He had this weird scrollbar in Visual Studio which displayed a preview of the code with an highlighted “window” of what was on the screen.

For those who’d be interested in checking it out:

RockScroll

Also, the only other plugin I use is Visual Assist X, you can get it here (not free though, but totally worth it!):

Visual Assist X