Skip to content

Instantly share code, notes, and snippets.

View odytrice's full-sized avatar

Ody Mbegbu odytrice

View GitHub Profile
@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 / 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 / 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 / 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
seq {
for i in 1..10 do
for j in 10..15 do
yield i * j
}
@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
@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 / 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 / Paging.cs
Last active December 11, 2017 13:10
ASP.NET MVC Paging Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace System.Web.Mvc
{
@odytrice
odytrice / migrate.bat
Last active March 28, 2018 10:58
Migration File for Fluent Migrator for F# projects
REM Migrate Database
packages\FluentMigrator\tools\Migrate.exe --db=sqlserver --target=Dumia.Migrations\bin\Debug\Dumia.Migrations.dll --configPath=Dumia.Http\web.config --c=Dumia %*
REM Update Database DBML file
.\utils\SqlMetal.exe /server:"(local)" /database:dumia /user:admin1 /password:admin1 /dbml:"Dumia.Infrastructure/Database.dbml"