Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Ody Mbegbu odytrice

🏠
Working from home
Block or report user

Report or block odytrice

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@odytrice
odytrice / AuthorizeUser.cs
Created Jan 1, 2017
Authorize Attribute based on Permissions
View AuthorizeUser.cs
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 Jul 27, 2018
Extension Method to Assign Object properties in an Optimistic way
View AssignExtension.cs
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 Jan 1, 2017
Tests Ninject Bindings in an Automated Way
View TestBindings.cs
namespace Application.Tests
{
[TestClass]
public class BindingsTest
{
[TestMethod]
public void TestBindings()
{
//Create Kernel and Load Assembly Application.Web
View Monads-ComputationExpression.fs
seq {
for i in 1..10 do
for j in 10..15 do
yield i * j
}
@odytrice
odytrice / FluentMigratorAddOrUpdate.fs
Created Nov 2, 2016
Merge Command For Fluent Migrator written in F#
View FluentMigratorAddOrUpdate.fs
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 Oct 14, 2016
Sample EF Core Migration
View SampleMigration.fs
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 Oct 18, 2018
Troubleshooting SQL Server
View Sql Server Kill Processes.sql
# 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)
@odytrice
odytrice / objects-closures.ts
Created Aug 13, 2016
This shows the relationship between Objects and Closures
View objects-closures.ts
//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 Aug 3, 2016
Angular Typescript Directives and Utilities
View angular-paging.ts
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 Aug 2, 2016
Angular Typescript Directives and Utilities
View directives.ts
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;
You can’t perform that action at this time.