Skip to content

Instantly share code, notes, and snippets.

View brendankowitz's full-sized avatar

Brendan Kowitz brendankowitz

View GitHub Profile
@brendankowitz
brendankowitz / UnitTestFhirNet19.cs
Created November 20, 2020 15:07
Extension differences
using System;
using System.Linq;
using Hl7.Fhir.Introspection;
using Hl7.Fhir.Model;
using Hl7.Fhir.Serialization;
using Xunit;
namespace TestProject1
{
public class UnitTest1
@brendankowitz
brendankowitz / CancellableSemaphore.cs
Last active January 24, 2024 11:24
What is a good pattern for Awaiting Semaphores with a CancellationToken?
/// <summary>
/// Allows a semaphore to release with the IDisposable pattern
/// </summary>
/// <remarks>
/// Solves an issue where using the pattern:
/// <code>
/// try { await sem.WaitAsync(cancellationToken); }
/// finally { sem.Release(); }
/// </code>
/// Can result in SemaphoreFullException if the token is cancelled and the
<!DOCTYPE html>
<html class="en-us" lang="en">
<head>
<title></title>
</head>
<body>
Crash!!
<h3><a id="download" name="download">Improved download experience</a></h3>
@brendankowitz
brendankowitz / Extensions.cs
Created June 11, 2015 19:59
Returns the property name from a lambda expression
using System;
using System.Linq;
using System.Linq.Expressions;
namespace Extensions
{
public class PropertyExtension
{
public static string GetFor<T>(Expression<Func<T>> propertyNameLambda)
{
@brendankowitz
brendankowitz / JsReferenceBundleOrderer.cs
Created February 4, 2015 03:48
Js Bundle Orderer using comment references. Using QuickGraph nuget package.
public class JsReferenceBundleOrderer : IBundleOrderer
{
readonly Regex _referenceRegex = new Regex(@"///\s*<reference\s+path\s*=\s*""(?<filename>.*?)""\s*(?:/>|>)", RegexOptions.Compiled);
public IEnumerable<BundleFile> OrderFiles(BundleContext context, IEnumerable<BundleFile> files)
{
var bundleFiles = files as List<BundleFile> ?? files.ToList();
var adjacencyGraph = new AdjacencyGraph<string, Edge<string>>();
var topSort = new TopologicalSortAlgorithm<string, Edge<string>>(adjacencyGraph);
@brendankowitz
brendankowitz / BundleConfig.cs
Last active August 29, 2015 14:01
Register directory based script bundles in an mvc project
var applicationPath = app.Server.MapPath("~/");
var contentBundleBasePath = app.Server.MapPath("~/Content/bundles");
bundles.CreateRecursiveBundles(
contentBundleBasePath,
applicationPath,
contentBundleBasePath);
bundles.CreateRecursiveBundles(app.Server.MapPath("~/Views"), applicationPath, applicationPath);
bundles.CreateRecursiveBundles(app.Server.MapPath("~/Areas"), applicationPath, applicationPath);
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
@brendankowitz
brendankowitz / azure prob.png
Last active December 27, 2015 02:08
An Azure situation...
azure prob.png
@brendankowitz
brendankowitz / modalBootstrapDialog.js
Last active December 22, 2015 02:29
Durandal modal dialog modification for bootstrap dialogs
define(['./composition', './system', './viewModel'],
function (composition, system, viewModel) {
var contexts = {},
modalCount = 0;
function ensureModalInstance(objOrModuleId) {
return system.defer(function (dfd) {
if (typeof objOrModuleId == "string") {
system.acquire(objOrModuleId).then(function (module) {
@brendankowitz
brendankowitz / SetListItemDataTemplateState.cs
Created May 21, 2013 11:23
WinRT + ExtendedVisualStateManager + Caliburn = Visual State Groups in a ListItem DataTemplate
public class SetListItemDataTemplateState
{
public void SelectionChanged(dynamic sender, dynamic args)
{
var container = sender.ItemContainerGenerator;
foreach (var item in args.AddedItems)
{
var listItem = container.ContainerFromItem(item);
var layout = FrameworkElementExtensions.FindDescendantByName(listItem, "RootLayout");
ExtendedVisualStateManager.GoToElementState(layout, "ToSelected", true);