Skip to content

Instantly share code, notes, and snippets.

View NDiiong's full-sized avatar
😀
Hi there!

duong.nb NDiiong

😀
Hi there!
View GitHub Profile
@NDiiong
NDiiong / bootstrap-button-toggle-on-off-switch.markdown
Created June 23, 2019 04:18
Bootstrap Button Toggle (On/Off Switch)

Bootstrap Button Toggle (On/Off Switch)

Working on a client project that will be using Bootstrap, and needed to build a toggle/switch that came in a couple different sizes. I wasn't seeing that as a built-in option within Bootstrap, and I didn't really like the ones already out there that I found from a quick search (I didn't want to use a plugin, just wanted it to utilize Bootstrap's built-in JS), so I decided to make my own.

This example is just using the default "Quick Add" Bootstrap CSS & JS, no added/custom JS on my part, I've simply utilized Bootstrap's buttons.js Single Toggle method (http://getbootstrap.com/javascript/#buttons) and added some custom styling (LESS).

A Pen by Aanjulena Sweet on CodePen.

License.

@NDiiong
NDiiong / ObjectValidator.cs
Created June 24, 2020 16:04 — forked from mainettis/ObjectValidator.cs
Simple Generic Object Validation as based on solution found here: https://codereview.stackexchange.com/questions/178106/simple-object-validator
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq.Expressions;
// I loved this when I found here: https://codereview.stackexchange.com/questions/178106/simple-object-validator
namespace Tools.Validate.Objects // could be something else
{
public class Validation
{
class Program
{
static void Main(string[] args)
{
var model = new Test() { };
var validator = new Validator<Test>();
var result = new Validator<Test>()
.AddRule(t => t.Name, new ValidatorNameRule())
.Validate(model);
public interface IValidator<in T> {
}
public class CompositeValidator<T> : IValidator<T> {
public CompositeValidator(params IValidator<T>[] validators) {
}
}
@NDiiong
NDiiong / IValidator.cs
Created June 24, 2020 16:41 — forked from ardacetinkaya/IValidator.cs
An easy Validation pattern implementation for any kind of application...
//Generic interface for Validators
public interface IValidator<T>
{
IEnumerable<ValidationResult> Validate(T businessEntity);
}
@NDiiong
NDiiong / Validation.cs
Created June 24, 2020 16:44 — forked from saberone/Validation.cs
A Quick hack for a simple validation using yield. The idea is to create a very clean api/interface. Some Unit tests are included, but they are far from thorough.
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web.Configuration;
using System.Web.Security;
namespace Validation
{
public interface IValidator <T>
{
public class ValidatorHandler<TRequest, TResponse>
: IRequestHandler<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
private readonly IRequestHandler<TRequest, TResponse> _inner;
private readonly IValidator<TRequest> _validator;
public ValidatorHandler(IRequestHandler<TRequest, TResponse> inner,
public class RegsiterCommandValidator : IValidator<RegisterCommand>
{
private readonly IValidationResult _validationResult;
private readonly IDbContext _context;
public RegsiterCommandValidator(IValidationResult validationResult, IDbContext context)
{
_validationResult = validationResult;
_context = context;
}
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System.Text;
using System.Threading.Tasks;
namespace WebApp
{
public class ShowAllServicesMiddleware
@NDiiong
NDiiong / Validation.cs
Last active July 16, 2020 02:54
Validation expression by properties.
public class ValidationError
{
public string Message { get; set; }
public int StatusCode { get; set; }
}
public interface IValidator<TInstance> where TInstance : class