Filed under Progress

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!

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!

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