Skip to content

Instantly share code, notes, and snippets.

View cDoru's full-sized avatar
💭
I may be slow to respond.

Doru Cioclea cDoru

💭
I may be slow to respond.
  • Cluj-Napoca
View GitHub Profile
namespace Middleware
{
public class WebApiTrace
{
public Guid Id { get; set; }
public WebApiTrace()
{
Id = Guid.NewGuid();
@cDoru
cDoru / ApplyOrdering.cs
Last active March 3, 2017 10:16
Applies order by / order by descending to an IQueryable collection knowing the string property name which we order
public static class SortUtils
{
private static readonly Type QueryableType = typeof(Queryable);
public static IOrderedQueryable<T> OrderDescending<T>(this IQueryable<T> query, string propertyName)
{
return ApplyOrdering(query, propertyName, false, true);
}
public static IOrderedQueryable<T> OrderAscending<T>(this IQueryable<T> query, string propertyName)
@cDoru
cDoru / RunHelper.cs
Last active March 24, 2017 11:29
Runs a collection of actions, logs exceptions and throws an aggregate exception (if there were any exceptions)
public class RunHelper
{
readonly bool _logError;
readonly ILog _log;
public RunHelper( ILog log )
{
_log = log;
_logError = true;
}
@cDoru
cDoru / delete-all-tables.sql
Created March 27, 2017 12:18
Small sql util script which deletes all tables from a sql database
DECLARE @Sql NVARCHAR(500) DECLARE @Cursor CURSOR
SET @Cursor = CURSOR FAST_FORWARD FOR
SELECT DISTINCT sql = 'ALTER TABLE [' + tc2.TABLE_NAME + '] DROP [' + rc1.CONSTRAINT_NAME + ']'
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc1
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc2 ON tc2.CONSTRAINT_NAME =rc1.CONSTRAINT_NAME
OPEN @Cursor FETCH NEXT FROM @Cursor INTO @Sql
WHILE (@@FETCH_STATUS = 0)
@cDoru
cDoru / missing_indexes.sql
Last active March 30, 2017 10:08
Sql query that checks missing indexes on an sql server
SELECT CAST(SERVERPROPERTY('ServerName') AS [nvarchar](256)) AS [SQLServer]
,db.[database_id] AS [DatabaseID]
,db.[name] AS [DatabaseName]
,id.[object_id] AS [ObjectID]
,id.[statement] AS [FullyQualifiedObjectName]
,id.[equality_columns] AS [EqualityColumns]
,id.[inequality_columns] AS [InEqualityColumns]
,id.[included_columns] AS [IncludedColumns]
,gs.[unique_compiles] AS [UniqueCompiles]
,gs.[user_seeks] AS [UserSeeks]
@cDoru
cDoru / missing_indexes_1.sql
Last active March 30, 2017 10:06
Alternative to finding the missing indexes
SELECT db_name(d.database_id) dbname
, object_name(d.object_id) tablename
, d.equality_columns
, d.inequality_columns
, d.included_columns
,'CREATE INDEX [missing_index_' + CONVERT (varchar, g.index_group_handle) + '_' + CONVERT (varchar, d.index_handle)
+ '_' + LEFT (PARSENAME(d.statement, 1), 32) + ']'
+ ' ON ' + d.statement
+ ' (' + ISNULL (d.equality_columns,'')
+ CASE WHEN d.equality_columns IS NOT NULL AND d.inequality_columns IS NOT NULL THEN ',' ELSE '' END
@cDoru
cDoru / FindYourMissingIndexes.sql
Created March 30, 2017 10:05
Find your missing indexes (current database)
begin try
SELECT
d.[object_id],
s = OBJECT_SCHEMA_NAME(d.[object_id]),
o = OBJECT_NAME(d.[object_id]),
d.equality_columns,
d.inequality_columns,
d.included_columns,
s.unique_compiles,
s.user_seeks, s.last_user_seek,
@cDoru
cDoru / Rfc3339DateTime.cs
Created March 30, 2017 16:02
Gist parsing datetime (rfc3339)
/// <summary>
/// Provides methods for converting <see cref="DateTime"/> structures to and from the equivalent RFC 3339 string representation.
/// </summary>
public static class Rfc3339DateTime
{
static Rfc3339DateTime()
{
Formats = new List<string>
{
@cDoru
cDoru / Database.Poco.Core.ttinclude
Created April 20, 2017 14:34
Reverse poco generator (ef code first from db). Include these files in your project, define a connectionStrings entry in your configuration file (or specify it in the database.tt) and generate your poco unit of work layer
<#
#>
<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ include file="EF6.Utility.CS.ttinclude"#>
<#@ assembly name="System.Configuration" #>
<#@ assembly name="System.Windows.Forms" #>
<#@ import namespace="System.Data" #>
<#@ import namespace="System.Data.SqlClient" #>
<#@ import namespace="System.Data.Common" #>
<#@ import namespace="System.Data.Entity.Infrastructure.Pluralization" #>
@cDoru
cDoru / WatiNHelper.cs
Created June 26, 2017 07:53 — forked from pagebrooks/WatiNHelper.cs
This helper class adds Eval so that you can obtain the result of a JavaScript function. This functionality is not native to WatiN. Forked from: http://blog.ashmind.com/2007/09/05/evaluating-javascript-in-watin
// Forked from: http://blog.ashmind.com/2007/09/05/evaluating-javascript-in-watin/
// This helper class adds Eval so that you can obtain the result of a JavaScript
// function. This functionality is not native to WatiN.
/*
* Usage:
* var browser = new IE();
* var foo = browser.NativeDocument.Eval<bool>("isFoo()");
*/