Skip to content

Instantly share code, notes, and snippets.

#
# Add the SQL Server Provider.
# Source: http://technet.microsoft.com/en-us/library/cc281962(v=sql.105).aspx
#
$ErrorActionPreference = "Stop"
$sqlpsreg="HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.SqlServer.Management.PowerShell.sqlps"
if (Get-ChildItem $sqlpsreg -ErrorAction "SilentlyContinue")
@thoemmi
thoemmi / PreBuild.targets.xml
Created November 21, 2012 07:54
Don't copy referenced assemblies to output folder
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- make all references non-private, so they won't be copied to the output folder -->
<Target Name="ClearReferenceCopyLocalPaths" AfterTargets="ResolveAssemblyReferences">
<ItemGroup>
<ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)" />
</ItemGroup>
</Target>
@thoemmi
thoemmi / gist:3848253
Created October 7, 2012 12:29
Find parent document by path in RavenDB
class Program {
static void Main(string[] args) {
using (var store = new EmbeddableDocumentStore { RunInMemory = true }) {
store.Initialize();
using (var session = store.OpenSession()) {
session.Store(new Document { Path = "a" });
session.Store(new Document { Path = "a/b" });
session.Store(new Document { Path = "a/b/c" });
session.Store(new Document { Path = "a/d" });
@thoemmi
thoemmi / fake-http-context.cs
Created October 5, 2012 19:59 — forked from AlexZeitler/fake-http-context.cs
A Moq-using fake HTTP context to test controllers.
public HttpContextBase FakeHttpContext() {
var context = new Mock<HttpContextBase>();
var files = new Mock<HttpFileCollectionBase>();
var request = new Mock<HttpRequestBase>();
var response = new Mock<HttpResponseBase>();
var session = new Mock<HttpSessionStateBase>();
var server = new Mock<HttpServerUtilityBase>();
var user = new Mock<IPrincipal>();
var identity = new Mock<IIdentity>();
request.Setup(req => req.ApplicationPath).Returns("~/");
@thoemmi
thoemmi / PreBuild.targets.xml
Created September 14, 2012 19:58
Embed referenced assemblies, because ILMerge won't work with WPF applications
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
Originally written by Daniel Chambers (http://www.digitallycreated.net)
http://www.digitallycreated.net/Blog/61/combining-multiple-assemblies-into-a-single-exe-for-a-wpf-application
-->
<Target Name="EmbedReferencedAssemblies" AfterTargets="ResolveAssemblyReferences">
<ItemGroup>
<!-- get list of assemblies marked as CopyToLocal -->
<AssembliesToEmbed Include="@(ReferenceCopyLocalPaths)" Condition="'%(Extension)' == '.dll'"/>
@thoemmi
thoemmi / Microsoft.PowerShell_profile.ps1
Created September 14, 2012 08:21
my PowerShell profile script
# red background if running elevated
& {
$wid=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$prp=new-object System.Security.Principal.WindowsPrincipal($wid)
$adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator
$IsAdmin=$prp.IsInRole($adm)
if ($IsAdmin)
{
(get-host).UI.RawUI.Backgroundcolor="DarkRed"
clear-host
@thoemmi
thoemmi / PreBuild.targets.xml
Created August 26, 2012 21:22
a msbuild target file creating a CommonAssemblyInfo.cs based on `git describe`
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask
TaskName="GetVersion"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
<ParameterGroup>
<VersionString ParameterType="System.String" Required="true" />
<Version ParameterType="System.String" Output="true" />
@thoemmi
thoemmi / Add-XmlFragment.ps1
Created June 15, 2012 15:50
PowerShell function to add an XML fragment to an XmlNode
<#
.SYNOPSIS
Adds an XML fragment to an XmlNode
.DESCRIPTION
Adds an XML fragment to an XmlNode
.NOTES
Author : Thomas Freudenberg - info@thomasfreudenberg.com
@thoemmi
thoemmi / Expand-ZipFile.ps1
Created May 6, 2012 17:18
Expand-ZipFile
function Expand-ZipFile {
param {
$zipPath,
$destination,
[switch] $quiet
}
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipPath)
$destinationFolder = $shellApplication.NameSpace($destination)
@thoemmi
thoemmi / psake.ps1
Created May 4, 2012 21:01
my psake file with getting latest psake from nuget
# Helper script for those who want to run psake without importing the module.
# Example:
# .\psake.ps1 "default.ps1" "BuildHelloWord" "4.0"
# Must match parameter definitions for psake.psm1/invoke-psake
# otherwise named parameter binding fails
param(
[Parameter(Position=0,Mandatory=0)]
[string]$buildFile = 'default.ps1',
[Parameter(Position=1,Mandatory=0)]