Skip to content

Instantly share code, notes, and snippets.

View ajai8085's full-sized avatar
🎯
Focusing

Ajai ajai8085

🎯
Focusing
View GitHub Profile
@ajai8085
ajai8085 / DapperExtensions.cs
Last active November 20, 2015 00:24
Prepare dynamic parameters for dapper on the fly , use parameter name as expressions to retrieve the values etc .
static public class DapperExtensions
{
public static MemberInfo GetMemberInfo(this Expression expression)
{
LambdaExpression lambdaExpression = (LambdaExpression)expression;
MemberExpression memberExpression;
if (lambdaExpression.Body is UnaryExpression)
{
@ajai8085
ajai8085 / Msmq
Created December 9, 2015 03:45
Msmq Test (Normal, Transactional, Pub-Subscriber Sample
using System;
using System.Messaging;
namespace TestTransactionalQueue
{
class Program
{
private static MessageQueue GetQueue(bool trans=true ,string path = @".\Private$\TestTran")
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
namespace WpfApplication1
{
public class AsyncObservableCollection<T> : ObservableCollection<T>
{
private readonly SynchronizationContext _synchronizationContext = SynchronizationContext.Current;
@ajai8085
ajai8085 / AutomapperConfigurationProfile.cs
Created April 12, 2016 05:34
Automapper 4.2 and Autofac Setup
internal class AutomapperConfigurationProfile : Profile
{
protected override void Configure()
{
CreateMap<Source,Destination>().ForMember(dest=>dest.Field1,opts=> opts.MapFrom(src=>(int)src.Fieldxx));
CreateMap<Abc,Xyz>().ReverseMap();
...
Mapping here
}
public static class DynamicColorGenExtensions
{
//Find foreground color for a dynamic background color
public static Color FindForgroundColor(this Color color)
{
if (color.R <= 5 && color.G <= 5 && color.B <= 5)
{
return Color.WhiteSmoke;
}
@ajai8085
ajai8085 / make-keys.bat
Created November 22, 2016 23:55 — forked from codingoutloud/make-keys.bat
Handy OpenSSL command-line combinations I've used - they might've been hard to find or come up with, so capturing them here.
@echo off
if _%1_==__ goto USAGE
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem -subj "/CN=My Cert Name"
openssl pkcs12 -export -out mycert.pfx -inkey mycert.pem -in mycert.pem -passout pass:%1
openssl x509 -inform pem -in mycert.pem -outform der -out mycert.cer
openssl pkcs12 -in mycert.pfx -nodes -passin pass:%1 | openssl x509 -noout -fingerprint
openssl x509 -in mycert.pem -noout -fingerprint
@ajai8085
ajai8085 / ObjectExtensions.cs
Created January 23, 2017 21:34
Shallow Copy public properties between unrelated objects which has same property name , this can also copy the fields from derived class to base class and maintain a pure base class object . (useful when passing parameter to dapper)
public static void CopyMatchingProperties<TResult, TInput>(this TInput input, TResult result)
where TResult : class
where TInput : class
{
var properties = typeof(TResult).GetProperties(BindingFlags.Instance | BindingFlags.Public).ToList();
var propertiesInput = typeof(TInput).GetProperties(BindingFlags.Instance | BindingFlags.Public).ToList();
properties.ForEach(p =>
{
declare @dbName varchar(100)
set @dbName ='MyDatabase'
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = @dbName)
BEGIN
declare @liveConnections as Table(Id int identity(1,1), name varchar(max), spid int )
@ajai8085
ajai8085 / AssemblyExtensions.cs
Created February 16, 2017 23:32
Get all instances of custom attribute defined only for classes with allowmultiple=false , useful when using FluentMigrator
public static class AssemblyExtensions{
public static List<TCustomAttribute> GetAllCustomAttributeInstances<TCustomAttribute>(this Assembly assembly)
where TCustomAttribute : Attribute
{
var supportedMigrationVersions = assembly
.GetTypes()
.Where(t => Attribute.IsDefined(t, typeof(TCustomAttribute)))
.Select(t => (t.GetCustomAttribute(typeof(TCustomAttribute)) as TCustomAttribute))
.ToList();
@ajai8085
ajai8085 / ArrowWithPath.xaml
Created May 5, 2017 03:30
WPF Path to draw Arrow left right top bottom
<Window x:Class="WpfApplication6.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<StackPanel>
<Path Fill="Black" Data="M 0 10 L 20 10 L 10 0 Z"/>
<Path Fill="Black" Data="M 0 0 L 10 10 L 20 0 Z"/>