Sunday, January 5, 2014

2 Ways to Count Rows in HBase

There are 2 ways to count the number of rows in an HBase table:

Run the following from the linux command line:
$ hbase org.apache.hadoop.hbase.mapreduce.RowCounter MyTableName

Run the following from the hbase shell (which is accessible from the Hue shell):
> count 'MyTableName'


Tuesday, April 2, 2013

C# LINQ Group by key and get max value of group

This is a handy C# LINQ snippet to group by a key in a list of objects and return a new list with only max values based on another property:

SomeList.GroupBy(x => x.MyKey).Select(g => g.OrderByDescending(x => x.DateCreated).First());

This was a stackoverflow answer - thanks driis!

Wednesday, November 28, 2012

Decode a mongo BinData field into a Guid with C#

This C# snippet will decode a mongo BinData field into a Guid

got this from Mongo:
{
  "_id" : ObjectId("50b40a5db14ea8902cd5d5ed"),
   "MyGuid : new BinData(3, "MC/0P9nkEeGgjYQrK2V3pQ=="),

   ...
}

but want to know the value of MyGid?  Try this little snippet:

using System;
namespace MongoGuidDecoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = args[0];
            var bytes = Convert.FromBase64String(input.Trim());
            var guid = new Guid(bytes);
            Console.WriteLine(input);
            Console.WriteLine(guid);
        }
    }
}


Now run to get the Guid representation:
>MongoGuidDecoder MC/0P9nkEeGgjYQrK2V3pQ==
MC/0P9nkEeGgjYQrK2V3pQ==
3ff42f30-e4d9-e111-a08d-842b2b6577a5

Tuesday, September 18, 2012

My CentOS Gottchas

Lessons for CentOS 6.3 in Virtualbox

Configure Bridged Adapter to see the internet:


# vi /etc/sysconfig/network-scripts/ifcfg-eth0
edit to have NM_CONTROLLED="no" and ONBOOT="yes"
Ref:  http://serverfault.com/questions/349993/virtualbox-centos-no-eth0

Then run:
# service network restart


Friday, June 8, 2012

R is fantastic (esp with ggplot2)

I keep being amazed at the R language, especially when using the free RStudio IDE.  I've mainly focused on using various analytical packages (like randomForest), but wow ggplot2 is awesome in it's simplicity for doing visualisations.  The following isn't the best data for an example, but you get the idea:


scores = rbind(0.25199,0.26516,0.29329,0.30794,0.30630,0.33529,0.33910,0.34185,0.33703,0.34423,0.34877,0.32457,0.33826,0.33670,0.34237,0.33503,0.33186,0.33125,0.32908,0.34548,0.34357,0.34371,0.35440,0.35082,0.34633,0.35529)
var = rbind(7.62,5.32,9.60,11.38,13.31,14.38,13.60,15.60,12.18,11.98,10.88,25.00,13.59,13.67,14.17,25.27,26.73,25.90,22.97,38.98,21.21,23.86,21.48,23.07,24.38,22.46)


summary(scores)
summary(var)


library(ggplot2)
qplot(scores,var) + geom_smooth()


Monday, May 21, 2012

Using WinMerge as merge/diff tool in TFS


Original source: http://jonfuller.codingtomusic.com/2008/08/26/tfs-using-winmerge-as-your-mergediff-tool/
Thanks Jon!

In VS, go To: Tools/Options/SourceControl/Visual Studio Team Foundation Server/Configure User Tools

Click "Add..."
Extension:  .*
Operation: Compare
Command: C:\Program Files\WinMerge\WinMergeU.exe
Arguments: /e /wl /dl %6 /dr %7 %1 %2
Click "Add..."

Extension:  .*
Operation: Merge
Command: C:\Program Files\WinMerge\WinMergeU.exe
Arguments: /ub /dl %6 /dr %7 %1 %2 %4

The winmerge command line reference can be found here.

Thursday, May 17, 2012

Javascript console.log() and IE

Arg how I loath IE, why doesn't it support console.log(obj)?

To prevent IE from throwing an exception when it encounters console.log, add the following to a site-wide js file:

if (!window.console) console = { log: function () { } };


This makes cross browser testing much easier while in development.