Skip to content

Instantly share code, notes, and snippets.

View refactorsaurusrex's full-sized avatar

refactorsaurusrex

View GitHub Profile
@refactorsaurusrex
refactorsaurusrex / WPFZoomImageOnLoad1.xml
Last active August 29, 2015 14:16
WPF: Zoom In An Image On Application Load
<!-- Assume a data context with all the appropriate bindings -->
<Window
<Window.InputBindings>
<KeyBinding Key="Up" Command="{Binding ZoomIn}" />
<KeyBinding Key="Down" Command="{Binding ZoomOut}" />
</Window.InputBindings>
<Grid>
<Image Source="{Binding MyPath}" HorizontalAlignment="Center"
VerticalAlignment="Center" Width="{Binding DisplayedWidth}" >
<Image.Triggers>
@refactorsaurusrex
refactorsaurusrex / Program.cs
Created May 29, 2015 04:54
Super simple C# script to zip up build artifacts for a project in the same solution, give the zip file a sequential, version specific name, and add it to a specific directory.
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@refactorsaurusrex
refactorsaurusrex / example.build.xml
Created June 4, 2015 21:37
How to edit the content of a subset of files from within a directory using NAnt. In this example, I iterate recursively through all paths contained within `C:\somePath\dbDirectory\` for all files with the extension of `.sql.template`, load the file, replace all instances of `@DBNAME@` with the value of `${database.name}`, and save the edited fil…
<foreach item="File" property="filename">
<in>
<items>
<include name="C:\somePath\dbDirectory\**.sql.template"/>
</items>
</in>
<do>
<loadfile file="${filename}" property="fileContents">
<filterchain>
<replacetokens>
@refactorsaurusrex
refactorsaurusrex / AzureBlobClient.cs
Last active August 29, 2015 14:23
Simple client for uploading a local directory to an Azure blog storage container.
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
namespace PublishClickOnceToAzure
{
public class AzureBlobClient
{
@refactorsaurusrex
refactorsaurusrex / selectMenu.html
Created July 4, 2015 19:03
How To Bind A JQueryUI SelectMenu Widget To KnockOut
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.3.0/knockout-min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/sunny/jquery-ui.css">
<script>
$(document).ready(function() {
@refactorsaurusrex
refactorsaurusrex / GetFiles.cs
Created November 2, 2015 22:26
Recursively navigate the file system, skipping any files or directories that are not accessible.
public static IEnumerable<string> GetFiles(string root, string searchPattern)
{
Stack<string> pending = new Stack<string>();
pending.Push(root);
while (pending.Count != 0)
{
var path = pending.Pop();
string[] next = null;
try
{
@refactorsaurusrex
refactorsaurusrex / pie.cs
Created December 12, 2015 03:31
C# Pie!
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Confections
{
public class Pie<T> : IReadOnlyCollection<Slice<T>>
{
readonly List<Slice<T>> slices;
@refactorsaurusrex
refactorsaurusrex / Program.cs
Last active April 23, 2016 02:51
Lists all currently running IIS applications, along with their app pool names and process ids.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ListAllWebApps
{
class Program
@refactorsaurusrex
refactorsaurusrex / wordBoundaries.cs
Created May 26, 2016 20:02
A better way to add line endings at specific positions in a long text string.
var text = "A long string....";
var words = text.Split(' ');
var allLines = words.Skip(1).Aggregate(words.Take(1).ToList(), (lines, word) =>
{
if (lines.Last().Length + word.Length >= 80)
lines.Add(word);
else
lines[lines.Count - 1] += " " + word;
return lines;
});
@refactorsaurusrex
refactorsaurusrex / DeleteLocalGitBranches.ps1
Last active August 18, 2016 14:31
Delete all local git branches
function Delete-LocalBranches ($Commit = 'HEAD', [switch]$Force) {
git branch |
? { $_ -notmatch '(^\*)|(^. master$)' } |
% { git branch $(if($Force) { '-D' } else { "-d" }) $_.Substring(2) }
}