Skip to content

Instantly share code, notes, and snippets.

@thoemmi
thoemmi / UpdateVcxprojFiles.ps1
Last active August 29, 2015 14:15
Updates .vcxproj files to Visual Studio 2013 while still building against VS2012 platform
function UpdateVcxprojFile($filename) {
$content = [xml](Get-Content -Path $filename)
$changed = $false
$toolsVersion = $content.Project.ToolsVersion
if ($toolsVersion -ne "12.0") {
$content.Project.ToolsVersion = "12.0"
$changed = $true
}
using System;
using System.Diagnostics;
using System.Net;
namespace ConsoleApplication1 {
internal class Program {
private const int COUNT = 20;
private static void Main() {
var urls = new[] {
@thoemmi
thoemmi / Get-NuGetPackageFolder.ps1
Created May 4, 2012 20:18
Get-NuGetPackageFolder
function Get-NuGetPackageFolder {
param(
[string] $package_name,
[string] $nuget_packages_config
)
$xml = [xml](gc $nuget_packages_config)
$package = $xml.packages.package | where { $_.id -eq $package_name }
Join-Path $packages_dir ($package_name + "." + $package.version)
}
@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)]
@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 / 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 / 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 / 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 / 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>
#
# 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")