Skip to content

Instantly share code, notes, and snippets.

Avatar

Amir Barylko amirci

View GitHub Profile
@amirci
amirci / PropertiesInterceptor
Created Nov 5, 2010
Interceptor that stores the properties of an interface
View PropertiesInterceptor
public class PropertyInterceptor : IInterceptor
{
private readonly IDictionary<string, object> _properties = new Dictionary<string, object>();
public void Intercept(IInvocation invocation)
{
var key = invocation.Method.Name.Substring(4);
if (invocation.Method.Name.StartsWith("set_"))
{
@amirci
amirci / Fluid enumerable join to string.cs
Created Mar 18, 2011
Extensions to Join all the elements in the collection calling the functor and using separator
View Fluid enumerable join to string.cs
public static string Join<T>(this IEnumerable<T> collection, char separator, Func<T, string> fn)
{
return collection
.Head()
.Aggregate(new StringBuilder(), (b, x) =>
{
b.Append(fn(x));
b.Append(separator);
return b;
})
@amirci
amirci / Rakefile.rb
Created Mar 27, 2011
Rakefile to generate nuget packages passing the name of the package, version and folder to get the assemblies from
View Rakefile.rb
require 'rubygems'
require 'rake/clean'
require 'albacore'
include FileUtils
desc 'Publish nuget package'
task :default => ["deploy:publish"]
namespace :deploy do
@amirci
amirci / local nuget packages.rb
Created Apr 10, 2011
Install packages from packages_local.config
View local nuget packages.rb
FileList["**/packages_local.config"].each do |file|
cp file, "packages.config"
sh "nuget install packages.config /OutputDirectory Packages /source #{local_feed}"
end
View test_prdc_api.rb
require 'rubygems'
require 'net/http'
require 'json'
require 'uri'
require 'date'
@host = 'prairiedevcon.com'
#@host = 'localhost'
@port = '80'
#@port = '50758'
@amirci
amirci / prdc_dsl_populate.cs
Created Jun 5, 2011
DSL to populate presenters and sessions
View prdc_dsl_populate.cs
return MakeSlots(
b => b.From(7).To(8).Event("Registration & Breakfast"),
b => b.From(8).To(8.15).Event("Welcome"),
b => b.From(8.15).To(9.15).Event("KeyNote"),
b => b.From(9.30).To(10.45)
.InRoom(LombardyA)
.Presenter("Tom Opgenorth").Session("Intro Into the Android Army"),
b => b.InRoom(LombardyB)
.Session("Limits of TDD: How To Test Code Never Meant To Be")
.Presenter("Robert Reppel"),
@amirci
amirci / virtual_and_new.cs
Created Jun 6, 2011
Virtual and redefining methods with "new" is not the same
View virtual_and_new.cs
public class ConcreteMockTest
{
[Test]
public void Worker_WhenDoWorkIsCalled_SendsEmailToTylerAboutRussianBrides()
{
var emailSender = new FakeEmailSender();
var worker = new Worker(emailSender);
worker.DoWork();
@amirci
amirci / param_with_anonymous_class.cs
Created Sep 14, 2011
Anonymous classes as parameters
View param_with_anonymous_class.cs
// using a IDictionary
public void ExecuteCall(string query, IDictionary<string, object> parameters);
ExecuteCall("SELECT * from....", new Dictionary { {"City", "New York" }, { "Code", 3 } });
// using an anonymous
public void ExecuteCall(string query, object parameters);
// and to call it
ExecuteCall("SELECT * from....", new { City = "New York", Code = 3 } );
@amirci
amirci / expression_property_name.cs
Created Sep 15, 2011
Using expression to pass property names
View expression_property_name.cs
// Given the class
class PropertyId {
public int Id {get;set;}
public int StateCode {get;set;}
}
var id = new PropertyId { Id = 1, StateCode = "NY" };
// call the method
SetProperty(id => id.StateCode, "CA");
@amirci
amirci / C# NumberFor
Created Jan 7, 2012 — forked from anonymous/C# NumberFor
NumberFor extension for HtmlHelper
View C# NumberFor
using System;
using System.Linq.Expressions;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Text.RegularExpressions;
namespace Website.Extensions
{
public static class HtmlExtensions
{