Skip to content

Instantly share code, notes, and snippets.

View krcourville's full-sized avatar

Ken Courville krcourville

View GitHub Profile
@krcourville
krcourville / gist:5818395
Created June 19, 2013 21:44
Demonstration of using generic structures to better organize mappings and the copying of data from a keyed datasource to an object.
//
// datasource
private static Dictionary<string,object> sourceData = new Dictionary<string,object>{
{"test1", "Joe"},
{"test2", DateTime.Now},
{"test3", 5}
};
//
// target object
class Foo
@krcourville
krcourville / gist:5966257
Last active October 16, 2017 07:19
Snippet for JavaScript regions. Place in your personal My Snippets folder (Documents/Visual Studio xxxx) or the global folder: \Program Files (x86)\Microsoft Visual Studio xx.x\JavaScript\Snippets\1033\JavaScript
<CodeSnippet Format="1.1.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>region</Title>
<Author>Ken Courville</Author>
<Shortcut>try</Shortcut>
<Description>Code snippet for a region statement</Description>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
@krcourville
krcourville / gist:6809041
Created October 3, 2013 12:27
Dumping object to HTML table with a Razor view: Here's a razor view for rendering an object to html table. Includes support for arrays, anonymous object, and complex objects with twitter bootstrap formatting. Note: CamelToTitleCase() is a string extension function.
@model object
@{
ViewBag.Title = "Object Information";
}
@if(!Model.GetType().Name.Contains("Anonymous")){
}
@foreach (var prop in Model.GetType().GetProperties())
@krcourville
krcourville / gist:6809075
Last active December 24, 2015 13:59
Functional Fluent Code Sample : To increase code readability and code refactorability (new word), I find myself using fluent functions more and more. As a result, here is a code sample that might be used to toggle visibility of properties for a child view model.
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
using System;
public interface ISelectiveDisplay {
bool IsVisible { get; set; }
ICollection<string> PropertiesToHide { get; }
}
@krcourville
krcourville / gist:6922112
Created October 10, 2013 17:16
XmlDiff Code Sample
void Main()
{
var contact = new Contact{
FirstName = "John",
LastName = "Smith"
};
var sourceXml = ToXml(contact);
@krcourville
krcourville / gist:6933451
Last active December 25, 2015 06:39
Element-centric XML diff with Linq to Xml
void Main()
{
var contact = new Contact{
FirstName = "John",
LastName = "Smith",
HomePhone = new Phone{
Number = "303-123-1234"
}
};
@krcourville
krcourville / gist:7309218
Created November 4, 2013 21:06
Navigate table with arrow keys using jQuery
$('table.arrow-nav').keydown(function(e){
var $table = $(this);
var $active = $('input:focus,select:focus',$table);
var $next = null;
var focusableQuery = 'input:visible,select:visible,textarea:visible';
var position = parseInt( $active.closest('td').index()) + 1;
console.log('position :',position);
switch(e.keyCode){
case 37: // <Left>
$next = $active.parent('td').prev().find(focusableQuery);
@krcourville
krcourville / SqlServer_MongoDb_Insert_PerfTest
Last active August 29, 2015 14:15
A Linqpad script used to test insert performance for various scenarios
const int iterations = 10;
const int inserts = 1000000;
const string mongodbname = "perftest";
private SqlConnection sqlConnection;
private MongoDatabase mongoDb;
private List<Result> allresults = new List<Result>();
#region setup-teardown
private void Setup(){
sqlConnection = new SqlConnection(Connection.ConnectionString);
@krcourville
krcourville / app.config
Created February 24, 2015 21:43
Mongo log4net appender sample using nuget package log4mongo-net
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<connectionStrings>
<add name="mongolog" connectionString="{mymongoconnectionstring}"/>
</connectionStrings>
<appSettings>
@krcourville
krcourville / gist:bb6e19ae2797a800edab
Created April 27, 2015 14:23
CouchBase Lite Prefix Saerch Issue
const string myprop = "myprop";
const string myvalue = "myvalue";
var manager = new Manager(new System.IO.DirectoryInfo(@"C:\temp\cbldb"), ManagerOptions.Default);
var db = manager.GetDatabase("test");
var newdoc = db.CreateDocument();
var props = new Dictionary<string, object>
{
{myprop, myvalue }