Skip to content

Instantly share code, notes, and snippets.

View johnw86's full-sized avatar

John Walker johnw86

View GitHub Profile
<ul>
<li ng-repeat="(key, errors) in editForm.$error track by $index"> <strong>{{ key }}</strong> errors
<ul>
<li ng-repeat="e in errors">{{ e.$name }} has an error: <strong>{{ key }}</strong>.</li>
</ul>
</li>
</ul>
@johnw86
johnw86 / tests.txt
Last active October 2, 2019 09:02
Writing tests
// Arrange
// Act
// Assert
Naming convention
Update nuget.exe
nuget.exe update -self
Update source credentials so you don't have to keep entering them over and over
nuget.exe sources Update||Add -Name sourceNameHere -UserName userNameHere -Password passwordHere -Source sourceUrlHere
@johnw86
johnw86 / mongo-shell.txt
Last active September 3, 2018 13:46
Mongo shell snippets
To be ran against mongo.exe
// Start up - specify db file location
"PathToMongo.exe" --dbpath C:\mongodb\data
// Connect to shell
mongo --port 27017 -u "username" -p "password" --authenticationDatabase "admin"
Option param --nodb
// Select db
@johnw86
johnw86 / cors.txt
Created October 23, 2017 09:31
Allow CORS in .net application
protected void Application_BeginRequest()
{
if (Request.Headers.AllKeys.Any(x => x.ToUpper() == "ORIGIN") && Request.HttpMethod.ToUpper() == "OPTIONS")
{
Response.Flush();
}
}
<customHeaders>
<remove name="X-Powered-By" />
@johnw86
johnw86 / Console
Created December 5, 2017 20:51
Console tips
console.table(data);
@johnw86
johnw86 / typeahead.css
Created December 12, 2017 11:39
typeahead.js basic styling
.tt-hint, .tt-input {
display: block;
width: 100%;
padding: 3px 6px;
color: #555;
vertical-align: middle;
background-color: #ffffff;
border: 1px solid #cccccc;
border-radius: 4px;
}
@johnw86
johnw86 / interface-implementation.cs
Created March 22, 2018 12:08
Use Reflection to create instance of all implementations of an interface.
var implementations = Assembly.GetExecutingAssembly().GetTypes()
.Where(x => typeof(IInterface).IsAssignableFrom(x) &&
!x.IsInterface &&
!x.IsAbstract &&
x.IsClass &&
x.IsPublic)
.Select(x => Activator.CreateInstance(x) as IInterface);
@johnw86
johnw86 / html-encode-decode.js
Created March 28, 2018 08:34
JavaScript functions to encode and decode html
function htmlEncode(html) {
return document.createElement('div').appendChild(
document.createTextNode(html)).parentNode.innerHTML;
};
function htmlDecode(html) {
var div = document.createElement('div');
div.innerHTML = html;
return div.textContent;
};
@johnw86
johnw86 / emailvalidator.cs
Created May 25, 2018 10:54
Email validator
using System;
using System.IO;
using System.Net.Mail;
namespace EmailValidator
{
class Program
{
static void Main()
{