Skip to content

Instantly share code, notes, and snippets.

View tonyjoanes's full-sized avatar
😏
LLM Learning

Tony Joanes tonyjoanes

😏
LLM Learning
View GitHub Profile
@tonyjoanes
tonyjoanes / nuget.config
Created February 16, 2016 14:26
Nuget config file to disable source control integration
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
@tonyjoanes
tonyjoanes / Levenshtein.cs
Created November 26, 2015 09:37
A couple of Levenshtein Calculations implementations. Useful for finding the distance between two strings. The distance is how many edits are required to make the strings the same
public static int Compute(string s, string t)
{
int n = s.Length;
int m = t.Length;
int[,] d = new int[n + 1, m + 1];
// Step 1
if (n == 0)
{
return m;
@tonyjoanes
tonyjoanes / GenericListToCsv.cs
Created November 25, 2015 14:31
Convert a generic list to CSV
private static string CreateCsvTextFile<T>(List<T> data)
{
var properties = typeof(T).GetProperties();
var result = new StringBuilder();
var headings = properties.Select(x => x.Name.ToString());
var headerLine = string.Join(",", headings);
result.AppendLine(headerLine);
@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;
@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 / 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 / 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 / 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 / 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 / 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)