Tuesday, July 03, 2012

Media center setup - XBMC-XVBA

I finally got my nettop - AMD E-350 based barebones system. Installed 4G of RAM and the plan was to set it up with XBMCBuntu or XBMC-XvBA. Instead of installing the XBMC-XvBA version directly, I figured that I could start with XBMCBuntu, see how it does and then if necessary move to the XvBA enabled builds.

I don't have a hard drive for the nettop - the plan was to have the system run off a 8Gig pen drive.

Basic Installation - XBMCBuntu

What you need

  1. The nettop with RAM installed.
  2. 2 USB pendrives - One for installation (2GB) and another which is going to act as your HDD (8G)

Steps

  1. Download UNetBootin for windows and the XBMCBuntu iso image
  2. Create a Live USB using UNetBootin: Once you have UNetBootin installed, stick in a flash drive in the usb, start UNetBootin and selec the XBMCBuntu iso image as the source distribution iso and the flash drive as the destination.
  3. Boot the nettop using the USB drive: You might have to play around with boot devices and priorities in the BIOS settings to get it to boot from the USB drive. To keep things simple, stick the pendrive into one of the USB2 ports (avoid the USB3)
  4. ON the UNetBootin boot menu, you can just try out XBMCBuntu live image. I did so and things seemed to work well enough for me to do the full install to another USB drive plugged into the system. Note that if you're not able to find the target drive, then just reboot with both the USB drives plugged in - sometimes, newly inserted devices aren't detected.
  5. Install, go through the menus and wait for it to complete.
  6. As you go through the menus, keep in mind to choose a custom partitioning scheme. In my case, I had 4G of RAM and there's no sense in having a swap drive on the pen drive. If you plan on having hibernation support, then use a 2G swap partition (50% of RAM) - else you can skip the swap altogether.
  7. Once done, pull out the installation pen drive and reboot. You should be able to reboot off the USB pendrive that you installed into. The installation pendrive is pretty much done - you won't need it any longer.

XBMCBuntu

At this point, I had XBMCBuntu up and running however, there were a few problems:

  1. On idle, CPU utilization was very high (~ 60 - 70%) and the unit was running hot.
  2. Display resolution proved troublesome - my LCD's native resolution is 1366x768 but that wasn't available over HDMI.
  3. I was able to get 1360x768 on DVI/D-Sub - but that meant using a separate cable for audio out.

Of these, the high CPU utilization was the biggest worry - so there's a few steps available to try

  1. Within XBMC - set sync to display refresh - always.
  2. Turn off RSS feeds
  3. Tweaks .xbmc/userdata/advancedsettings.xml:
<advancedsettings>
    <useddsfanart>true</useddsfanart>
    <cputempcommand>cputemp</cputempcommand>
    <samba>
        <clienttimeout>30</clienttimeout>
    </samba>
    <network>
        <disableipv6>true</disableipv6>
    </network>
    <loglevel hide="false">1</loglevel>
    <gui>
        <algorithmdirtyregions>1</algorithmdirtyregions>
        <visualizedirtyregions>false</visualizedirtyregions>
        <nofliptimeout>0</nofliptimeout>
    </gui>
    <measurerefreshrate>true</measurerefreshrate>
    <videoextensions>
        <add>.dat|.DAT</add>
    </videoextensions>
    <tvshowmatching append="yes">
        <!-- matches title 01/04 episode title and similar.-->
        <regexp>[s]?([0-9]+)[/._ ][e]?([0-9]+)</regexp>
    </tvshowmatching>
    <gputempcommand>/usr/bin/aticonfig --od-gettemperature | grep Temperature | cut -f 2 -d "-" | cut -f 1 -d "." | sed -e "s, ,," | sed 's/$/ C/'</gputempcommand>
</advancedsettings>

Did those and while they dropped the CPU utilization to about 25% which was quite good. However, during videos, the CPU was still high - and that's because even though XBMCBuntu official uses hardware acceleration through VAAPI, it still is spotty.

Getting XvBA

I went over to the XBMC-XvBA installation thread and followed the directions in the first post to add the XBMC-XvBA ppas. The download took some time and XvBA build got installed. Started XBMC and things were much, much better.

sudo apt-add-repository ppa:wsnipex/xbmc-xvba
sudo apt-get update
sudo apt-get install xbmc xbmc-bin    

There are other tweaks that are listed on the XBMC-XvBA installation thread which I also went ahead and applied.

Other tweaks

Optimizing Linux for a flash/pen drive installation

Installing on a pen drive /usb flash drive has its pain points. My boot time was around painfully slow (~3.5 minutes). Opening Chromium took forever and even page loads were slow (it would be stuck with the status bar on 'checking cache'...). Also, the incessant writing to disk is probably killing off my pen drive much much faster. I ended up doing the following:

  1. Use the noatime and nodiratime flags for the USB drive

    # /etc/fstab
    UUID=39f52ccf-363b-4b6e-abdd-927809618d83 /               ext4    noatime,nodiratime,errors=remount-ro 0       1
  2. Use tmpfs - In memory, reduces writes to disk and is faster. With 4G of RAM, this is a no-brainer.

    # /etc/fstab
    tmpfs /tmp tmpfs defaults,noatime,nodiratime,mode=1777 0 0
  3. Browsers - use profile-sync-daemon for Ubuntu from Arch Linux - will automatically move your browser profile directory from your home folder to /tmpfs
  4. Move .xbmc to NAS/External drive along with your media. Makes a lot more sense to keep your .xbmc folder with your media on a external hdd.
  5. Change to noop or deadline scheduler:

    # Assuming sda is your USB drive
    sudo echo noop > /sys/block/sda/queue/scheduler
  6. Change system swappiness. We don't want the OS to use swap drive at all.

    # /etc/sysctl.conf
    vm.swappiness=1

Getting suspend/hibernate to work

I had greatest trouble here - but was able to get pm-utils working eventually. pm-utils is a framework of shell scripts around suspend/hibernation/wakeup that provides hooks to execute scripts before standby/hibernation and when the computer resumes from sleep/shutdown. First test if basic suspend/hibernate works

# check suspend methods supported
cat /sys/power/state
# S3
sudo sh -c "echo mem > /sys/power/state"

If your system goes into standby, then things are good. But its just a good start. In my case, system would go into standby only the first time after boot. After that, it would go into standby but then resume immediately. Its been asked enough times on Google and I've probably tried all the fixes. The first one is to update a kernel param acpi_enforce_resources=lax

# /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_enforce_resources=lax"

After that, make sure to run  sudo update-grub In my case, the magic incantation above failed (your mileage might vary). Nothing bad happened so I kept it on. Anyway, so I rebooted, then suspended and resumed the first time (which works) and took a dump of dmesg > dmesg.1.log. After that again tried to suspend and when it came back immediately, I could get a dmesg output and scan the entries after the first run. Turned out that the log had entries related to xhci_hcd - so decided to unload it first and then try to suspend:

sudo modprobe -r xhci_hcd
sudo sh -c "echo mem > /sys/power/state"

After this, the system was able to standby each and every time. Now it was time to get pm-utils working. Out of the box, pm-utils came with a config that had a bunch of things that I didn't understand (and I doubt they applied to this machine). If standby was working directly, then it should have worked through pm-utils. However, it needed some amount of pushing around before that comes around to a functional state.

Getting pm-utils to play nice

So now that I had confirmed suspend working, it was time to see why pm-utils was being so bad. First off, time to clean up the default configuration. So copied /usr/lib/pm-utils/config to /etc/pm/config.d/config and then start editing it

SLEEP_MODULE="kernel"
# These variables will be handled specially when we load files in
# /etc/pm/config.d.
# Multiple declarations of these environment variables will result in
# their contents being concatenated instead of being overwritten.
# If you need to unload any modules to suspend/resume, add them here.
SUSPEND_MODULES="xhci_hcd"
# If you want to keep hooks from running, add their names  here.
HOOK_BLACKLIST="99_fglrx 99lirc-resume novatel_3g_suspend"

Waking up with the keyboard

if you'd like wake up with a usb device (usb keybd), then you need to find out the usb port where your device is connected. The easiest way might be to check dmesg output which would usually print this out. In my case, my wireless keyboard/trackball are connected on USB3

echo USB3 >  /sys/proc/acpi
echo  enabled > /sys/proc/devices/usb3/power/wakeup

After that, the HTPC could be woken up with a keypress. Now I haven't been able to find a way to do the same thing with only the keyboard (so that the system doesn't wake up anytime anyone picks up the keyboard - so for now, have turned this off). The above change won't persist over a reboot - so to make it persistent, put the two lines above to /etc/rc.local before the exit 0

Fixing up fglrx annoyances (ATI binary driver)

Not much point of a HTPC if the video isn't top quality. And there are a lot of variables involved there - your computer hardware, software, drivers, type of connection (HDMI/DVI) and the telly itself. Also, video driver support on Linux for ATI leaves quite a bit to be desired. One of the reasons of going with XBMCBuntu was knowing that there'll be large community support available on ubuntuforums.

Right off the bat, things started at the mildly irritating level. Catalyst control center in root mode won't start even though there's a big fat menu item there. Quick google and it says that the easiest way out is to use gksu amdcccle in the run dialog (ALT-F2).

So where does all this get us

After all this, it makes a sea change in the overall experience:

  1. XBMC idles at 15 - 20% cpu utilization. During video playback, stil stays at a comfy 40% - 50% while playing 720p/1080p videos
  2. Browsers (Chrome and FF) open near instantly; browsing experience is better than my desktop and page loads, tab switches etc feel much nimbler than on my desktop (AMD 6 core, 12G monster running Win 7x64)
  3. Total cost - USD 180

More to come

  1. Hibernation support
  2. Torrenting
  3. Scheduled wake up from shutdown/hibernate/suspend state

Saturday, June 30, 2012

Avast! trial expiration kills Internet connection - how bad is that!

So I use 'free for personal use' Avast Antivirus at home for the past couple of years. It's been mostly good though I've had some reservations about it - namely, nag pop-ups and so on. Some months ago (or maybe was it a year ago?) there was a program update and it wanted me to install 'Avira Internet Security'. Now I had no need for this (I use COMODO firewall which has been quite good) however, there was no way around it. Avira's update process said I could revert back to the free Antivirus version anytime without a re-install or a re-anything!
Not much of an option and you can't blame them for trying to push their products and convert free users to paying ones - so I went ahead with the upgrade. About a fortnight ago, I started getting warnings about 'your trial licenses is about to expire' and so on. The good thing about the internet security product was that it was discreet - in fact, safe to say that I even forgot that I installed it.
Remembering the notices about the trial expiring and reverting back to the free version, I chose to ignore all the warnings till yesterday afternoon when the wife called me up at work about 'internet not working from the home machine'. Now my wifi dongle on the home pc does once in a while show up with a 'Limited connection' that's quickly fixed with either disabling and enabling the dongle or unplugging it and putting it back in the USB port. I offered that up as a solution and a few hours later am told that it hasn't fixed the issue.This morning I finally sat down to see what was up. Turns out that the WIFI just wouldnt connect. So up comes device manager and under Network Devices I see a whole lot of 'avast! NDIS filter' virtual devices showing up. Opened Avast! gui and there are no panels for turning the thing off... Its reverted back to the free version - but has killed my net connection in the process! Not a happy camper at this point - still wasn't worried since I figured there've got to be tons of users with the same problem and it probably has a simple fix. Google did not reveal any simple fixes - Avast's community forum had help! Avast Internet Security trial expired, no internet connection and Avast Internet Security Trial seems to have affected my internet connection. The suggestions offered - buy a license, uninstall and re-install Avast etc were just not Ok. I definitely wasn't the only one affected but looks like a small but sizable user population was affected. If that was so, then Avast! should have done something about it - however, looks like they don't believe much in that. Agreed it's a free product and will not merit levels of support that you'd get for something that you pay for. But:

  1. I did not ask for the installation of the 'Premium' product trial.
  2. There was no option to opt out of the 'trial'
  3. They actively messaged that there's 'nothing to lose' from using the trial.
Given all that, they should have stepped up and either taken care of the issue with an update OR put up steps on how to solve it. It doesn't take that much. Here's how I got back my net connection:
  1. Device manager - Remove all 'Avast!' virtual devices with a right click 'Uninstall'
  2. Restart
  3. No WIFI still... so open 'Network and sharing center-> Change Adapter settings-> Wifi Connection -> properties'. In the 'This connection uses the following items:' list there was one more avast! filter device. Selected and uninstalled that too and restarted again.
  4. Back in business...WIFI is back up and running!
It's time to say goodbye to Avast!. Any recommendations for good, free antivirus solutions?

Wednesday, April 04, 2012

Media center upgrades - part two

So this is a continuation to my last post on my effort to upgrade the media center at home. While I wait for hardware to come, I've been reading up through forums and blogs online and am finding it real hard to get some good advice. So, thought it might help to list down concisely the situation as it stands currently, in the hope that it will server other folks who're trying to find similar answers.

So what's the fuss all about?

Getting XBMC on Linux with AMD fusion APUs to work nicely and render hardware accelerated video. Also, while we're at it, also do it by booting off a pendrive (ie hdd less system)

Background

Graphics APIs

To get hardware accelerated video on ATI/AMD hardware on Linux, currently, there are two choices

  1. XvBA - this is AMD's graphic APIs (similar to VDPAU on nVidia). Not very well supported.
  2. VAAPI - this is intels APIs. XBMC Eden is said to work well with VAAPI.

Drivers

  1. Open source Linux drivers for ATI chips lag behind the closed source ATI proprietary drivers. For HD video, you're pretty much limited to using ATI's proprietary drivers. So, let's emphasize - from now on, driver means ATI Catalyst for Linux

The Contenders

OpenElec.tv

OpenElec is covered in the earlier post - but essentially you have a Fusion optimized micro builds that can run off an SD card/flash drive. From a video perspective, this should be identical to XBMCBuntu. The upside is that everything is pre-configured while the downside is that it's pretty limited.

XBMCBuntu

Also covered in my previous post - lightweight Ubuntu based distro/LiveCD. XBMC Eden implements VAAPI and Catalyst Fusion APUs drivers can be used asa backend with these and provide hardware accelerated video. There are some cases where this bridging doesn't/may not work well. On the other hand, since this is the officially supported method, its going to be around and improved upon, and likely to have more info available in public domain etc.

XBMC-XvBA PVR builds

So this is an unofficial build by the community. THe promise is that instead of going the VAAPI route, this has direct support for XvBA api so, offes better performance. The forum thread tracking this is available here. While the build is supposed to be quite usable, from the thread activity, it seems its also heavily under development.The goal is to merge this back to the mainline once it stabilizes.

I plan to go the path of least resistance - OpenElec, then XBMC-XvBA and finally settle on XBMCBuntu - but things might change once I actually get down to it.

Time for the big fat disclaimer - Nothing in this post is guaranteed to be correct. this is my read of stuff on the net and it could be wrong. You're welcome to correct it in the comments and I'd be more than happy to fix the post.

Monday, April 02, 2012

Compiling Vim again - Cygwin

Vim installed by Cygwin's setup project does not have Ruby/Python/Perl support enabled by default. As my list of must have vim plugins has a few which use Ruby and Python, thought that it might be good to build my own Cygwin build of Vim. Turned out a little more work than I thought - but that's more due to the misleading (at least for me :) ) Make file in the vim source tree called Make_cyg.mak.

Here's how to compile:
  1. Make sure you have python (and ruby, perl and whatever other interpreters you need vim built with) installed.
  2. Do not install vim through cygwin (or uninstall it if you have it)
  3. Download vim source tarball, untar it and go into the vim73/src folder.
  4. Configure

    ./configure --enable-pythoninterp --enable-perlinterp --enable-rubyinterp --enable-gui=no --without-x --enable-multibyte --prefix=/usr
    make && make install
  5. You're off to the races!

Saturday, March 31, 2012

Media center upgrades

I have a small form factor (SFF) machine on the way to take up duties as a media center machine. After waiting for long, finally pulled the trigger on a Foxconn Barebones Book sized system and 4G of RAM. I haven't ordered a hard drive - the plan is to run XBMC completely off a USB drive. As it is, media is on a 1TB external disk and the cost of 2.5" laptop HDDs has gone through the roof.

In terms of software, I've got to figure out which XBMC to use - the contenders are to either install XBMCBuntu or go with one of the specialized builds from OpenElec. I'm still new to both - so will need to do some reading up before I decide.

OpenElec

OpenElec has small footprint (100MB), customized builds for different chipsets. Its meant to be run from a flash drive - so it has a few optimizations to make sure that it doesn't clobber your flash drive. Also, the stable version of OpenElec based on XBMC 10.0 "Dharma" has native AMD Fusion chipset support. Its also designed to be self updating and from reading the manuals, boots right into XBMC and OpenElec settings are all accessed via a XBMC extension so you never have to drop down to the linux machine underneath it.

At this point, looks like OpenELec is really limiting. I would really love to run a browser, use the machine for torrenting etc - and somehow using the XBMC interface for all those doesn't sound too good.

Also, XBMC Eden is supposed to support AMD Fusion natively and OpenElec hasn't been updated yet for Eden (there are nightly builds available though that are based on Eden).

XBMCBuntu

XBMCBuntu is XBMC's official liveCD - you can use the live CD to install to another USB drive media and provided the system can boot from USB, you're off to the races.
The thing here is that it isnt specific to a 'flash' drive - so there's a small tradeoff in terms of the flash drive life. XBMCBuntu is based on Lubuntu 11.10.

Migrating the database

I also have to figure out how to migrate my XBMC database of movie information from Windows XP to the Linux setup - not sure if its even possible - but its something that's definitely worth a shot. In any case, if it doesnt work, then will just let XBMC rebuild its database overnight.

The hardware's supposed to come in april 2nd week - can't wait for it :)

Friday, March 23, 2012

Moved to bitbucket

I've been using Git Enterprise for hosting private repositories since github's free plan doesn't include any private repos. Git enterprise's worked - but the UI leads a lot to be desired the few times that you actually have to use the web interface.

So the other day while doing something else, I landed on bitbucket . Bitbucket is Atlassian's code hosting service - and for some reason I was under the impression that it only supported mercurial repositories. Was pleasantly surprised to see that not only can you have git repos, you also get unlimiited private and public repos with upto 5 collaborators all for the unbeatable price of free!

Can't ask for more - so it's Bye-bye Git Enterprise! and Hello! Bitbucket... Bitbucket also has a nice helpful repo import - plug in the url to your git repo and it gets cloned. Once that was done, it was a simple matter to update the origin url of my repo with


git remote set-url origin https://raghur@bitbucket.org/raghur/home.git

Thursday, March 22, 2012

Hey look! A flying pig!

:)

MS has added git support to Codeplex - who'd have thought that such a day would ever dawn.

Kudos to the good souls at MS who made this happen - One can only imagine the kind of conversations that would've taken place to get the necessary approvals for this :).

Still Git has great mindshare but native windows support is pretty bad. Hopefully this might even help making a good gui for git on windows. After creating an abomination like TFS, MS should realize the benefit of just going with openly available tools rather than create.

Maybe not - that's more like seeing a squadron of pigs flying!

Tuesday, March 13, 2012

Coffeescript looks promising

I've just ran across Coffeescript... can't believe what sort of a hole I've been living in.

It's a source to source compiler (ie when you 'compile' a coffeescript script, you get javascript source.)

So why would you want a source to source compiler for Javascript?
Well, as apps become more and more 'front-end' heavy with DHTML/Ajax bling bling, the javascript that holds all that together also becomes more and more complex. Yeah, sure you used Jquery (or 'insert your favourite js framework') - but that's not even scratching the surface. You're still writing tons of js code, and dealing with its idiosyncracies and tearing your hair apart.

Enter Coffeescript - clean syntax with elements of style borrowed from ruby and python, this is super clean and efficient. You write your code in coffeescript which is neat, clean and concise. What it generates is very idiomatic and clean javascript.

Let's try something - take a guess at what the following does:

    var Animal, Mammal, animal, farm, _i, _len,
      __hasProp = {}.hasOwnProperty,
      __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

    Animal = (function() {

      function Animal(name) {
        this.name = name;
      }

      Animal.prototype.speak = function() {
        return console.log("I am a " + this.name);
      };

      return Animal;

    })();

    Mammal = (function(_super) {

      __extends(Mammal, _super);

      function Mammal() {
        return Mammal.__super__.constructor.apply(this, arguments);
      }

      Mammal.prototype.speak = function() {
        Mammal.__super__.speak.apply(this, arguments);
        return console.log("and I'm a mammal");
      };

      return Mammal;

    })(Animal);

    farm = [new Animal("fish"), new Mammal("dog")];

    for (_i = 0, _len = farm.length; _i < _len; _i++) {
      animal = farm[_i];
      animal.speak();
    }
    
And now - see if you like this better:


    class Animal
        constructor: (@name)->
        speak: ->
            console.log "I am a #{@name}"
    
    class Mammal extends Animal
        speak:->
            super
            console.log ("and I'm a mammal")
    
    farm=[ (new Animal "fish"), (new Mammal "dog")]
    
    animal.speak() for animal in farm

The javascript version is the generated from the coffeescript version above . Head over to coffeescript.org page - they have an online interpreter where you can try out coffeescript code and it generates equivalent javascript source.


If you're wow'ed with that (I am) - and just in case you're saying good bye to javascript, here's the nub.. since its a source to source compiler, unless you understand what's going on under the covers, you'll hit a problem soonish when you have to debug something.

So, Javascript isn't optional - but if you have that bit covered, there's no reason to have to 'live' with the iffy side of javascript. Take a look something like coffeescript and have a little fun along the way.

Friday, February 17, 2012

VIM config updates

Ultisnips has been updated to 2.0. See the video here for the updates and new features. One piece of information - and one that I was eagerly waiting for is that 2.0 works perfectly with auto complete popup. This wasn't always the case - in fact, the bug on launchpad for the same had been marked as a 'wont-fix'. In any case, I was super thrilled to see that its been fixed.


Zencoding.vim also has been updated... if you're writing any sort of markup the old way, then just google zencoding - there's a couple of videos that will blow your socks off. For the truly impatient, you write a CSS like expression and its converted back to markup! How cool is that?

Friday, January 27, 2012

IOS-no previous simulator versions!

Ran into a situation today where we had a mobile web app that was reported to be misbehaving on iOS 3.2. The Mac at work has the latest XCode and IOS 5 simulator loaded on it. So we thought it would be quite routine to just start a simulator running IOS 3.2 - after all this having simulators of different versions of the OS is pretty routine. Android makes it trivial and before that, Blackberry has always had different simulator versions for different versions of their OS. Truth be told, RIM probably overdid it. They had too many versions, a developer website that would drive even the most persistent BB fanboys to stark raving madness and documentation that took great pains to suck! Hell, its a separate rant altogether :).


Anyway, after clicking around Xcode for a bit, imagine our surprise when we found that only a device debugging package for iOS 3.2 was available as an updated package for Xcode. That didnt seem right - so off to Google and there's a post on SE http://apple.stackexchange.com/questions/14128/how-do-i-install-the-3-0-iphone-simulator-on-xcode-4


Apparently, Apple doesn't want you to test on previous versions (or atleast - 2 major versions before. Testing on last major version IOS4 is ok though). Now isn't that absolutely ridiculous? Sure, Apple wants people to upgrade their phones to the latest OS versions and they've done a great job of ensuring that later versions of the OS work on older generation phones - but from a development tool standpoint, making tools to test your app unavailable is taking things too far. So tomorrow if my site/app doesnt work properly on a iOS 3 device, the user isnt going to blame Apple. Its the app developer who gets the bug report :(.


So once I'd made my peace with Apple's decisions and diktats on what simulators I was allowed to play with, I reflected on it a bit. I think the key is that that IOS's simulator is really just a simulator (ie software running on the host machine but mimicking a device). On the other hand, the Android emulator is actually a full qnx VM that's totally isolated from the host machine. In IOS's case, the simulator is sharing libraries and tools installed on the base OS - and as such, it would be quite hard to simulate older versions. In Android's case, since each emulator is really like running a VM, you can have all the different versions at your beck and call. On the flip side of things, the emulator approach really slows things down - everything from booting up the VM to actually running code inside it whereas IOS simulator positively zips around. I'm not sure if this is indeed the case - it's just my theory. Looking around on the net, I couldnt find a solid reference - so if you know of one, drop it in the comments.. I did find a few on SE/SO - but they were by no means conclusive http://stackoverflow.com/questions/4544588/difference-between-iphone-simulator-and-android-emulator

VIM macro super powers

So my affair with Vim continues - and I seem to have discovered VIM's macro super powers. The obvious next step is to shout from the rooftops and hence this blog post (and there's hardly anything original - apart from the fact that I've just had a 'aha' moment when it comes to macros and thought it might help other budding vimmers out there...


A little primer - Macros let you repeat a set of commands. The way to go about it is to press q<macro_letter> where <macro_letter> is between lowercase a-z. This starts recording a macro in Vim (and you see a recording message at the bottom). Now hit commands you want to repeat later and press q when done to finish recording. VIM records all the keystrokes you enter in the register you specified as the macro name. To now execute the macro, position the macro on the line and then hit @<macro_letter> and Vim will faithfully replay your commands.


Its a great time saver - especially for complex editing tasks where search/replace doesn't cut it. But, if you're feeling a dissappointed after coming this far (after all, I promised a aha moment), then hang on.


Today's discovery was that you can edit macros that you've recorded quite easily and save them back!!! THIS IS HUGE. Why so? Because when you record a macro, its quite normal to jump around quite a bit or get one or two keystrokes wrong. In fact, its for this reason that I could never use Emacs's macro facility and failed to just 'get it'. However, in VIM, you could just open a scratch pad editor and hit "<macro_letter>p - that's double quote-letter-p to paste the contents of register containing your macro. You see your macro keystrokes - so go ahead and edit them and then use "<register>y<movement> to save your edits back to the register. You can now execute the macro with a @<macro_letter> as if that's the way it was recorded in the first place.


Another obvious tip - you can execute the contents of any register as if it were a macro with a @. Not sure when that could be helpful - but knowing that its possible is good.

Tuesday, January 17, 2012

Yoohooo!! Successfully compiled Android from source

Finally!!!


So my last weekend project had been to compile Android ICS from source. Given that the size of the repo itself is in excess of 6Gigs, just getting it down itself took the better part of Friday night and Saturday night. When I got down to running make on it, it was Sunday afternoon.


Needless to say, things didn't work too well. I'm running this on a 32 bit Ubuntu 10.04 Virtualbox with a piddly 1GB RAM. When make failed the first time, realized that swap was a measly 300Mb. First steps first, went on to increase memory to 2GB (that's all I can spare) and increased swap to 2Gs.


Compilation next round started and that failed too - ran out of disk space - and this was Sunday night. Things kind of stayed there and finally this evening, resized the disk in virtualbox to 50Gigs. Again started the compilation and this time ran into linker errors when building webcore. One more round of troubleshooting involved deleting the previously built static library and then running make again. Surprisingly, this time make completed successfully - to the point where I wasn't sure if it had succeeded or just failed silently on something else.


The next step was to run the emulator to see if it really would boot up. Over at source.android.com, they oversimplify it when they say that you just run emulator from the android root folder. That didn't work for me - and this time it was because I hadn't sourced the envSetup.sh file... this thread http://groups.google.com/group/android-platform/browse_thread/thread/91ff18e034acf951 helped in tracking that one down.


So finally, after all that trouble, I have my very own ICS build running!!!!


For now, its onward ahoy to setting up Eclipse and starting with a fix I've been mulling about for sometime now..


Signing off from cloud nine
R

Monday, January 16, 2012

Ubuntu, Console VIM - weird characters in insert mode

Now that I feel quite comfy with VIM, over the weekend I needed to edit a config file in my Ubuntu 10.10 Virtualbox machine quickly. Instead of GVim, I just opened the file in console VIM. As I hit i to get into insert mode, a bunch of weird character boxes were inserted. That was not good at all :( - just when you think you're comfortable with something if it does something totally weird. In any case, I was in too much of a hurry to bother and went about editing my file with gVim. Also, backspace was wonky (same weird characters) - so I felt better. For some reason that I fail to understand, why must Linux make proper backspace and delete handling such a pain! In any case, it's something that I've dealt with enough times to know that there'll be something on Google.


Later on, tried to see what all the fuss was about. Googling around, I found :help :fixdel and that seemed simple enough. Alas, when I tried it out, it didn't fix the issue at all. Also, I seemed to be getting weird characters just pressing i to get into insert mode - and the VIM wiki page didn't have anything about that. Neither did Google turn up anything that seemed related.


So today early morning, on a whim, read up a little on VIm terminal handling. I have the following in my .vimrc
[sourcecode language="text"]
set t_Co=256
[/sourcecode]
Maybe it was the color escape code that was coming in - so checked out :echoe &term which returned xterm under gnome-console and builtin_gui under gvim. So I've put the following bit in my .vimrc and it seems to have fixed things nicely:
[sourcecode language="text"]
if &term == "xterm"
set term=xterm-256color
endif
[/sourcecode]

Wednesday, January 11, 2012

Android Annoyances

So yesterday and today while driving back from work, I've had to join conference calls. The conference call provider we use at work has 10 digit passcode numbers. Usually, I have a few bridge numbers with the DTMF codes saved in my contacts so I can just click on the contact to get dialled to the access number and have the participant passcode typed in for me. However, yesterday and today's calls were on a different bridge and I had to try to remember a 10 digit number after dialling the access code - and all that while driving. Needless to say, it took a few attempts and I'm sure at that time my attention wasn't where it should have been - ie on the road and on the traffic. Besides being thoroughly unsafe on Bangalore roads, its just frustrating(thankfully - better sense prevailed today and I pulled over, dialled into the bridge and then started driving again).


So the issue really is that the native parser that parses out email and calendar invites doesn't understand access codes and passcodes. It shouldn't be too hard to do - but then I started digging a bit deeper this evening. Granted that the parser isn't smart enough, at the very minimum if it handles tel: links properly, then its just a matter of educating folks who set up meetings to set them up so that you can click to call with something like <a href="tel:23423432233,,9230233#"> - in fact, in Outlook if you type TEL: and then the number, it will automatically be parsed as a tel: hyperlink. Turns out that its a massive fail - if I click the link, Android will show me the dialler but without the DTMF codes (basically, only the number upto the first comma). TOTAL FAIL.


So, Isn't this something that should have been brain dead simple to do? I mean - this is 2012 after all - and I'm not asking much. All I'm asking is that the tel: url parsing/handling be done in such a way that we can use our phones properly!!! Turns out that there's an open ticket 4575 since Nov 09. And its marked as an enhancement - I find that laughable since its a bug and definitely something that can be done quite easily (esp since a contact that has DTMF codes is dialled properly). However, for the 2 years that the ticket has languished, there have been 73 comments and not a single response from big GOOG :(


At the moment, doesnt look like this is going to be fixed - so I started browsing thru the Android source tree to see if I can find where the implementation for tel: urls - however, given the size of the android source, that's like trying to find a needle in a haystack. Guess I'll have better luck with seeing if CyanogenMod folks can fix this in CM9.


So about that, the other thing that has confounded me is why in the world can't Android bundle a decent T9 dialer/smart dialer out of the box. I know there are tons of apps on the market that do that - but seriously, is smart dialing something so out of the world that I need an app for it? As expected, there's a ticket but no action.


I think its safe to assume that Google isn't interested in fixing these issues as there's no 'benefit' in doing so - though for the life of me, I can't imagine either of them being particularly hard. In any case, I'm eagerly awaiting a CM9 build for the Nexus One (right now, am running an ICS build from XDA).

Tuesday, January 10, 2012

Facebook publicize is driving me nuts!

I'm thoroughly frustrated with Wordpress.com's facebook publicize feature. In theory, its supposed to post to your facebook wall whenever you publish a new post and that way publicize your post among your friend circle.....if it ever works. I've done all the resets, disconnects and reconnects and it just doesn't. Now, this could very well be a facebook problem rather than a wordpress.com problem - so while my rant might be misdirected, its a rant anyway against the thoroughly frustrating experience. Its like a bucket of cold water on my enthusiasm to be more active on my blog.


You see, with having posted rarely to this blog, I get a measly 70/80 page views per day (yeah - there's no need for the snide looks); So one part of actively persisting on the blog has been to see if I can get to 100+ page views per day. Modest goals, I admit - and getting the linky to a new post on the FB wall is a big part of it. If only it worked as it says on the tin :( :(


Anyway, this post is a test in itself - I've just jumped through the said hoops , mumbled the magic incantations and in other words, followed every bit of direction available to make this work right. And if this post shows up on my FB wall, well and good. If not, then I'm done with trying to get this to work.

Monday, January 09, 2012

A syntax highlighter extension for Deck.js

So for the past few hours, have been playing with Deck.js . I like the idea of a web based presentation format rather than a blob like powerpoint. At the same time, I'm a bit circumspect too - given the state of the tools. At least for my use, there's really no burning need that powerpoint can't solve (though I get the shivers everytime I have to do a presentation). All the web based/HTML5 seem raw at the moment on some much needed features (slide notes, slide prints, scaling issues etc).

Anyway, after a few minutes on Google and StackOverflow, decided to give Deck.js a spin. Deck.js is really nice and you should take a tour if you haven't done so. So finally, after giving the online presentation and the introduction a try, downloaded the latest to give it a more thorough spin. As usual, one of the first things was embedding code snippets and I thought it would be nice to integrate Alex Gorbatchev's SyntaxHighlighter into this. Turned out really simple to do (I'm sure there are other syntax highlighter extensions to deck.js out there) - but since I got something working pretty easily, here it is:

Create a file called deck.syntaxhighlighter.js with code below:

[sourcecode language="javascript"]
(function ($) {
$("head").append(
'<link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css" />'
).append(
'<link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" rel="stylesheet" type="text/css" />'
);
function setupSyntaxHighlighterAutoloads() {
console.log("calling SyntaxHighlighter");
SyntaxHighlighter.autoloader(
'applescript http://alexgorbatchev.com/pub/sh/current/scripts/shBrushAppleScript.js',
'actionscript3 as3 http://alexgorbatchev.com/pub/sh/current/scripts/shBrushAS3.js',
'bash shell http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js',
'coldfusion cf http://alexgorbatchev.com/pub/sh/current/scripts/shBrushColdFusion.js',
'cpp c http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js',
'c# c-sharp csharp http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js',
'css http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js',
'delphi pascal http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDelphi.js',
'diff patch pas http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDiff.js',
'erl erlang http://alexgorbatchev.com/pub/sh/current/scripts/shBrushErlang.js',
'groovy http://alexgorbatchev.com/pub/sh/current/scripts/shBrushGroovy.js',
'java http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js',
'jfx javafx http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJavaFX.js',
'js jscript javascript http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js',
'perl pl http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js',
'php http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js',
'text plain http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js',
'py python http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js',
'ruby rails ror rb http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js',
'sass scss http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSass.js',
'scala http://alexgorbatchev.com/pub/sh/current/scripts/shBrushScala.js',
'sql http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js',
'vb vbnet http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js',
'xml xhtml xslt html http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js'
);
SyntaxHighlighter.all();
}
$.getScript("http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js",
function () {
$.getScript("http://alexgorbatchev.com/pub/sh/current/scripts/shAutoloader.js",setupSyntaxHighlighterAutoloads);
});
})(jQuery);
[/sourcecode]

Throw that in your deck.js/extensions folder. IN the slide deck you want to use this extension, include a script line before the end of the body tag:

[sourcecode language="html"]
<script src="../extensions/deck.syntaxhighlighter.js"></script>
</body>
</html>
[/sourcecode]

And you're done. Now to include any code snippets in your deck, just use either of the methods specified in the SyntaxHighlighter page (snippet for the script tag below)

[sourcecode language="html"]
<script type="syntaxhighlighter" class="brush: js">
$(document).ready(function () {
//this is the function body
});
</script>
[/sourcecode]

That's all there is to it. Code above can do with some improvements (conditionally load local copies if the remote loading fails etc) - but this is just a quickie script - so feel free to modify this to your heart's content.

Friday, January 06, 2012

Vim - unmap Esc!!

So I had the bright idea (by no means original, though, as I later figured out) that it'd be great to avoid the Esc key on Vim as its so far away from the home row. The alternative to pressing Esc is Ctrl-[ which, even though I've mapped CapsLock to control, I still find hard. So then, after some more googling around I've settled down on mapping jk to Esc. Its been a few hours with this setup and while its been an absolute pain till now, I think its a great way to avoid the Esc key jump. I can already feel my finger muscle memory relearning and my hand jumps instinctively for the Esc key much less now.

Here's my setup in case you want to try this out. Bung the following into your .vimrc or _vimrc as the case may be:

inoremap  :echoe "use jk"
inoremap jk 
The first mapping makes VIM echo a reminder. Its not friendly since it introduces a pause. However, the idea is to make the Esc so painful that you will shy away from hitting it.

Upgraded to XBMC 11.0 Eden beta

So I upgraded the good ole' media center machine at home to XBMC 11.0 Beta
. XBMC has been one of those software finds that has been just marvellous - to the point where I can't imagine the telly at home without XBMC. I've pretty much stopped watching regular tv/cable and almost exclusively on XBMC.
Also, its been a great way to keep the aging laptop (circa 2006 - core2Duo 1.6 Ghz, 2 Gb RAM and a piddling ATI Radeon X1600) in active duty.
Here's a hat-tip to all the XBMC guys and gals. And if you're not running a media center at home, you should give it a spin - XBMC makes your idiot box smart!

Saturday, December 31, 2011

Unit testing Apache CXF RESTful services - code available

So, the original post on the topic written about two and a half years ago had code snippets, but there's been comments and PMs for the complete code. So last week, as I resurrected this blog, decided to get that code out on github. Unfortunately, that was easier said than done; it has been quite some time and frankly, I'd lost the code. I must've switched machines about 3 times in the interim and gone from SVN to github for personal projects. Some hunting around ensued and thankfully, I was able to find the actual code we wrote based on the sample I'd posted. So cleaned that up - and just extracted the unit testing example out of it and pushed it to github - get it here. I haven't updated any of the dependencies - so this is still running against spring 2.5 and cxf 2.2.3 (I think) and things might've changed quite a bit since then (I haven't used the JAXRS bits of CXF much after that)


Running tests:
[sourcecode language="bash"]
mvn test
[/sourcecode]
Running the server:
[sourcecode language="bash"]
mvn jetty:run
[/sourcecode]

Syntax highlighting support in Wordpress.com with markdown

Now that I've cozied up to Vim/VimRepress combo for posting to this blog, there are a few things where I'm finding issues with posting code. With straight wordpress.com, I used to be able to mark up code with the [sourcecode][/sourcecode] tag and syntax highlighting comes in. With markdown - indenting a block of code with 4 spaces renders it as a <pre><code></code></pre> tags, but I don't know if there's a way to let WP.com know what language it is or any way to use the [sourcecode][/sourcecode] plugin from markdown.


Some googling on the topic didn't result in any wp.com specific answers (some folks have posted on using other plugins et cetera with a self hosted Wordpress - but nothing for wordpress.com)


Any ideas/pointers? Guess I should also post the question on the Unix stackexchange


Update on 1/1/2012


Using the sourcecode language="xxx" tag works - but you cant have any empty lines in your source.