Skip to content

Instantly share code, notes, and snippets.

View forcewake's full-sized avatar

Pavel Nasovich forcewake

View GitHub Profile
namespace Framework.Jobs.Arguments
{
using System;
using System.Linq.Expressions;
public static class StaticReflection
{
public static string GetMemberName<T>(
this T instance,
Expression<Func<T, object>> expression)
@forcewake
forcewake / find_column_by_value.sql
Created July 9, 2014 13:02
Find column by value. OMG
DECLARE @SearchStr nvarchar(100)
SET @SearchStr = '1102449'
-- Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.
-- Purpose: To search all columns of all tables for a given search string
-- Written by: Narayana Vyas Kondreddi
-- Site: http://vyaskn.tripod.com
-- Updated and tested by Tim Gaunt
-- http://www.thesitedoctor.co.uk
@forcewake
forcewake / table_to_class.sql
Created July 9, 2014 13:05
Create class from table
DECLARE @TableName VARCHAR(MAX) = 'NewsItem'
DECLARE @TableSchema VARCHAR(MAX) = 'Markets'
DECLARE @result varchar(max) = ''
SET @result = @result + 'using System;' + CHAR(13) + CHAR(13)
IF (@TableSchema IS NOT NULL)
BEGIN
SET @result = @result + 'namespace ' + @TableSchema + CHAR(13) + '{' + CHAR(13)
END
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Interview Questions</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
// Need to go direct to the registry as the EventLog.CreateEventSource
// method cycles through all logs, including the Security log, to
// verify that the source does not exist and is unique
try
{
var logKeyName = String.Format(CultureInfo.InvariantCulture, @"SYSTEM\CurrentControlSet\Services\EventLog\{0}", log);
var sourceKeyName = String.Format(CultureInfo.InvariantCulture, @"SYSTEM\CurrentControlSet\Services\EventLog\{0}\{1}", log, source);
using (Registry.LocalMachine.OpenSubKey(logKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree) ??
Registry.LocalMachine.CreateSubKey(logKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree))
using (var sourceKey = Registry.LocalMachine.OpenSubKey(sourceKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree) ??
@forcewake
forcewake / Mapper.cs
Created August 1, 2014 06:39
Light mapper instead of AutoMapper
public static class QueryableExtensions
{
public static ProjectionExpression<TSource> Project<TSource>(this IQueryable<TSource> source)
{
return new ProjectionExpression<TSource>(source);
}
}
public class ProjectionExpression<TSource>
{
using System;
using System.Linq.Expressions;
class Test
{
// This is the method you want, I think
static Expression<Func<TInput,object>> AddBox<TInput, TOutput>
(Expression<Func<TInput, TOutput>> expression)
{
// Add the boxing operation, but get a weakly typed expression
# PowerShell script that recursively deletes all 'bin' and 'obj' (or any other specified) folders inside current folder
$CurrentPath = (Get-Location -PSProvider FileSystem).ProviderPath
# recursively get all folders matching given includes, except ignored folders
$FoldersToRemove = Get-ChildItem .\ -include bin,obj -Recurse | where {$_ -notmatch '_tools' -and $_ -notmatch '_build'} | foreach {$_.fullname}
# recursively get all folders matching given includes
$AllFolders = Get-ChildItem .\ -include bin,obj -Recurse | foreach {$_.fullname}
namespace System
{
using System.Collections.Generic;
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
public class Switch<T>
{
[
{
"title": "Design patterns and practices in .NET: the Adapter Pattern",
"link": "http://dotnetcodr.com/2013/04/25/design-patterns-and-practices-in-net-the-adapter-pattern/"
},
{
"title": "Design patterns and practices in .NET: the Strategy Pattern",
"link": "http://dotnetcodr.com/2013/04/29/design-patterns-and-practices-in-net-the-strategy-pattern/"
},
{