Skip to content

Instantly share code, notes, and snippets.

View haacked's full-sized avatar
🏠
Code code code

Phil Haack haacked

🏠
Code code code
View GitHub Profile
@haacked
haacked / gist:912552
Created April 10, 2011 17:36
Sample jQuery File
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
<script src="../../Scripts/jquery-1.5.1.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#form").validate({
rules: {
@haacked
haacked / gist:912630
Created April 10, 2011 19:16
jquery validation with radio buttons.
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
<style type="text/css">
input.error
{
border: solid 1px red;
color: Red;
}
@haacked
haacked / FormatAllFiles.ps1
Created May 21, 2011 08:06
Format all CS files in a Visual Studio solution (UGLY VERSION)
// Open up the NuGet Package Manager in Visual Studio and paste the following line to format every file in the solution.
// I'll write a not-so-ugly version later. ;)
// BUG! This doesn't recursively grab all files from the project. :(
$dte.Solution.Projects | ForEach-Object {$_.ProjectItems | ForEach-Object { if ($_.Name.EndsWith('.cs')) {$window = $_.Open('{7651A701-06E5-11D1-8EBD-00A0C90F26EA}'); if ($window){Write-Host $_.Name;[System.Threading.Thread]::Sleep(100);$window.Activate();$_.Document.DTE.ExecuteCommand('Edit.FormatDocument');$_.Document.DTE.ExecuteCommand('Edit.RemoveAndSort');$window.Close(1);}} }}
@haacked
haacked / phil-bios.md
Last active January 13, 2021 16:28
Phil's Bios

I'm often asked to provide a bio such as when speaking. I hate writing them over and over so I keep this around.

Bio

Phil Haack is the founder and CEO of Haacked LLC where he coaches software organizations and helps them become the best versions of themselves.

To do this, Phil draws upon his experiences at GitHub where he was a director of engineering and helped make GitHub friendly to developers on the Microsoft platform.

He also draws upon his experience at Microsoft where he was a Senior Program Manager responsible for shipping ASP.NET MVC, NuGet, among other projects. These products had permissive open source licenses and ushered in Microsoft’s Open Source era.

@haacked
haacked / TestHelper.cs
Created January 14, 2012 07:25
String Comparison Unit Test Helper
public static class TestHelpers
{
public static void ShouldEqualWithDiff(this string actualValue, string expectedValue)
{
ShouldEqualWithDiff(actualValue, expectedValue, DiffStyle.Full, Console.Out);
}
public static void ShouldEqualWithDiff(this string actualValue, string expectedValue, DiffStyle diffStyle)
{
ShouldEqualWithDiff(actualValue, expectedValue, diffStyle, Console.Out);
@haacked
haacked / utf-rt.cs
Created January 30, 2012 06:27
Round Tripping UTF-8
using System;
using System.Text;
class Program
{
static void Main(string[] args)
{
var data = new byte[] { 128 };
string text = Encoding.UTF8.GetString(data);
var bytes = Encoding.UTF8.GetBytes(text);
@haacked
haacked / windows-1252-roundtrip.cs
Created January 30, 2012 06:55
Windows-1252 Encoding Round Trip Demo
using System;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
var encoding = Encoding.GetEncoding(1252);
for (int b = Byte.MinValue; b <= Byte.MaxValue; b++)
@haacked
haacked / ServiceResolverAdapter.cs
Created March 11, 2012 19:34
ServiceResolverAdapter: Allows you to use the ASP.NET MVC DependencyResolver for ASP.NET Web API
public class ServiceResolverAdapter : IDependencyResolver
{
private readonly System.Web.Mvc.IDependencyResolver dependencyResolver;
public ServiceResolverAdapter(System.Web.Mvc.IDependencyResolver dependencyResolver)
{
if (dependencyResolver == null) throw new ArgumentNullException("dependencyResolver");
this.dependencyResolver = dependencyResolver;
}
@haacked
haacked / continue-after-unit-tests.cs
Created October 8, 2012 22:34
ContinueAfter Unit Tests
public class TheContinueAfterMethod
{
[Fact]
public void RunsNextItemAfterCompletion()
{
var stringSequence = new[] { "one", "two", "three" }.ToObservable();
var observed = new List<String>();
Observable.Return(123).ContinueAfter(() => stringSequence)
.Subscribe(observed.Add);
@haacked
haacked / GetLoadableTypes.cs
Created January 5, 2013 22:14
Method to return all loadable types in an assembly. See [this blog post](http://haacked.com/archive/2012/07/23/get-all-types-in-an-assembly.aspx) for details.
public static IEnumerable<Type> GetLoadableTypes(this Assembly assembly)
{
if (assembly == null) throw new ArgumentNullException("assembly");
try
{
return assembly.GetTypes();
}
catch (ReflectionTypeLoadException e)
{
return e.Types.Where(t => t != null);