This blog has moved! Look for new posts at http://albertarmea.com.


If you’re on Windows, use MSysGit Bash as your primary shell, and also have gVim installed from the official site, you probably want vim and gvim to use the Vim you installed rather than the one that comes with Git.

There are two non-invasive ways I can think of doing this:

  1. Add aliases to your .bashrc similar to:
    alias vim='/c/Program\ Files\ \(x86\)/Vim/vim74/vim.exe'
    alias view='/c/Program\ Files\ \(x86\)/Vim/vim74/vim.exe -R'
    alias vimdiff='/c/Program\ Files\ \(x86\)/Vim/vim74/vim.exe -d'
    alias gvim='/c/Program\ Files\ \(x86\)/Vim/vim74/gvim.exe'
    alias gvimdiff='/c/Program\ Files\ \(x86\)/Vim/vim74/gvim.exe -d'
    
  2. Create small wrapper scripts in ~/bin, which Git Bash includes in your $PATH by default. Create files named vim, gvim, etc. that look something like this:
    #!/bin/bash
    
    /c/Program\ Files\ \(x86\)/Vim/vim74/vim.exe "$@"
    

With the filename “$SOURCE.$EXT” stored as Bash variables, run this (messy) one-liner:

ffmpeg -i "$SOURCE.$EXT" 2>&1 | grep Chapter | sed -E "s/ *Chapter #([0-9]+\.[0-9]+): start ([0-9]+\.[0-9]+), end ([0-9]+\.[0-9]+)/-i \"$SOURCE.$EXT\" -vcodec copy -acodec copy -ss \2 -to \3 \"$SOURCE-\1.$EXT\"/" | xargs -n 11 ffmpeg

My specific use case was to quickly split long videos with QuickTime chapter markers exported by Final Cut Pro.

Thanks to h4cc and DaniWeb user 4evrmrepylrning for pointing me in the right direction on lossless video splitting and getting chapter markers, respectively.


cyberquend:

Thank you Google! Such entertainment. Now I can procrastinate again, ever since microcorruption ended q_q.

The best reminder to sanitize user input is to try exploiting unsanitized inputs yourself. Here, Google lets you do exactly that.


The original post describes the problem and a now-broken solution.

After I was introduced to the Xposed Framework, I decided to attempt the problem of remapping Bluetooth AT commands again, this time in a more widely compatible way. I still cannot present a working solution at this time, but I’ll document what I’ve found in the hope that it will be useful.

Take 2: Override Bluetooth library in Java

As stated on the xda thread, Xposed Framework “allows developers to replace any method in any class (may it be in the framework, systemui or a custom app)”. Within the Android sources, I found a method, com.android.phone.BluetoothHandsfree.initializeHandsfreeAtParser(), that appears to set up a Bluetooth AT command parser. I then attempted to override this method using the Xposed Framework on my phone, a Nexus 5 running stock rooted 4.4.2. This didn’t work. The Xposed logs reported that the class and method did not exist. A search through more recent Android sources shows that the class was removed in 4.2.

Take 3: Override Bluetooth library in C

Searching for “BLDN” in the 4.4.2 sources reveals one file of C code, bta_ag_cmd.c. The function bta_ag_at_hfp_hfp_cback(…) appears to handle the command actions by calling a callback. Xposed Framework cannot modify compiled C code, but Cydia Substrate can. This turned out to not be useful because I could not find where the callbacks are defined.

Take 4: Override redial signal globally in the dialer

My last idea was to globally override the redial command in the dialer (who uses the redial button, anyway? That’s what the call history is for). Unfortunately, the Nexus 5 dialer is closed-source. After decompiling the APK with apktool, I couldn’t find any mention of “AT+” or “BLDN” inside. There was one mention of the string “REDIALING” in the class com.android.services.telephony.common.Call but I’m not familiar enough with smali (Dalvik assembly) to figure out what’s going on here. Using Java Decompiler on the classes.dex found within the apk results in “// INTERNAL ERROR //” on the Call class, but produces readable code on most of the other classes.

I’m out of ideas - even directly patching and recompiling Android is out until I can find where the aforementioned callbacks are defined.


See this iTerm bug report.

tl;dr: I noticed that when running Vim in a terminal session within Ubuntu’s GNOME Terminal or SSH'ed through either PuTTY or Chrome’s Secure Shell, mouse clicks beyond column 223 instead wrap to the column modulus 223. It turns out this is an issue with the xterm specification that does not have a simple fix.


This post refers to revision 35b1e14009 of HandsfreeActions.

The Problem

I recently started driving a 2013 Honda CR-V. While it is overall a great car, one of its quirks is that its hands-free Bluetooth interface, HandsFreeLink, is cumbersome and hard to use. Additionally, none of the steering wheel buttons map to Google Now voice search by default or send a signal that can be easily customized by one of the many apps for this.

Instead, the only button that seems to immediately send a signal to the phone is the call button - pressing and holding the call button located on the steering wheel of the car causes the phone to redial the last number called. The car sends an AT+BLDN handsfree signal to the phone. I was not able to find a clean, officially supported way for an Android app to receive a signal or to set a listener for Bluetooth Handsfree protocol actions.

The “Solution”

Some Android versions will output a line similar to 05-31 19:02:38.614 V/Bluetooth AT recv(20133): AT+BLDN in the system log when this signal is received. I could not find a way to listen for new system logs, so I wrote my own, which was a bit of an adventure into Android Services and Java Threads. The basic idea of the LogcatReader class is to start a logcat process and a Thread that continuously reads its output. When a line matching certain criteria, such as time or log tags, is read it calls a Listener that was set by the LogcatReader’s creator. As of Jelly Bean, an app reading the system logs in this manner requires root.

Once the LogcatReader reports that it has just read a log line corresponding to an AT+BLDN signal, we must then cancel the impending redialed call. To do this, I registered a BroadcastReceiver that is called whenever an outgoing call is made. The BroadcastReceiver will cancel the call if AT+BLDN was received in the past five seconds. Then I start the Voice Search activity.

Closing Notes

  1. This was much more involved than it needed to be, and still has quite a bit to go.
  2. Google, please put this in the operating system, where it belongs (and can be implemented reliably and without all these hacks) - or at the very least provide an API to listen for and override the Bluetooth Handsfree profile.
  3. Honda, please make your interface usable by adding a dedicated steering wheel button for Google Now (or Siri, if you’re so inclined).

Google’s ADT Bundle is an easy way to get a complete Android development environment. However, I’ve noticed that having Eclipse open significantly reduces the battery life on my MacBook, even though it uses negligible amounts of CPU.

It turns out that opening the drag-and-drop GUI editor even once causes Eclipse to unnecessarily use the Nvidia graphics card for the remainder of that session, draining the battery. It is possible to prevent Eclipse (and all other applications) from switching graphics processors by disabling automatic graphics switching entirely:

  1. Quit Eclipse if it is open.
  2. Download, install, and open gfxCardStatus.
  3. Click the gfxCardStatus menu bar icon and choose “Integrated Only”.
  4. Open Eclipse.

In other news, I’m looking forward to the final release of Android Studio, which no longer uses Eclipse.


The default mpich that comes with MacPorts when you run sudo port install mpich is compiled with an ancient version of GCC that does not support C++ 11. This results in this cryptic error:

$ mpic++ -std=c++0x mnist.cpp -o mnist
cc1plus: error: unrecognized command line option "-std=c++0x"

Simply installing GCC 4.7 with sudo port install mp-gcc47 does not fix this issue because mpicc and mpic++ compile your code using the version of GCC that was used to compile it instead of the active version of GCC.

This can be fixed by running sudo port install mpich +gcc47 which will compile and install MPI with a usable version of GCC.


I recently had to use dlib for a class assignment. While there is a package for dlib on most Linux distributions, there is no MacPorts package for dlib. So the only way I could think of globally installing it was copying the headers:

  1. Download dlib from their site.
  2. Extract the archive.
  3. Copy [archive root]/dlib to /usr/include.

The Makefile for whatever you were trying to compile should be happy now.