Skip to content

Instantly share code, notes, and snippets.

View motowilliams's full-sized avatar

Eric Williams motowilliams

View GitHub Profile
@motowilliams
motowilliams / Getting-started-with-MVCContrib-Filters02.cs
Created October 23, 2011 20:34
Getting-started-with-MVCContrib-Filters
[HttpPost]
[ModelStateToTempData]
public ActionResult CreateCustomer(CustomerEditModel customerEditModel)
{
if (ModelState.IsValid)
{
//Do Something Worthy of your NEW Customer
return RedirectToAction("Success");
}
return RedirectToAction("FixErrors");
@motowilliams
motowilliams / Getting-started-with-MVCContrib-Filters03.cs
Created October 23, 2011 20:35
Getting-started-with-MVCContrib-Filters
[HttpPost]
[ModelStateToTempData]
[PassParametersDuringRedirect]
public ActionResult CreateCustomer(CustomerEditModel customerEditModel)
{
if (ModelState.IsValid)
{
//Do Something Worthy of your NEW Customer
return this.RedirectToAction(x => x.Success(customerEditModel));
}
@motowilliams
motowilliams / Stupid-Linq-Tricks-Record-Rollup01.cs
Created October 23, 2011 20:40
Stupid-Linq-Tricks-Record-Rollup
//Source object where depending on the length of the text
public class RawRecords
{
public int Id { get; set; }
public int Sequence { get; set; }
public DateTime Timestamp { get; set; }
public string Comment { get; set; }
}
//Destination object where you want the multiple comment lines to be rolled up into the destination CommentText property.
@motowilliams
motowilliams / Stupid-Linq-Tricks-Record-Rollup02.cs
Created October 23, 2011 20:42
Stupid-Linq-Tricks-Record-Rollup
[TestMethod]
public void multiple_comment_rollup()
{
IEnumerable<RawRecords> rawRecords = GetSampleRows();
const string EXPECTED_COMMENT_42 = "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.";
const string EXPECTED_COMMENT_69 = "Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante.";
IEnumerable<Comment> actualComments =
from ncr in rawRecords
group ncr by new { ncr.Id, ncr.Timestamp }
@motowilliams
motowilliams / Stupid-Linq-Tricks-Record-Rollup03.cs
Created October 23, 2011 20:43
Stupid-Linq-Tricks-Record-Rollup
private static IEnumerable<RawRecords> GetSampleRow()
{
var timestamp1 = new DateTime(2010, 3, 12);
return new List<RawRecords>
{
new RawRecords { Sequence = 4, Id = 42, Timestamp = timestamp1, Comment = "et malesuada fames " },
new RawRecords { Sequence = 1, Id = 42, Timestamp = timestamp1, Comment = "Pellentesque habitant " },
new RawRecords { Sequence = 3, Id = 42, Timestamp = timestamp1, Comment = "senectus et netus " },
new RawRecords { Sequence = 5, Id = 42, Timestamp = timestamp1, Comment = "ac turpis egestas." },
new RawRecords { Sequence = 2, Id = 42, Timestamp = timestamp1, Comment = "morbi tristique " },
@motowilliams
motowilliams / LINQPad-with-Databases01.sql
Created October 23, 2011 20:44
LINQPad-with-Databases
BEGIN TRANSACTION;
CREATE TABLE People (Id INTEGER PRIMARY KEY, FirstName varchar(25), LastName varchar(50), JokerRating int);
INSERT INTO People VALUES(1,'Chuck','Norris',0);
INSERT INTO People VALUES(2,'Clint','Eastwood',0);
INSERT INTO People VALUES(3,'Pauly','Shore',1);
INSERT INTO People VALUES(4,'Eric','Williams',2);
COMMIT;
C:\Users\Eric\code\xizzle [master]> .\build.ps1
psake version 4.00
Copyright (c) 2010 James Kovacs
Executing Clean
Executing Init
Executing Compile
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.
@motowilliams
motowilliams / gist:1610702
Created January 14, 2012 08:07
AppHarbor Nuget Package Restore
------ Build started: Project: MapR, Configuration: Debug Any CPU ------
Successfully installed 'jQuery 1.6.4'.
Successfully installed 'Microsoft.Web.Infrastructure 1.0.0.0'.
Successfully installed 'SignalR 0.3.5'.
Successfully installed 'SignalR.Js 0.3.5'.
Successfully installed 'SignalR.Server 0.3.5'.
MapR -> C:\Users\Eric\code\MapR\bin\MapR.dll
Attempting to build package from 'MapR.csproj'.
Packing files from 'C:\Users\Eric\code\MapR\bin'.
Found packages.config. Using packages listed as dependencies
Build started 1/14/2012 8:21:18 AM.
Project "D:\temp\t1pzp5xx.p3v\input\MapR.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "Release|Any CPU".
Project "D:\temp\t1pzp5xx.p3v\input\MapR.sln" (1) is building "D:\temp\t1pzp5xx.p3v\input\MapR.csproj" (2) on node 1 (default targets).
RestorePackages:
"D:\temp\t1pzp5xx.p3v\input\.nuget\nuget.exe" install "D:\temp\t1pzp5xx.p3v\input\packages.config" -source "" -o "D:\temp\t1pzp5xx.p3v\input\packages"
Successfully installed 'jQuery 1.6.4'.
Successfully installed 'Microsoft.Web.Infrastructure 1.0.0.0'.
Successfully installed 'SignalR 0.3.5'.
@motowilliams
motowilliams / GoogleMapsApiTests.cs
Created January 16, 2012 20:45 — forked from mythz/GoogleMapsApiTests.cs
Parsing the GMaps API JSON Response with ServiceStack's JsonSerializer
//Code sample from test:
//https://github.com/ServiceStack/ServiceStack.Text/blob/master/tests/ServiceStack.Text.Tests/DynamicModels/GoogleMapsApiTests.cs
using System;
using System.Collections.Generic;
using NUnit.Framework;
namespace ServiceStack.Text.Tests.DynamicModels
{
public class GoogleMapsApiTests