Wednesday, May 2, 2012

JSON pretty-printing

Today's magic invocation is for pretty-printing JSON strings. If I hit a REST service with my browser, I get back a wad of JSON, which is great, but a bit hard to read. In Chrome (at least), I can pop open the Javascript console and run this:
JSON.stringify(JSON.parse(document.body.children[0].textContent), null, 4)
The JSON is actually displayed by Chrome as text in a <pre> block, which is the only element on the page (child 0 of body). So I have to grab that text, parse it into JSON, and then pretty-print it using stringify (with a 4-space indent). Thanks to Stackoverflow for pointing me in the right direction.

Monday, April 16, 2012

vim config w/ pathogen

From article on Vim plugin management

What I actually did was install pathogen as per https://github.com/tpope/vim-pathogen (more or less)

mkdir -p ~/.vim/autoload ~/.vim/bundle; curl -so ~/.vim/autoload/pathogen.vim https://raw.github.com/tpope/vim-pathogen/HEAD/autoload/pathogen.vim
echo -e "\n\ncall pathogen#infect()\n\n" >> ~/.vimrc

Then manually install just the few plugins I really wanted.

cd .vim/bundle/
git clone git://github.com/pangloss/vim-javascript.git
git clone git://github.com/timcharper/textile.vim.git
git clone git://github.com/tpope/vim-markdown.git
git clone git://github.com/nono/vim-handlebars.git
git clone git://github.com/kchmck/vim-coffee-script.git
mkdir jQuery
curl -o jQuery/jquery.vim http://www.vim.org/scripts/download_script.php?src_id=15752

Saturday, February 11, 2012

Disable touchpad tap-to-click

I'm on Xubuntu now, and the settings manager doesn't have any way to disable tap-to-click on the touchpad. Found the solution on the Ubuntu forums:

/usr/bin/synclient MaxTapTime=0

The instructions also say how to get this to run on startup.

Tuesday, January 31, 2012

Javascript in Eclipse

The problem: In Eclipse on my Windows machine at work, I get an error attempting to open Javascript files, and have to open them as plain text.

After a bit of Googling around, I ended up using the JSEditor plugin. There doesn't seem to be an update site for it, so I downloaded it from

http://sourceforge.net/projects/jseditor/

To install it, cd into the eclipse directory (with the 'plugins' subdir), and unzip it. Then restart Eclipse.

Thursday, January 26, 2012

GalaxyNexus on Linux

Update: The much simpler solution is to change the USB settings on the GN to PTP, not MTP.

Apparently, newer Android devices don't just magically mount as USB drives on Linux (or at least, Ubuntu). Fortunately, someone else has figured it out already. They go through a couple extra steps for setting up a mount command alias, but in brief, you need to use the MTP (Media Transfer Protocol) tools.

sudo apt-get install mtp-tools mtpfs
mtp-detect | grep idVendor
mtp-detect | grep idProduct
# Create a udev rule (Galaxy Nexus is 04e8/685c):
# SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", ATTRS{idProduct}=="685c", MODE="0666", GROUP="plugdev"
sudo vi /etc/udev/rules.d/51-android.rules
sudo /etc/init.d/udev restart
sudo mkdir /media/GalaxyNexus
sudo mtpfs -o allow_other /media/GalaxyNexus/
# To unmount
sudo umount /media/GalaxyNexus

Saturday, January 7, 2012

Android dev install

Installing an app you've developed on an actual Android device is documented pretty well, but I tripped over a missing step (c) for Linux:

sudo /etc/init.d/udev restart

I.e. Once you've added your settings to /etc/udev/rules.d/51-android.rules, you need to restart the udev service. Obvious in retrospect, I suppose.