Skip to content

Instantly share code, notes, and snippets.

View rally25rs's full-sized avatar

Jeff Valore rally25rs

View GitHub Profile
@rally25rs
rally25rs / gist:cb58c6aa57a04d777efb
Created September 23, 2014 18:46
SQL Server - Get all running queries
SELECT SUBSTRING(st.text, ( r.statement_start_offset / 2 ) + 1,
( ( CASE WHEN r.statement_end_offset <= 0
THEN DATALENGTH(st.text)
ELSE r.statement_end_offset END -
r.statement_start_offset ) / 2 ) + 1) AS statement_text ,
r.session_id,
r.status,
r.command,
r.cpu_time,
r.total_elapsed_time
@rally25rs
rally25rs / CodeSample2.cs
Created May 10, 2011 00:47
Code Sample 2 (factory pattern)
/* ***
* This sample is again from an ORM tool that I had been working on.
*
* This is simply an example of a "factory" pattern that I wrote a few years ago.
* This factory is designed to return the same IDataBinder instance when the same
* database connection string is passed in.
* *** */
@rally25rs
rally25rs / AssertMvc.cs
Created January 8, 2012 15:16
MSTest Assert Utility for MVC3 Controller Unit Testing
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
/// <summary>
/// MSTest Asserts for unit testing MVC3 Controllers.
/// </summary>
public static class AssertMvc
{
public static T ResultIs<T>(object result)
where T : ActionResult
@rally25rs
rally25rs / AnythingToCs.cs
Created April 5, 2012 11:56
Anything to CSV
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace AnythingToCsv
{
public static class EnumerableExtensions
{
@rally25rs
rally25rs / .gitignore
Created August 9, 2012 11:58
.gitignore for .NET projects.
# .gitignore for .NET projects
# Standard VS.NET
obj
bin
*.csproj.user
*.suo
*.cache
Thumbs.db
@rally25rs
rally25rs / CodeSample1.cs
Created May 10, 2011 00:27
Code Sample 1 (DynamicMethods and ILEmit)
/* ***
* This is a method from an object-relation-mapping (ORM) tool that I had started to write.
* I eventually stopped working on it, ad instead contributed time to the open source
* SubSonic project instead.
*
* This method is an example of generating DynamicMethods to be used at runtime to check and
* set some properties any an arbitrary type. This was used over straight reflection every time
* because reflection can be fairly slow. The use of a DynamicMethod is much quicker.
* *** */
@rally25rs
rally25rs / fileStorage.coffee
Created December 29, 2014 14:22
Cordova File API Wrapper
window.fileStorage =
save: (name, data) ->
deferred = $.Deferred()
fail = (error) =>
deferred.reject(error)
gotFileSystem = (fileSystem) =>
fileSystem.root.getFile(name, { create: true, exclusive: false }, gotFileEntry, fail)
@rally25rs
rally25rs / JsonEncodeAnExpandoObjectByWrappingItInADynamicJsonObject.cs
Created July 3, 2012 20:09
Serialize an ExpandoObject to a JSON string by wrapping it in a DynamicJsonObject
// By default, Json.Encode will turn an ExpandoObject into an array of items,
// because internally an ExpandoObject extends IEnumerable<KeyValuePair<string, object>>.
// You can turn it into a non-list JSON string by first wrapping it in a DynamicJsonObject.
[TestMethod]
public void JsonEncodeAnExpandoObjectByWrappingItInADynamicJsonObject()
{
dynamic expando = new ExpandoObject();
expando.Value = 10;
expando.Product = "Apples";
@rally25rs
rally25rs / HtmlHelperDisplayNameExtensions.cs
Created November 20, 2011 03:29
Extension methods for ASP.NET MVC3 that provide helpers for getting display names from IEnumerable models.
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web.Mvc;
namespace Web.Extensions
{
public static class HtmlHelperDisplayNameExtensions
{
/// <summary>
@rally25rs
rally25rs / FakeDbSet.cs
Created December 18, 2011 02:11
Fake implementation of Entity Framework IDbSet to use for unit testing.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
namespace Rally25rs.Gist.Data
{