Skip to content

Instantly share code, notes, and snippets.

View krcourville's full-sized avatar

Ken Courville krcourville

View GitHub Profile
@krcourville
krcourville / gist:a4c2a5ad2392fcbaf22a
Created July 20, 2015 15:16
Linqpad recursively print MSSQL table and related tables
const string connectionstring = @"Server=myserver;Database=mydb;Trusted_Connection=True;Connection Timeout=30;";
string dependsSql = @"
select t.name as TableWithForeignKey, fk.constraint_column_id as FK_columns , c.name as ForeignKeyColumn
from sys.foreign_key_columns as fk
inner join sys.tables as t on fk.parent_object_id = t.object_id
inner join sys.columns as c on fk.parent_object_id = c.object_id and fk.parent_column_id = c.column_id
where fk.referenced_object_id = (select object_id from sys.tables where name = @tablename)
order by TableWithForeignKey";
@krcourville
krcourville / PromiseHelper.js
Created May 5, 2015 01:07
Example of sequentially processing an array of promises
function PromiseHelper(){}
PromiseHelper.sequentialProcess = function(promises) {
if(promises.length && promises.length > 0){
return promises.reduce( function( current, acc ) {
return current.then(acc);
});
}else {
return $.when();
}
@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 }
@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 / 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 / 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 / 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: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: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: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())