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 / AngularJS_Chrome_Snippets.js
Created September 26, 2018 09:45
Chrome Snippets for AngularJS
/**
* Setup the angular injector so we can get instances
* of angular objects
* Usage: injector.get('dataContext');
*/
var injector = angular
.element(document.body)
.injector();
/**

ObjectCalisthenicsKata1

Coding kata using object calisthenics rules

  • Only One Level Of Indentation Per Method
  • Don't Use The ELSE Keyword
  • Wrap All Primitives And Strings
  • First Class Collections
  • One Dot Per Line
  • Don't Abbreviate
  • Keep All Entities Small
@tonyjoanes
tonyjoanes / build.proj
Created February 16, 2016 14:28
Build file that points to Nuget.exe and performs a restore
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutDir Condition=" '$(OutDir)'=='' ">$(MSBuildThisFileDirectory)bin\</OutDir>
<Configuration Condition=" '$(Configuration)'=='' ">Release</Configuration>
<SourceHome Condition=" '$(SourceHome)'=='' ">$(MSBuildThisFileDirectory)</SourceHome>
<ToolsHome Condition=" '$(ToolsHome)'=='' ">$(MSBuildThisFileDirectory)tools\</ToolsHome>
@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;