Skip to content

Instantly share code, notes, and snippets.

View mjul's full-sized avatar

Martin Jul mjul

View GitHub Profile
@mjul
mjul / Microsoft.PowerShell_profile.ps1
Last active November 15, 2018 18:31
Visual Studio 2013 developer prompt for PowerShell
pushd 'c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC'
cmd /c "vcvarsall.bat&set" |
foreach {
if ($_ -match "=") {
$v = $_.split("="); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])"
}
}
popd
write-host "`nVisual Studio 2013 Command Prompt variables set." -ForegroundColor Yellow
@mjul
mjul / configure-sql-server.ps1
Created May 31, 2013 14:57
Limit the memory usage of SQL Server. We use it to set up developer PCs and other instances where a SQL Server should share the machine with other applications.
## Configure a SQL Server for running on a shared machine (set max memory)
Function Configure-SqlServer
{
<#
.Synopsis
Configure a SQL Server for use with Panda.
.Example
Configure-SqlServer .\SQLExpress
Configure the local SQL Server Express
@mjul
mjul / DynamicLookup.cs
Created May 28, 2013 09:07
Using C# dynamic type to navigate a dictionary via dynamically generated properties corresponding to the dictionary's keys.
protected override University MapFromRow(Row input)
{
// Using dynamic so we can hit the TryGetMember on Row to look up
// missing properties (here: all of them) in the key-value map.
dynamic row = input;
return new University()
{
UniversityNumber = Int32.Parse(row.UniversityNumber),
Name = row.UniversityName,
};
@mjul
mjul / CompileModel.tt
Created May 23, 2013 16:00
Visual Studio T4 template that invokes an external compiler on a file in the project to generate a C# code file.
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Diagnostics" #>
<#@ assembly name="EnvDTE" #>
<#@ import namespace="EnvDTE" #>
<#@ output extension=".cs" #>
@mjul
mjul / EqualityTesting.cs
Last active December 16, 2015 22:39
Test Helper for Equals and GetHashCode, checking that the Equals relation is an equivalence relation, meaning that it is Reflexive, Transitive and Symmetrical. Also tests equality operator overloading.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
namespace TestHelpers
{
public class EqualityTesting
@mjul
mjul / IntegrationAttribute.cs
Last active December 16, 2015 22:29
Attributes to mark NUnit tests by category, so you can see how much environment they need set up and run them in the right order, for example: * Unit test (in-process), * Integration test (needs files, databases, network, services, or other out-of-process resources, but the System Under Test is limited to our own system) * SystemIntegrationTest …
using NUnit.Framework;
namespace DeveloperTest.TestHelpers
{
public class IntegrationAttribute : CategoryAttribute
{
public IntegrationAttribute()
: base("Integration")
{
}
@mjul
mjul / LinqExpressionsTest.cs
Created May 2, 2013 11:36
Navigating Linq expression trees to get names of nodes, member accessors etc. This can be used to compile Linq expressions, e.g. transforming expressions to query code for external systems like services or databases.
using System;
using System.Linq.Expressions;
using NUnit.Framework;
namespace LinqExperiments
{
[TestFixture]
public class LinqExpressionsTest
{
private class NumberedText
@mjul
mjul / convert-visio-drawings-to-pdf.ps1
Created March 21, 2013 11:10
Convert the Visio drawings in the current directory to PDF
# Convert Visio (2013) documents to PDF
$drawings = Get-ChildItem -Filter "*.vsdx"
Write-Host "Converting Visio documents to PDF..." -ForegroundColor Cyan
try
{
$visio = New-Object -ComObject Visio.Application
$visio.Visible = $true
@mjul
mjul / CSharpCallingJavascript.cs
Created February 26, 2013 15:15
Compile and call JavaScript code from .NET (C#). Opens up the possibility to use for example ClojureScript core.logic as a rule engine in C# business applications.
using System;
using System.CodeDom.Compiler;
using Microsoft.JScript;
namespace JavascriptFromDotNet
{
class Program
{
private const string Source = @"
package Test
@mjul
mjul / DataApplicationException.cs
Last active October 13, 2015 12:18
Easily add context to exceptions using anonymous types. // throw new DataException("Import failed.", null, new { DataSource = "FileMaker", Type = "Student", StudentNumber = 123 });
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
namespace ClassLibrary1
{
/// <summary>