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 / 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 / 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 / DataRepository.cs
Last active October 26, 2016 10:57
A Generic DataRepository Class that Abstracts the DbContext
public class DataRepository : IDataRepository
{
private DbContext _dbContext;
public DataRepository(DbContext context)
{
_dbContext = context;
}
public IQueryable<T> Query<T>() where T : class
@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 / objects-closures.ts
Created August 13, 2016 17:25
This shows the relationship between Objects and Closures
//External state
let z = 5;
//this closure implicitly contains the value of z
let closure = function(x){
return x + z;
}
//The above loosely translates to..
class ObjectClosure{
@odytrice
odytrice / angular-paging.ts
Last active August 3, 2016 12:50
Angular Typescript Directives and Utilities
module App {
export class PagedList<T>{
private page: number;
private list: IList<T>;
private items: T[];
private itemsPerPage: number;
private numOfPages: number;
private count: number;
constructor(list: IList<T>, itemsPerPage = 10) {
@odytrice
odytrice / directives.ts
Created August 2, 2016 10:22
Angular Typescript Directives and Utilities
module App.Directives {
var Directive = function (): ng.IDirective {
return {
restrict: "A",
scope: {
location: "@navigate"
},
link: function (scope: any, el, attrs) {
el.click(function () {
document.location.href = scope.location;