Skip to content

Instantly share code, notes, and snippets.

View mgroves's full-sized avatar

Matthew D. Groves mgroves

View GitHub Profile
@mgroves
mgroves / gist:3373650
Created August 16, 2012 21:03
Any way to write this better?
// foos and bars are both List<string>
foreach (var foo in foos)
{
bars.Any(e => e.Contains("something" + foo)).ShouldBeTrue();
}
// when I click the element after the page loads
// nothing happens: no error, no alert, nothing.
// when I run this same code in the JavaScript console
// THEN it will show the alert
// $("#" + context.reportId + " .some-css-class").length is 7
// in normal execution and in the console
// what the heck am I doing wrong
@mgroves
mgroves / gist:4693861
Created February 1, 2013 20:22
TIL about System.Version
public class version_test
{
[Test]
public void test1()
{
Assert.That(new Version(1,0), Is.LessThan(new Version(2,0)));
Assert.That(new Version(1,5), Is.LessThan(new Version(2,0)));
Assert.That(new Version(1,int.MaxValue), Is.LessThan(new Version(2,0)));
Assert.That(new Version(2,0), Is.EqualTo(new Version(2,0)));
[AspectRoleDependency(AspectDependencyAction.Order, AspectDependencyPosition.Before, StandardRoles.Tracing)]
[Serializable]
public class AspectA : OnMethodBoundaryAspect
{
// ... etc ...
}
@mgroves
mgroves / gist:5078543
Created March 3, 2013 22:10
PostSharp lazy loading aspect that uses Lazy<T>
[Serializable]
public class LazyLoadStructureMap : LocationInterceptionAspect
{
Lazy<object> _backingField;
public override void OnGetValue(LocationInterceptionArgs args)
{
if (_backingField == null)
_backingField = new Lazy<object>(() =>
{
<p>
<select name="Associations[0].SomeId">
<option value="">Select...</option>
<option value="7">AAA</option> <!-- why isn't a value in the dropdown selected? -->
<option value="8">BBB</option>
<option value="9">CCC</option>
</select>
<!-- but yet, the value here is populated -->
<input name="Associations[0].Foo" type="text" value="whatever">
</p>
public class ReportingController : BaseController
{
public ActionResult Index()
{
var objDataSource = new ObjectDataSource();
objDataSource.DataSource = typeof (EzReportData);
objDataSource.DataMember = "GetAllTerritories";
objDataSource.Parameters.Add("ez", typeof(int), 1);
var report = new TerritoryReport();
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
IocBootstrap.Configure();
}
}
public partial class _Default : Page
{
public IWhateverService WhateverService { private get; set; }
public ISomethingElse SomethingElseService { private get; set; }
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(WhateverService.HelloWorld());
Response.Write(SomethingElseService.HelloWorld2());
}