Skip to content

Instantly share code, notes, and snippets.

View AnthonyMastrean's full-sized avatar
🏡
Working remotely

Anthony Mastrean AnthonyMastrean

🏡
Working remotely
View GitHub Profile
@AnthonyMastrean
AnthonyMastrean / Foreach.cs
Last active September 27, 2015 02:48
Reverse foreach structure
namespace System
{
public static class ReverseForeach
{
public static void ForEach<T>(this Action<T> action, IEnumerable<T> enumerable)
{
foreach(var item in enumerable)
{
action(item);
}
@AnthonyMastrean
AnthonyMastrean / SystemDate.cs
Created May 11, 2012 14:23
Public static funcs wrapping system calls.
namespace System
{
public static class SystemDate
{
public static Func<DateTime> UtcNow { get; private set; }
static SystemDate()
{
Reset();
}
@AnthonyMastrean
AnthonyMastrean / Indexes.cs
Created June 4, 2012 14:30
Type Safe Enum helper methods.
public class Index
{
public static Index One = new Index(1);
public static Index Two = new Index(2);
public static Index Three = new Index(3);
public int Value { get; private set; }
public Index(int value)
{
// http://www.interact-sw.co.uk/iangblog/2004/04/26/yetmoretimedlocking
using System;
using System.Threading;
// Thanks to Eric Gunnerson for recommending this be a struct rather
// than a class - avoids a heap allocation.
// Thanks to Change Gillespie and Jocelyn Coulmance for pointing out
// the bugs that then crept in when I changed it to use struct...
// Thanks to John Sands for providing the necessary incentive to make
@AnthonyMastrean
AnthonyMastrean / closebracket.ahk
Created July 12, 2012 21:12
Close Bracket Script
;NOTE: Add the windows where this script is active here
GroupAdd, TextEditors, ahk_class TextPad4
GroupAdd, TextEditors, ahk_class ConsoleWindowClass
#IfWinActive, ahk_group TextEditors
;NOTE: Is this a concatenated string acting as an array?
altkeys = (Join: LTrim
AppsKey, LWin, RWin, LControl, LShift, RShift, LAlt, RAlt
PrintScreen, CtrlBreak, Pause, Break
@AnthonyMastrean
AnthonyMastrean / rakefile.rb
Last active October 8, 2015 14:07
MSpec + Rake + TeamCity
# Find all spec assemblies, lazy.
mspec_assemblies = FileList['bin/Release/*.Specs.dll']
mspec_results = mspec_assemblies.pathmap("%X.results.xml")
# Try to solve the TeamCity build log problem by quieting the service messages
# and, instead, generating a test result file per assembly. The console messages
# are probably still useful (so do not include '--silent').
task :generate_mspec_tasks do
mspec_assemblies.zip(mspec_results) do |name, result|
mspec name do |mspec|
@AnthonyMastrean
AnthonyMastrean / Latch.cs
Created September 6, 2012 14:55
Latch object and some related behavior
namespace System
{
public class Latch
{
public static explicit operator Latch(bool isSet)
{
return new Latch(isSet);
}
public static implicit operator bool(Latch latch)
@AnthonyMastrean
AnthonyMastrean / nuspec.rb
Created September 27, 2012 21:32
Automatic discovery of NuGet dependencies.
def auto_add_dependencies(projects)
projects.each do |project|
each_project_dependency do |dependency|
@dependencies.push dependency
end
end
end
def get_packages_config(project)
return File.join File.dirname project, 'packages.config'
@AnthonyMastrean
AnthonyMastrean / InstallShieldConfiguration.rb
Created October 22, 2012 15:06
InstallShield multi version support
module InstallShield
class InstallShieldConfiguration
attr_accessor :command, :parameters, :ism, :product_version, :product_code
attr_reader :new_product_code
def initialize
@command = File.join ENV['ProgramFiles(x86)'], 'InstallShield/2010 StandaloneBuild/System/IsCmdBld.exe'
@parameters = []
end
@AnthonyMastrean
AnthonyMastrean / IAmAnAction.cs
Created October 25, 2012 14:13
Request handler redux
public interface IAmAnAction
{
void Handle(dynamic data = null);
}