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
Wednesday, November 28, 2012
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()
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.
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.
Wednesday, May 16, 2012
Configure Elmah on IIS7.x vs IIS6
Elmah in IIS 7.x:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" /> <!-- false if you also have httpModules in config -->
<modules runAllManagedModulesForAllRequests="true">
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
</modules>
<handlers>
<add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
</handlers>
</system.webServer>
Elmah in IIS 6, if you must:
<elmah>
<!-- See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for more information on remote access and securing ELMAH. -->
<security allowRemoteAccess="false" />
</elmah>
<system.web>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
</system.web>
Thanks Elmah - you're awesome!
<system.webServer>
<validation validateIntegratedModeConfiguration="false" /> <!-- false if you also have httpModules in config -->
<modules runAllManagedModulesForAllRequests="true">
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
</modules>
<handlers>
<add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
</handlers>
</system.webServer>
Elmah in IIS 6, if you must:
<elmah>
<!-- See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for more information on remote access and securing ELMAH. -->
<security allowRemoteAccess="false" />
</elmah>
<system.web>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
</system.web>
Thanks Elmah - you're awesome!
Sunday, April 29, 2012
Contained Javascript Library template
This Javascript template enables a library to be written in its own namespace and handle being included multiple times on a page.
It's based on Douglas Crockford's json2.js library.
var MyLibrary;
if (!MyLibrary) {
MyLibrary = {};
}
(function () {
//'use strict';
if (typeof MyLibrary.myFunction !== 'function') {
MyLibrary.myFunction = function (arg1, arg2) {
//...method body here...
return true;
};
}
}());
It's based on Douglas Crockford's json2.js library.
var MyLibrary;
if (!MyLibrary) {
MyLibrary = {};
}
(function () {
//'use strict';
if (typeof MyLibrary.myFunction !== 'function') {
MyLibrary.myFunction = function (arg1, arg2) {
//...method body here...
return true;
};
}
}());
Subscribe to:
Posts (Atom)
