Skip to content

Instantly share code, notes, and snippets.

View odytrice's full-sized avatar

Ody Mbegbu odytrice

View GitHub Profile
@odytrice
odytrice / p4merge-git-tool.md
Last active September 12, 2017 11:02 — forked from dgoguerra/p4merge-git-tool.md
Setup p4merge as difftool and mergetool on Windows

P4Merge Windows Configuration

Setting up p4merge as diff and merge tool on Windows. Tried for Git version 1.8.4.msysgit.0.

Two alternatives are explained: using the command line, and directly editing the config file.

Setting up from the command line

Being the installation path "C:Program Files\Perforce\p4merge.exe", just run:

@odytrice
odytrice / ExcelProcessor.cs
Last active September 28, 2019 07:37
Excel Processor using EPPlus Nuget Package
public class ExcelProcessor
{
public Stream Generate<T>(Dictionary<string, IEnumerable<T>> Sheets)
{
//Generate Excel Workbook in Memory
using (var excel = new ExcelPackage())
{
if (Sheets.Any() == false) throw new Exception("No Sheets were supplied");
foreach (var pair in Sheets)
@odytrice
odytrice / Extensions.cs
Last active September 28, 2019 07:37
Generic Abstract Model
public static class Extensions
{
public static T ParseEnum<T>(this string value) where T : struct
{
if (Enum.TryParse(value, true, out T enumobj))
{
return enumobj;
}
else
{
@odytrice
odytrice / AuthorizeUser.cs
Created January 1, 2017 19:07
Authorize Attribute based on Permissions
public class AuthorizeUserAttribute: AuthorizeAttribute
{
private string[] _permissions;
private IUserManager _user;
public AuthorizeUserAttribute(params string[] permissions)
{
_permissions = permissions;
_user = NinjectContainer.Resolve<IUserManager>();
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
@odytrice
odytrice / AssignExtension.cs
Last active July 27, 2018 10:10
Extension Method to Assign Object properties in an Optimistic way
public static class Extensions
{
[DebuggerStepThrough]
/// <summary>
/// Update properties with properties of the object Supplied (typically anonymous)
/// </summary>
/// <typeparam name="T">Type of Source Object</typeparam>
/// <param name="destination">Object whose property you want to update</param>
/// <param name="source">destination object (typically anonymous) you want to take values from</param>
/// <returns>Update reference to same Object</returns>
@odytrice
odytrice / TestBindings.cs
Created January 1, 2017 17:23
Tests Ninject Bindings in an Automated Way
namespace Application.Tests
{
[TestClass]
public class BindingsTest
{
[TestMethod]
public void TestBindings()
{
//Create Kernel and Load Assembly Application.Web
seq {
for i in 1..10 do
for j in 10..15 do
yield i * j
}
@odytrice
odytrice / FluentMigratorAddOrUpdate.fs
Created November 2, 2016 10:08
Merge Command For Fluent Migrator written in F#
namespace FluentMigrator.Extensions
open FluentMigrator.Expressions
open FluentMigrator.Infrastructure
open System
open System.Collections.Generic
open System.Linq
open FluentMigrator
open FluentMigrator.Model
open System.Data
@odytrice
odytrice / SampleMigration.fs
Last active October 14, 2016 18:10
Sample EF Core Migration
namespace MyAPI.Migrations
open System
open System.Collections.Generic
open Microsoft.EntityFrameworkCore
open Microsoft.EntityFrameworkCore.Migrations
open Microsoft.EntityFrameworkCore.Metadata
open Microsoft.EntityFrameworkCore.Infrastructure
open Microsoft.EntityFrameworkCore.Migrations.Operations
open Microsoft.EntityFrameworkCore.Migrations.Operations.Builders
@odytrice
odytrice / Sql Server Kill Processes.sql
Last active October 18, 2018 05:19
Troubleshooting SQL Server
# DANGER - Kills all processes for a specific database
-- DECLARE @SQL varchar(max);
-- SELECT @SQL = COALESCE(@SQL,'') + 'Kill ' + Convert(varchar, r.session_id) + ';' from sys.dm_exec_requests r left join sys.dm_os_waiting_tasks t
-- on r.session_id = t.session_id where r.session_id >= 50 and r.session_id <> @@spid
-- EXEC(@SQL)