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 / 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 / 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 / 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 / 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>

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 / 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();
/**
function getWatchers(root) {
root = angular.element(root || document.documentElement);
var watcherCount = 0;
function getElemWatchers(element) {
var isolateWatchers = getWatchersFromScope(element.data().$isolateScope);
var scopeWatchers = getWatchersFromScope(element.data().$scope);
var watchers = scopeWatchers.concat(isolateWatchers);
angular.forEach(element.children(), function (childElement) {
watchers = watchers.concat(getElemWatchers(angular.element(childElement)));
// working d. bodnar 12-21-2017
/*
static const uint8_t D0 = 16;
static const uint8_t D1 = 5;
static const uint8_t D2 = 4;
static const uint8_t D3 = 0;
static const uint8_t D4 = 2;
static const uint8_t D5 = 14;
static const uint8_t D6 = 12;
(function () {
'use strict';
// Define the dependencies within an array and have a
// separate clean function for the controller code
angular
.module('app')
.controller('MyController'[
'dependecyOne',
'dependecyTwo',
@tonyjoanes
tonyjoanes / angularjs_controllers2.js
Last active October 18, 2019 14:14
AngularJS Controllers using $inject
(function () {
'use strict';
angular
.module('app')
.controller('MyController', MyController);
MyController.$inject = ['dependencyOne', 'dependecyTwo'];
function MyController(