Skip to content

Instantly share code, notes, and snippets.

View tonyjoanes's full-sized avatar
🤡
Focusing

Tony Joanes tonyjoanes

🤡
Focusing
View GitHub Profile
@tonyjoanes
tonyjoanes / gist:5af399e23d10e1d2c942
Created October 10, 2014 15:15
MVC Route testing
[TestFixtureSetUp]
public void TestSetup()
{
var routes = RouteTable.Routes;
routes.Clear();
routes.MapRoute(
"Default",
"{controller}",
new {controller = "Recipe", action = "Healthy", id = ""}
@tonyjoanes
tonyjoanes / gist:d567beea64f6eb589066
Created October 10, 2014 15:21
MVC Route testing
[Test]
public void should_map_to_recipe_controller()
{
"~/Recipe".ShouldMapTo<recipecontroller>(action => action.Healthy());
}
@tonyjoanes
tonyjoanes / gist:218a79435060c706fba3
Created October 13, 2014 14:19
Logging Aspect Interceptor
public class LoggingAspect : IInterceptor
{
private readonly ILogger logger;
private readonly Stopwatch stopwatch;
public LoggingAspect(ILogger logger)
{
this.logger = logger;
this.stopwatch = new Stopwatch();
}
@tonyjoanes
tonyjoanes / DapperMap.cs
Last active August 29, 2015 14:07
Simple Dapper query and mapping
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class PersonService
{
public Person GetPerson(int id)
@tonyjoanes
tonyjoanes / ldap querying
Created April 29, 2015 12:45
using php_ldap extensions to query an Active Directory
<?php
function get_groups($user) {
// Active Directory server
$ldap_host = "ad.domain";
// Active Directory DN, base path for our querying user
$ldap_dn = "CN=Users,DC=ad,DC=domain";
// Active Directory user for querying
$query_user = "jane@".$ldap_host;
@tonyjoanes
tonyjoanes / AutofacBoot.cs
Last active October 21, 2015 08:37
Autofac convention based registration
private void BootAutoFac()
{
var builder = new ContainerBuilder();
var assemblies = AppDomain.CurrentDomain.GetAssemblies()
.Where(x => x.FullName.StartsWith("Your.Namespace")).ToArray();
builder.RegisterAssemblyTypes(assemblies)
.Where(t => t.IsClass)
@tonyjoanes
tonyjoanes / tablecolumnname.sql
Created October 28, 2015 10:50
Find tables with a column of particular name MSSQL
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%name of column%'
ORDER BY schema_name, table_name;
@tonyjoanes
tonyjoanes / AuthorisedADAttribute.cs
Last active November 6, 2015 13:13
Custom authorize filter for restricting access based on group
public class AuthoriseAdAttribute : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
var groupList = GetGroupList();
if (base.AuthorizeCore(httpContext))
{
if (string.IsNullOrEmpty(groupList))
return true;
@tonyjoanes
tonyjoanes / home.controller.tests.js
Created November 13, 2015 16:07
Jasmine sample controller test spec
/// <reference path="../MvcAngularJasmineTests/Scripts/angular.js"/>
/// <reference path="../MvcAngularJasmineTests/Scripts/angular-route.js"/>
/// <reference path="Scripts/angular-mocks.js"/>
/// <reference path="../MvcAngularJasmineTests/Scripts/app/app.js"/>
/// <reference path="../MvcAngularJasmineTests/Scripts/home/home.controller.js"/>
/// <reference path="Scripts/jasmine/jasmine.js"/>
describe('When working with the home.controller', function () {
@tonyjoanes
tonyjoanes / home.controller.js
Created November 13, 2015 16:12
Extremely simple angular controller
(function () {
'use strict';
angular
.module('SampleApp')
.controller('HomeController', HomeController);
function HomeController() {
var vm = this;