bash on Windows is real–not a VM

I have talked to a few folks recently, and they still don’t believe bash on Windows (RS1) is ‘real’ and think it some kind of a VM. No it is not. It is the ‘real’ user mode running on Windows. It is not Cygwin, and it is not a VM. It is essentially all of the user mode (I.e. Linux without the kernel).

The kernel in this case is a wrapper around the NT kernel that translates the Linux commands to Windows and then things run. As far as Linux is concerned, its the same code and doesn’t have any changes). Technically this is called Windows Subsystem for Linux (WSL).

On windows, this is installed in the user space; so each user get their own instance effectively which is isolated from the other users. Once you install it (and if you are still reading this, then you probably know how to install it), then this shows up under C:\Users\your-user-ID\AppData\Local\lxss. If you can’t find that folder, you can still type it and navigate to it. Below is  a screen shot on what this looks like:

image

It is a little interesting and been mucking around this. Here is you can see the installation of gcc:

image

And here is the output of the CPU details:

image

root@localhost:/proc# cat cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 78
model name      : Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
stepping        : 3
microcode       : 0xffffffff
cpu MHz         : 2808.000
cache size      : 256 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 2
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 6
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm pni pclmulqdq est tm2 ssse3 fma cx16 xtpr sse4_1 sse4_2 movbe popcnt aes xsave osxsave avx f16c rdrand hypervisor
bogomips        : 5616.00
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 78
model name      : Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
stepping        : 3
microcode       : 0xffffffff
cpu MHz         : 2808.000
cache size      : 256 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 2
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 6
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm pni pclmulqdq est tm2 ssse3 fma cx16 xtpr sse4_1 sse4_2 movbe popcnt aes xsave osxsave avx f16c rdrand hypervisor
bogomips        : 5616.00
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

processor       : 2
vendor_id       : GenuineIntel
cpu family      : 6
model           : 78
model name      : Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
stepping        : 3
microcode       : 0xffffffff
cpu MHz         : 2808.000
cache size      : 256 KB
physical id     : 0
siblings        : 4
core id         : 1
cpu cores       : 2
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 6
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm pni pclmulqdq est tm2 ssse3 fma cx16 xtpr sse4_1 sse4_2 movbe popcnt aes xsave osxsave avx f16c rdrand hypervisor
bogomips        : 5616.00
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

processor       : 3
vendor_id       : GenuineIntel
cpu family      : 6
model           : 78
model name      : Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
stepping        : 3
microcode       : 0xffffffff
cpu MHz         : 2808.000
cache size      : 256 KB
physical id     : 0
siblings        : 4
core id         : 1
cpu cores       : 2
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 6
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm pni pclmulqdq est tm2 ssse3 fma cx16 xtpr sse4_1 sse4_2 movbe popcnt aes xsave osxsave avx f16c rdrand hypervisor
bogomips        : 5616.00
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

root@localhost:/proc#

All, in all a very interesting world. A few things to note:

  • This is still in beta, so there will be issues.
  • It is user mode and not server mode. Live with it.
  • There would be path issues if you stray into the 256 character limit of Windows and then try and manipulate it in bash.

Happy hacking!

Download Build (2016) decks and videos

Update – Was a typo in the script, which I fixed. If someone had an issue, copy it again and give it a go.

I prefer to download and see the decks and videos ‘offline’ instead of streaming, as I can easily pause them and then pick off where I left – especially handy when I need to go to a meeting, or take care of some work, or just on a crappy network.

To that end, I downloaded all the sessions and the videos from Build (2016); I think one of the sessions might have gotten corrupted, but ignoring that I have about 140GB of data downloaded and 219 Sessions.

To do this, I used a Power Shell script that helped me download. The script (below) is simple enough – it loops through and for each session does the following:

  • Creates the relevant folder – this includes the Session code, Title, and the Presenters.
  • For each session, extracts the abstract / description of that session and saves it in a text file in that folder.
  • Downloads the presentation for that session.
  • Downloads a jpg which shows the image session – sometimes it is easier just to see the title slide. I thought better to have it and not use it, than the other way.
  • And finally downloads the high-quality video of that session. In the script, you can choose a lower quality video if you prefer that. And if you want only the decks, then you can comment out parts of the script where it doesn’t download the video.

Here is an example on what the output for one of the sessions (P517 – Debugging Events in Edge) looks like:

Build-2016-download-example

A few points to note:

  • In the script, the root folder it tries to create and use is “d:\build”; you might want to change this to something else you prefer or what works for you. I would recommend to not making the root too long as you would get into long file name issues.
  • The script first loops through and downloads everything else except the videos first. And then 2nd time goes and grabs the videos.
  • If there is an exception with the images, then it just ‘eats’ it and moves on. It is not a breaking condition to stop the script.
# First setup the folder where to download using the parameters outlined below.
# Second, loop through and get the decks first
# Third. loop through and get the videos last
# Note: IF you don't want to download the videos, and want only the pptx then comment the section later in the script

# parameters
[Environment]::CurrentDirectory=(Get-Location -PSProvider FileSystem).ProviderPath 
$rss = (new-object net.webclient)

#Filenames might get long, so keep this short!
$downloadlocation = "D:\build"

	if (-not (Test-Path $downloadlocation)) { 
		Write-Host "Folder $fpath dosen't exist. Creating it..."  
		New-Item $downloadlocation -type directory 
	}
set-location $downloadlocation

# Grab the RSS feed - Build 2016
$a = ($rss.downloadstring("http://s.ch9.ms/events/build/2016/rss/mp4high")) 
$b = ($rss.downloadstring("http://s.ch9.ms/events/build/2016/rss/slides")) 

# Video quality default is high; you can select regular (mp4) or lower quality (mp3)
#$a = ($rss.downloadstring("http://s.ch9.ms/events/build/2015/rss/mp4")) 
#$a = ($rss.downloadstring("http://s.ch9.ms/events/build/2015/rss/mp3")) 


# ********** download the decks **********
try { 
    $b.rss.channel.item | foreach {   
	    $code = $_.comments.split("/") | select -last 1	   
	
	    # Get the url for the pptx file
	    $urlpptx = New-Object System.Uri($_.enclosure.url)  
        $urljpg = New-Object System.Uri($_.thumbnail.url)

        # make the filename readable
        $filepptx = $code + "-" + $_.creator + " - " + $_.title.Replace(":", "-").Replace("?", "").Replace("/", "-").Replace("<", "").Replace("|", "").Replace('"',"").Replace("*","")
	    $filepptx = $filepptx.substring(0, [System.Math]::Min(120, $filepptx.Length))
	    $filepptx = $filepptx.trim()
        $filejpg = $filepptx

	    $filepptx = $filepptx + ".pptx" 
        $filejpg = $filejpg + "_960.jpg"

	    if ($code -ne "") {
		     $folder = $code + " - " + $_.title.Replace(":", "-").Replace("?", "").Replace("/", "-").Replace("<", "").Replace("|", "").Replace('"',"").Replace("*","")
		     $folder = $folder.substring(0, [System.Math]::Min(100, $folder.Length))
		     $folder = $folder.trim()
	    }
	    else {
		    $folder = "NoCodeSessions"
	    }
	
	    if (-not (Test-Path $folder)) { 
		    Write-Host "Folder $folder dosen't exist. Creating it..."  
		    New-Item $folder -type directory 
	    }
	
	
	    # Make sure the PowerPoint file doesn't already exist
	    if (!(test-path "$downloadlocation\$folder\$filepptx")) { 	
		    # Echo out the file that's being downloaded
		    $filepptx
		    $wc = (New-Object System.Net.WebClient)  

		    # Download the pptx file
		    $wc.DownloadFile($urlpptx, "$downloadlocation\$filepptx")

            # download the jpg but don't want to break if this doesn't exist; hence the nested try blocks
            try {
                $wc.DownloadFile($urljpg, "$downloadlocation\$filejpg")
            }
            catch {
                Write-Host "Jpeg $filejpg doesn't exist ... eating the exception and moving on ..."
            }
        
		    mv $filepptx $folder 
            mv $filejpg $folder 
	    } #endif
	} #end-loop foreach

    Write-host "*************** Downloading all the decks complete ***************"
}
catch
{
    Write-host "Oops, could not find any slides."
}

# ********** download the videos **********
$a.rss.channel.item | foreach {   
	$code = $_.comments.split("/") | select -last 1	   
	
	# Grab the URL for the MP4 file
	$url = New-Object System.Uri($_.enclosure.url)  
	
	# Create the local file name for the MP4 download
	$file = $code + "-" + $_.creator + "-" + $_.title.Replace(":", "-").Replace("?", "").Replace("/", "-").Replace("<", "").Replace("|", "").Replace('"',"").Replace("*","")
	$file = $file.substring(0, [System.Math]::Min(120, $file.Length))
	$file = $file.trim()
	$file = $file + ".mp4"  
	
	if ($code -ne "") {
		 $folder = $code + " - " + $_.title.Replace(":", "-").Replace("?", "").Replace("/", "-").Replace("<", "").Replace("|", "").Replace('"',"").Replace("*","")
		 $folder = $folder.substring(0, [System.Math]::Min(100, $folder.Length))
		 $folder = $folder.trim()
	}
	else {
		$folder = "NoCodeSessions"
	}
	
	if (-not (Test-Path $folder)) { 
		Write-Host "Folder $folder) dosen't exist. Creating it..."  
		New-Item $folder -type directory 
	}
	
	# Make sure the MP4 file doesn't already exist
	if (!(test-path "$folder\$file")) { 	
		# Echo out the  file that's being downloaded
		$file
		$wc = (New-Object System.Net.WebClient)  

		# Download the MP4 file
		$wc.DownloadFile($url, "$downloadlocation\$file")
		mv $file $folder
	}

    #Try and get the Sessions text description
	$OutFile = New-Item -type file "$($downloadlocation)\$($Folder)\$($Code.trim()).txt" -Force  
    $Category = "" ; $Content = ""
    $_.category | foreach {$Category += $_ + ","}
    $Content = $_.title.trim() + "`r`n" + $_.creator + "`r`n" + $_.summary.trim() + "`r`n" + "`r`n" + $Category.Substring(0,$Category.Length -1)
    add-content $OutFile $Content		
} #end-loop foreach

Write-host "*************** All Done! ***************"

Unity and Visual Studio

Have been playing, a little with the new Visual Studio “preview” version (the installation of which is super smooth and takes waaaaay less time!). And as part of that saw the Unity Debugger option. Was this always there or is that new? Or did the Unity Tools beta add it? Interesting times to start playing with this, primarily for AR/VR and #HoloLens.

image

Humans and threading

We,  humans, are multi-threaded by design and can do many things in parallel –  with two exceptions I think. The only two blocking function we have to deal with are sneezing and farting. During these times, all current activity must be suspended for the duration. And of course it can be pretty annoying (or depending on the function, embarrassing).

So next time you check in some code, think about it –  is this smelly and sneezy (yep, that’s a word, now) or have I done the right thing?

Open Live Writer

Just downloaded and installed and posting this via Open Live Writer. Remember the lovely (but dead) Windows Live Writer from Microsoft? Well this is a forked version of that which is open source, based on MIT license.

The editor is offline and is very similar to word and can support a number of blogging platforms – including the common ones as you would expect. You can muck around the code (zip) or check it out on GIT. It is still work in progress of course (e.g. Plugin’s are not implemented yet). Irrespective, hugely grateful to Scott (Hanselman) to get this going.

Is rand() harmful?

​I saw this awesome presentation on why rand() is considered harmful. When you need a random number, don’t call rand() and especially don’t say rand() % 100! This presentation will explain why that’s so terrible, and how C++11’s header can make your life so much easier.

If you need uniqueness and non-deterministic, especially on the context of security or crypto then you need to think about a few things. For example the frequency, non-uniform distribution, and not using a pseudo random number generator (such as Mersenne twister) and not a linear congruential generator.

C++ Comment

int MyFunction()
{
    // There once was a man named Dave
    int Result = 0;

    // Whose code just wouldn't behave
    MyObject *Ptr = new MyObject();

    // He left to go to a meetin'
    Result = Ptr->DoSomething();

    // And left his memory a leakin'
    return Result;
}

How not to handle exceptions!

Was trying to pay my Electricity bill online via a site called Bangalore One, which is the Governments, premier one-stop shop for Electronic Delivery of Citizen Services.

I could not pay because it seems like some backend services they need for credit card payment is down. How do I know this? Because the site is revealing too much detail! See the exception details pasted below.

This is a great example of what not to do! I have seen this often, and it is lazy developers and even lazier testers who approved this and get this into production. One would have thought that government managing the “Silicon Valley of India” would know better!

It is also interesting to see that they are on a very old version of .NET – running on v1.1.

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[Exception: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.]
   BangaloreOne.clsBESCOM.fnCheckTransCnt(String LocationRRNo, String StaffCode, Int32 intDeptCode) +381
   bOneWebPortal.BESCOMConfirm.Page_Load(Object sender, EventArgs e) +721
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +750

Version Information: Microsoft .NET Framework Version:1.1.4322.2300; ASP.NET Version:1.1.4322.2300

Writing a compiler using C#

I was cleaning out my old papers (finally!) and came across an old paper I had titled “Compiler Writing Tools using C#” which essentially shows how you can write a number of tools like lex and yacc but instead of C/C++ on Unix, you use C# and .NET.

This paper covers the tokenizer, grammar, DFA, NFA, etc. I think conflicts and precedence is one area it would need a little more work. But overall its a very interesting piece of work – especially for one to learn the ropes if a lot of this is new.

Of course, writing compilers with C, overall is not the most productive experience (it sure is fun though!); if you have never done it before Standard ML or Haskell would be a better place to start. If you want to stick to .NET and roll out your own language (or create extensions) then check out this paper on MSDN.

All of this brought back memories when I wrote my own C++ compilers mainly with those tools on Unix System V and also on Xenix. Most people did not know (or perhaps remember) that Microsoft had a Unix version called Xenix which was later bought over by SCO and eventually become part of SCO Unix. Back in the days I use to run a dual-boot machine with Xenix and DOS. 🙂

Metro Apps in C++ anyone?

In Visual Studio “11” when I try and create a new C++ Metro app using the built-in template, I get the following error: “Can’t find localized resources”.

I wonder if anyone else has managed to get around this? I am running the Consumer Preview Build of Win 8 (Build 8250).

image

image

AWS Extension for Visual Studio

I had forgotten that I had the AWS Extension for Visual Studio installed until recently I noticed AWS Explorer item in the View menu option. This add-in allows you to explore the various features that Amazon exposes right from within Visual Studio. The toolkit makes it easier for developers to debug and deploy a .NET solutions that uses AWS.

image

When you install this, you also get AWS SDK for .NET which provides one with all the building blocks that are required for consuming the IaaS services exposed by AWS including SimpleDB, S3 and EC2.

If you are or planning to use AWS, this add-in is a must have in my opinion.

Troubleshooting WCF Performance – Part 1

More related details on Dustin’s post – WCF scales up slowly with bursts of work.

PowerShell script to kill named processes

There are times when you need to kill a number of processes in one-go like today when Chrome crashed a few times hanging all the running instances – next time Google says, one tab cannot bring down all of them – send them my way :). For such times, a PowerShell script is all you need.

I wrote up a simple one which takes the process name as input and then kills all the processes which match that name.

#Script is not signed, so need this.
Set-ExecutionPolicy Unrestricted

#Need to set the param to a variable
$target = $args[0]

if($target) {
    $orphanProcs = get-process | where {$_.Name -eq $target}

    #Check if list is null; if not kill all the procs
    if ($soonToBeDeadProcs) {
        #display list
        $soonToBeDeadProcs

        #kill list
        $soonToBeDeadProcs | foreach { $_.Kill() }
    }
    else { Write-Host "Oops, no processes found older with the name: $target" }
}
else { 
    Write-Host "Oops, no arguments passed. You need to provide one argument (the Process Name)."
    Write-Host "Example 1: killproc chrome"
    Write-Host "Example 2: killproc 'some other process'"
}

Example Output (Killing Chrome in this case):

PS C:\Users\amit.bahree\Desktop> .\killproc.ps1 chrome

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
——-  ——    —–      —– —–   ——     — ———–
    139      30    34292      46708   164     3.87    376 chrome
    137      22    20932      33648   149     2.48   1260 chrome
    141      21    17896      31328   148     3.01   3572 chrome
   5434      37    56932      66528   266 1,134.36   4940 chrome
    139      22    20288      33084   150     4.12   5032 chrome
    145      21    16576      31368   149     0.58   5148 chrome
    147      19    14384      26992   150     1.42   5604 chrome
    142      23    32292      37416   156     8.42   6528 chrome
    136      17    12456      23964   142     0.30   6732 chrome
    144      26    27004      39136   156     0.98   6736 chrome
   1586      90   151224     209888   512   395.87   7184 chrome
    138      22    21388      33916   151     3.76   7504 chrome
    123      13     7756      15196   126     0.56   7512 chrome
    142      21    23112      35552   150     2.01   9860 chrome
    140      18    13032      25148   150     1.73  10432 chrome

Twitter Trends

I was excited to find that Twitter had a JSON (Javascript Object Notation) endpoint for the current trending topics and decided to write a simple consumer which can read this and then spit it out in a simple console. And JSON being so simple and more or less “universal” meant that there are multiple implementations for .NET. Of course if you got lots of bandwidth you can roll out your own parser.

I ended up using Json.NET, which in addition to being OpenSource is also one of the most robust utilities which makes working with JSON formatted data dead simple.

The code for the console app is quite straightforward. The static function ReadTrends() retrieves the JSON string from twitter which is then consumed and extracted. The only tricky part was using a constant key; the easiest way I could think of doing this was to replace the date-time stamp with a literal and then use that literal.

Of course this will fail if you the function ReadTrends() is called at (or just before midnight) on Dec 31st and the code returns to the main() function in the new year. I don’t think this is something I am going to put in production and am not going to be too worried about this behaviour.

At the time of writing this, the twitter trends (in JSON) are:

{“trends”:{“2011-03-04 17:18:01”:[{“name”:”#coisasderetiro”,”events”:null,”query”:”#coisasderetiro”,”promoted_content”:null},
{“name”:”#tigerblood”,”events”:null,”query”:”#tigerblood”,”promoted_content”:null},
{“name”:”#blackpeoplemovies”,”events”:null,”query”:”#blackpeoplemovies”,”promoted_content”:null},
{“name”:”Frying Nemo”,”events”:null,”query”:”Frying Nemo”,”promoted_content”:null},
{“name”:”Acoustic Aftermath”,”events”:null,”query”:”Acoustic Aftermath”,”promoted_content”:null},
{“name”:”Blade Runner”,”events”:null,”query”:”Blade Runner”,”promoted_content”:null},
{“name”:”Fun Race”,”events”:null,”query”:”Fun Race”,”promoted_content”:null},
{“name”:”Bandra”,”events”:null,”query”:”Bandra”,”promoted_content”:null},
{“name”:”Mike Huckabee”,”events”:null,”query”:”Mike Huckabee”,”promoted_content”:null},
{“name”:”Arctic Monkeys”,”events”:null,”query”:”Arctic Monkeys”,”promoted_content”:null}]},”as_of”:1299259081}

And here is the output in the console. I can see Charlie Sheen’s #tigerblood is still trending; and wonder what Artic Monkeys are upto – is there new album out or something?


#coisasderetiro
#tigerblood
#blackpeoplemovies
Frying Nemo
Acoustic Aftermath
Blade Runner
Fun Race
Bandra
Mike Huckabee
Arctic Monkeys
All done. Press any key to continue…

And finally here is the code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using System.Net;
using System.IO;

namespace TwitterTrends
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //get the trends
                string temp = ReadTrends();

                //as the key is a datetime stamp (which is constantly moving), need something constant to interrogate.
                //simplest way is to find out the year and then take 19 characters from that which is the datetime stamp
                //replace that with a literal (DESIGEEK.COM in my case) and then use the literal. I don't think I will
                //be trending on Twitter; but if you are worried then you can use something like a GUID.
                //
                // For example at the time of writing this the datetime stamp was: "2011-03-02 14:20:00"
                string theDate = temp.Substring(temp.IndexOf(DateTime.Now.Year.ToString()), 19);
                temp = temp.Replace(theDate, "DESIGEEK.COM");

                //parse the string for the literal
                JObject trends = JObject.Parse(temp);
                var twitterTrends = from t in trends["trends"]["DESIGEEK.COM"]
                                    select t.Value<string>("name");

                //iterate through
                foreach (var item in twitterTrends)
                {
                    Console.WriteLine(item);
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("Following error occured:\n" + ex.ToString());
            }
            Console.WriteLine("\nAll done. Press any key to continue...");
            Console.ReadKey();
        }

        private static string ReadTrends()
        {
            //talk to twitter
            WebRequest theRequest = HttpWebRequest.Create("http://search.twitter.com/trends/current.json");
            HttpWebResponse theResponse = (HttpWebResponse)theRequest.GetResponse();

            //extract the data
            Stream stream = theResponse.GetResponseStream();
            StreamReader reader = new StreamReader(stream);
            string temp = reader.ReadToEnd();

            //clean up
            reader.Close();
            stream.Close();
            theResponse.Close();

            return temp;
        }
    }
}

[qrcodetag/]

Opensource ZigBee stack?

I was planning on getting the Telegesis ETRX2USB and wanted to know if there are any open source (or shareware) open source ZigBee stacks that I can use with that?

I also wanted to know if there is any opensource (or not too expensive), network management or network analyser for a ZigBee network? Essentially I want to be able to programatically view network and node information on the ZigBee network (e.g. S/N ratio, signal strength, etc.) – something similar to Ember’s Insight Desktop which shows the details I am interested in. I could not find anything specific and would be interested in getting ideas.

C++ Message queuing options?

I am thinking of implementing a queue in one of the projects I am working on right now (sorry cannot go into more details until it gets published – hopefully in a few months). Anywyas, this is in C++ which needs to run on Ubuntu and my queueing experience (with C++ or otherwise) is only with MSMQ which is brilliant, but does not help me here as that run only on Windows. I also cannot use something like STL Queue as this will need to run across a number of machines and trying to sync between them would a royal pain. In other words, this needs to be distributed and async “loose” messaging. 🙂

I am already using MOOS, so one option is for me to continue to use that – however this is for another part of the application and it might be easier for me to use something else (still need to think it through a little more).

These are the requirements (these are must haves!). Also if it makes a difference I am using CDT for this project.

  • Needs to be able to run on Ubuntu 9.04 (and higher)
  • Needs to be Open Source (cannot be commercial)
  • Needs to be able to store messages “offline”
  • Needs to be able to run on TCP with minimal dependencies. It would be nice not to have a whole bunch of underlying dependencies.
  • Preferably be easy to use (as a consumer) – I don’t have much time to read through loads of documentation just to get my head around the underlying object model and how to use it.
  • C++ support (if it was not obvious until now)

I did a little research online and came across the following, and wanted to get some feedback:

  • ActiveMQ – seems like it has good C++ support via CMS (C++ Messaging Service).
  • Amazon SQS –  not sure how good the C++ support is. If there is no library per se that I can use, then writing things around REST APIs might be more painful. Also I suddenly have a dependency to be able to go to the public internet. Also it is not free (though there is a free 100K messages / month).
  • MQ4CPP – seems quite amateurish (kudos to the guy writing it though – seems like an interesting project to pick up when once has time).
  • RabbitMQ – I know some guys used this at work (though that was using it in .NET); nothing for C++, but there some C experimental code; overall does not inspire confidence (in the context of C++).
  • OpenAMQ – seems quite interesting and also has a C++ API based on its WireAPI.
  • Anything else??

At face value it seems like this is down to ActiveMQ and OpenAMQ. Just looking at the quick samples between the two ActiveMQ seems like more C++ friendly and easier to use compared to OpenAMQ. Of course this is just the first impression and I could be completely wrong – it is not like I have had a chance to play with this (yet anyways).

Does anyone have any experience and feedback on this matter? Feel free to comment on this post, or tweet me.

SQL Syntax Error (with MySQL)

Say you are writing a new stored procedure (for MySQL) and when you execute it, you get an error something like shown below – as you probably figured out all it means is that there is a syntax error with in the SQL. Often the error is misleading especially if it is a complicated query. One easy way to help narrow down the issue is to run it in a SQL Console which usually provides a better clue that can be your pointer to fixing the issue.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for 
the right syntax to use near 'END' at line 17 (errno: 1064). Click 'Ignore' if you'd like to have this 
error ignored until the end of the script.

If you run this script you will get the above error:

DELIMITER $$

DROP PROCEDURE IF EXISTS `someSchema`.`sp_someSP`$$
CREATE  DEFINER=`someUser`@`someServer` PROCEDURE `someSchema`.`sp_someSP` (
	in uavname varchar(20)
)
BEGIN
SELECT u.id, i.*, ll.*, g.*, c.*
FROM 	uav as u,
	imu as i,
        uav_ll as ll,
        gps as g,
        uav_controller as c
WHERE
	u.name = uavname and
        u.id = i.uav_id and
        u.id = ll.uav_id and
        u.id = g.uav_id and
        u.id = c.uav_id
END$$

DELIMITER ;

The main issue in my example above was that a delimiter (semi-colon in this case) was missing where the SQL statement finishes i.e. in the last WHERE condition. Here is a snippet of what the updated WHERE clause should look like.

WHERE
	u.name = uavname and
        u.id = i.uav_id and
        u.id = ll.uav_id and
        u.id = g.uav_id and
        u.id = c.uav_id ; -- semicolon added here
END$$