Skip to content

Instantly share code, notes, and snippets.

@dejanvasic85
dejanvasic85 / MustBeTrueAttribute
Created February 29, 2016 00:35
Custom validation attribute to ensure a checkbox is checked
/// <summary>
/// This is used on mostly checkboxes that ensure that they are ticked such as terms and conditions.
/// </summary>
public class MustBeTrueAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
if (value == null) return false;
if (value.GetType() != typeof(bool)) return false;
@dejanvasic85
dejanvasic85 / MockBuilder.cs
Created May 19, 2015 06:49
Nice builder pattern to for building mock objects using Actions
internal class MockBuilder<TBuilder, TMock>
where TBuilder : MockBuilder<TBuilder, TMock>, new()
where TMock : class, new()
{
private IList<Action<TMock>> _buildSteps;
protected MockBuilder()
{
_buildSteps = Enumerable.Empty<Action<TMock>>().ToList();
}
public static class UnityConfig
{
public static IUnityContainer RegisterComponents()
{
var container = new UnityContainer();
// Register all repository classes automatically
// Register all service classes automatically in the business layer
@dejanvasic85
dejanvasic85 / passwordModule.html
Last active August 29, 2015 14:14
Angular Password Strength Indicator
<div ng-app="passwordModule" ng-controller="credentialsController" class="container">
<form name="form">
<div class="form-group">
<label for="password">Password</label>
<input type="text" name="password" id="password" ng-model="credentials.password" ng-model-options="{allowInvalid: true}" pattern-validator="((?=.*\d)(?=.*[A-Z])(?=.*\W).{8,8})" class="form-control" />
</div>
<div class="form-group">
<label>Password Strength</label>
@dejanvasic85
dejanvasic85 / passwordModule.js
Last active August 29, 2015 14:14
Angular Strength Indicator
angular.module('passwordModule', [])
.controller('credentialsController', ['$scope',
function($scope) {
// Initialise the password as hello
$scope.credentials = {
password: 'hello'
};
}
])
.directive('passwordStrength', [