Skip to content

Instantly share code, notes, and snippets.

View dcrosby42's full-sized avatar

David Crosby dcrosby42

  • Cisco Systems, Inc.
  • Grand Rapids MI
View GitHub Profile
class String
def from_json
ActiveSupport::JSON.decode(self)
end
end
@dcrosby42
dcrosby42 / gist:295900
Created February 5, 2010 16:03
New git repo from branch
# Creating a new git repository based on the subdirectory of an existing repository
# Got this from: http://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository
git clone --no-hardlinks project327 compass
cd compass
git filter-branch --subdirectory-filter bloomfire-compass HEAD -- --all
git reset --hard
git gc --aggressive
git prune
@dcrosby42
dcrosby42 / watin_search_helper.js
Created November 11, 2010 04:59
Helper function to embed in your page to let WatiN execute a CSS-selector based search for a DOM element.
;WatinSearchHelper = function ($) {
var earTagId = 1;
var getElementId = function (cssSelector) {
var resultId = "_no_element_";
var el = $(cssSelector);
if (el.length > 0) {
var firstEl = el[0];
if (firstEl.id == "") {
// Give this element a contrived id so we can find it directly from the WatiN side:
@dcrosby42
dcrosby42 / WatinSearchHelper_BrowserExtensions.cs
Created November 11, 2010 05:01
Extension method for WatiN.Core.Browser, utilizes in-page JS function WatinSearchHelper.getElementId()
using WatiN.Core;
namespace WatinSearchHelper
{
public static class BrowserExtensions
{
public static Element FindViaJQuery(this Browser browser, string cssSelector)
{
var elementId = browser.Eval(string.Format("WatinSearchHelper.getElementId(\"{0}\")", cssSelector));
return browser.Element(Find.ById(elementId));
}
var link = browser.FindViaJQuery(“.search_results.businesses .result a:contains(‘Applebees’)”).Click();
@dcrosby42
dcrosby42 / FullMigrationTest.cs
Created February 1, 2011 05:05
Sample code for a migration test using C# and MigratorDotNet for an ASP.NET MVC 2 web app
namespace UnitTests
{
public class FullMigrationTest
{
public static string[] AllExpectedTables = new[]
{
"BlogPost",
"Attachment",
"Photo",
@dcrosby42
dcrosby42 / MigrationTestHelper.cs
Created February 1, 2011 05:08
Utility code that uses MigratorDotNet to execute full sweep migrations.
namespace UnitTests.TestHelpers
{
public class MigrationTestHelper
{
public static readonly string Provider = "SqlServer";
public static readonly string ConnectString = "Database=myapp_test;Data Source=localhost;User Id=myUser;Password=abc123";
public static Migrator.Migrator GetMigrator()
{
var assembly = Assembly.GetAssembly(typeof(BootstrapAspDotNetAuthTables));
@dcrosby42
dcrosby42 / Global_asax.cs
Created February 1, 2011 05:16
Example snippet of Application_Start to execute migrations at startup
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
var assembly = Assembly.GetAssembly(typeof(MvcApplication));
var connectString = ConfigurationManager.ConnectStrings(“ApplicationServices”).ConnectionString;
var migrator = new Migrator(“SqlServer”, connectString, assembly);
@dcrosby42
dcrosby42 / Build_msbuild.xml
Created February 1, 2011 05:40
Sample MSBuild file for running MigratorDotNet migrations
<Project DefaultTargets="All" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="Lib\Migrator.MSBuild.dll" TaskName="Migrator.MSBuild.Migrate" />
<PropertyGroup>
<To>-1</To>
<Env>Development</Env>
<ConnectionString Condition="'$(Env)'=='Development'">Database=myapp_dev;Data Source=localhost;User Id=myuser;Password=abc123</ConnectionString>
<ConnectionString Condition="'$(Env)'=='Test'">Database=myapp_test;Data Source=test_db_server;User Id=myuser;Password=abc123</ConnectionString>
<ConnectionString Condition="'$(Env)'=='Production'">Database=myapp_prod;Data Source=prod_db_server;User Id=myuser;Password=abc123</ConnectionString>
@dcrosby42
dcrosby42 / myGRcitypoints issue #2
Created March 9, 2011 15:37
Vendor "Wes" cannot submit vendor info.
System.Data.SqlClient.SqlException (0x80131904): String or binary data would be truncated.
The statement has been terminated.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result