Skip to content

Instantly share code, notes, and snippets.

View randyburden's full-sized avatar

Randy Burden randyburden

View GitHub Profile
@randyburden
randyburden / gist:1915136
Created February 26, 2012 08:23
Enabling Custom Key-Press Logic for an IsReadOnly WPF RichTextBox
In your XAML:
-------------
<RichTextBox
Name="MyRichTextBox"
PreviewKeyDown="MyRichTextBox_PreviewKeyDown" />
In your C# Code-behind:
-----------------------
@randyburden
randyburden / FluentTableCells.js
Created May 7, 2012 19:01
Fluent Table Cells - An easily extendible fluent interface for programmatically creating table cells in JavaScript.
/*!
* Fluent Table Cells - An easily extendible fluent interface for programmatically creating table cells in JavaScript.
* Author: Randy Burden
* http://www.randyburden.com
* Open Source Url: https://gist.github.com/2629702
*
* Example usage:
var row = '<tr>';
@randyburden
randyburden / HtmlWithJQueryTemplate.html
Created November 15, 2012 22:45
HTML webpage template with jQuery and jQuery UI included
<!DOCTYPE html>
<html>
<head>
<title></title>
<!-- Stylesheets -->
<link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/themes/smoothness/jquery-ui.css" >
<style type="text/css">
body { font-family: Arial, Sans-Serif; font-size: 12pt; }
@randyburden
randyburden / NHibernateHelper.cs
Created November 28, 2012 21:02
NHibernate Helper Class
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Cfg;
/// <summary>
/// NHibernate Helper
/// </summary>
/// <remarks>
/// Because the SessionFactory creation is lazy-loaded, you technically never need to bootstrap NHibernate
@randyburden
randyburden / NHibernate_Duplicate_Mapping_Solution.cs
Created November 28, 2012 21:40
NHibernate Duplicate Mapping Problem Solution
/*
NHibernate now has the BeforeBindMapping event which gives you access to the object representation of the HBM XML files at runtime.
Use the BeforeBindMapping event to gain access to the object representation of the .HBM XML files.
This event allows you to modify any properties at runtime before the NHibernate Session Factory is created. This also makes the FluentNHibernate-equivalent convention unnecessary. Unfortunately there is currently no official documentation around this really great feature.
Here's a global solution to duplicate mapping problems ( Just remember that all HQL queries will now need to use Fully Qualified Type names instead of just the class names ).
*/
@randyburden
randyburden / Add_Yourself_As_A_Sql_Server_Express_SysAdmin.txt
Created November 28, 2012 21:45
Add Yourself as a SQL Server Express SysAdmin
Adding Yourself as SQL Server Express SysAdmin
----------------------------------------------
Problem:
The help desk installs SQL Server on our developer machines under their own user accounts meaning you aren't a
sysadmin on your own SQL Server Express instance which in turn means you can't create a new database.
Solution:
@randyburden
randyburden / ContextStorage.cs
Last active December 10, 2015 08:08
Abstracts away the application's underlying storage context allowing you to simply call Get() or Store() and it will store the data in the appropriate context. It makes use of reflection too so that there is no need to reference the System.Web assembly if the application doesn't need it. For ASP.NET applications, it will store in the data in the…
/// <summary>
/// Provides a means of getting/storing data in the host application's
/// appropriate context.
/// </summary>
/// <remarks>
/// For ASP.NET applications, it will store in the data in the current HTTPContext.
/// For all other applications, it will store the data in the logical call context.
/// </remarks>
public static class ContextStorage
{
@randyburden
randyburden / StopwatchHelper.cs
Last active December 10, 2015 22:59
Simple StopWatcher helper class to give you back a nicely formatted elapsed time.
using System;
using System.Diagnostics;
namespace PDFMerger.Helpers
{
public static class StopwatchHelper
{
/// <summary>
/// Returns the elapsed time of the stopwatch in a formatted string.
/// </summary>
@randyburden
randyburden / ServiceInterceptorAttribute.cs
Last active September 1, 2016 16:19
Provides numerous service interceptors/hooks for a WCF service, endpoint, or method all wrapped up in a single attribute. You can derive from the ServiceInterceptorAttribute class to create your own custom interceptor attribute or use it in conjunction with a class that implements IServiceInterceptor. Update: This has graduated to it's own proje…
using System;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace Utilities.Wcf.Interceptors
{
/// <summary>
@randyburden
randyburden / DoubleBracketedTokenHelper.cs
Last active December 13, 2015 21:59
DoubleBracketedTokenHelper - A template / token helper thingy I put together where each token is wrapped in double brackets a la handlebars.js like. This is definately half-baked and is meant to be more of a "Hey, note to self: next time your coding a template helper, remember to look at this gist to get some ideas about how to go about writing …
public class DoubleBracketedTokenHelper
{
public Dictionary<string, string> TokensAndValues = new Dictionary<string, string>();
/// <summary>
/// Tokens to ignore.
/// </summary>
public List<string> IgnoredTokens = new List<string> { "{{cr}}" };
// This finds any characters in between open and closing double brackets