Skip to content

Instantly share code, notes, and snippets.

View howarddierking's full-sized avatar

Howard Dierking howarddierking

View GitHub Profile
@howarddierking
howarddierking / gist:11158160
Created April 21, 2014 22:04
bad mongodb connection management
var dbClient;
var ensureDbClient = function(callback){
if(dbClient){
console.info('ensureDbClient: returning existing client');
return callback(null, dbClient);
} else {
console.info('ensureDbClient: returning NEW client');
MongoClient.connect(mongoConnectionString, mongoConnectionOptions, function(err, db){
if(err){
return callback(err, null);
var mapByOrgID = function(){
var orgID = this.OrgID;
if(orgID)
emit(orgID, { ecosystem: this.ecosystem });
};
var reduceEcosystems = function(key, values){
var ret = {
orgID: key,
ecosystems: []
// FROM THE SHELL
{
"result" : "organizations_reduced_ecosystems",
"timeMillis" : 20827,
"counts" : {
"input" : 198751,
"emit" : 198740,
"reduce" : 26380,
"output" : 162220
@howarddierking
howarddierking / bunyan.js
Last active August 29, 2015 14:08
testing bunyan
var bunyan = require('bunyan').createLogger({
name: "foo",
streams: [
{
stream: process.stdout,
level: "trace"
}
]
});
@howarddierking
howarddierking / EtagMessageHandler.cs
Created July 1, 2011 23:52
sample message handler for managing etags in web api
public class EtagMessageHandler : DelegatingChannel
{
readonly IETagStore _eTagStore;
public EtagMessageHandler(HttpMessageChannel innerChannel) : base(innerChannel) {
Trace.WriteLine("EtagMessageHandler - Ctor");
_eTagStore = new InMemoryETagStore();
}
Get-ChildItem $wcfsource -Exclude "*.StyleCop" -Recurse | %{Copy-Item $_.FullName -Destination ($hgroot + $_.FullName.Substring($wcfsource.Length)) -Force}
@howarddierking
howarddierking / gist:1209919
Created September 11, 2011 18:16
powershell script for transforming a codebase
Import-Module Pscx
# the variables you'll likely need to change on your local machine
$afroot = "D:\AppFabric"
$hgroot = 'D:\Programming Projects'
# $hgremote = "https://hg01.codeplex.com/wcf"
$hgremote = "D:\Programming Projects\wcf-codeplex-baseline_RC2"
# derived paths
$afwcfsource = $afroot + "\private\source\WCF"
@howarddierking
howarddierking / gist:1209930
Created September 11, 2011 18:22
Project file transformation
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl b"
xmlns:b="http://schemas.microsoft.com/developer/msbuild/2003">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:template match="/b:Project">
<xsl:copy>
@howarddierking
howarddierking / customMTF_skeleton.cs
Created September 14, 2011 18:56
custom media type formatter - skeleton
class MyCustomMediaTypeFormatter : MediaTypeFormatter
{
public MyCustomMediaTypeFormatter() {
SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/vnd.howard.fancyformat"));
}
protected override object OnReadFromStream(Type type, Stream stream, HttpContentHeaders contentHeaders) {
//stuff
}
@howarddierking
howarddierking / OAuthFacebookOperationHandler.cs
Created October 12, 2011 00:41
Web API Operation Handler for initiating a server-driven OAuth2 workflow with Facebook
public class OAuthFacebookOpHandler : HttpOperationHandler<HttpRequestMessage, HttpRequestMessage> {
readonly Uri _facebookBaseAuthUri = new Uri("https://www.facebook.com/dialog/oauth");
readonly AuthorizeAttribute _authorizationAttribute;
readonly string _facebookAppId;
public OAuthFacebookOpHandler() : base("response") { }
public OAuthFacebookOpHandler(AuthorizeAttribute authorizeAttribute, string appId) : this() {
_authorizationAttribute = authorizeAttribute;
_facebookAppId = appId;