Skip to content

Instantly share code, notes, and snippets.

View EfrainReyes's full-sized avatar

Efrain Reyes EfrainReyes

View GitHub Profile
using StringHelpers;
using NUnit.Framework;
namespace olakease.Tests {
[TestFixture]
public class SuperTest {
[Test]
public void NullObjectShouldNotThrowException() {
object obj = null;
public class CurrentUser : ICurrentUser {
private readonly IIdentity _identity;
private readonly HttpSessionStateBase _session;
private readonly UserInfoService _service;
private IUserInfo _user;
public CurrentUser(IIdentity identity, HttpSessionStateBase session, UserInfoService service) {
_identity = identity;
_session = session;
public class FormsAuthenticationService : IFormsAuthenticationService
{
private readonly HttpContextBase _context;
public FormsAuthenticationService(HttpContextBase context) {
_context = context;
}
public void SignIn(string userName, bool createPersistentCookie, IEnumerable<string> roles = null) {
string roleList = string.Empty;
@EfrainReyes
EfrainReyes / ValidateAjaxAttribute.cs
Last active October 23, 2015 19:28
Use MVC's model state on Ajax forms, provided that there's some client-side code to capture the validation output
/// <summary>
/// http://stackoverflow.com/questions/14005773/use-asp-net-mvc-validation-with-jquery-ajax
/// </summary>
public class ValidateAjaxAttribute : ActionFilterAttribute, IExceptionFilter
{
public override void OnActionExecuting(ActionExecutingContext filterContext) {
if(!filterContext.HttpContext.Request.IsAjaxRequest()) {
return;
}
public class ModelStateValidationAttribute : ActionFilterAttribute, IExceptionFilter
{
public override void OnActionExecuting(ActionExecutingContext filterContext) {
if(filterContext.HttpContext.Request.IsAjaxRequest())
return;
var modelIsValid = filterContext.Controller.ViewData.ModelState.IsValid;
if(!modelIsValid) {
filterContext.Result = new ViewResult() {
@EfrainReyes
EfrainReyes / MvcRegistry.cs
Created November 28, 2014 03:20
With this StructureMap Registry you can inject static and global objects like HttpContext and Session into your MVC controllers and any other helper classes you may have. Taken from Matt Honeycutt's pluralsight course on Building your own Application Framework
public class MvcRegistry : Registry
{
public MvcRegistry() {
For<BundleCollection>().Use(BundleTable.Bundles);
For<RouteCollection>().Use(RouteTable.Routes);
For<IIdentity>().Use(() => HttpContext.Current.User.Identity);
For<HttpSessionStateBase>()
.Use(() => new HttpSessionStateWrapper(HttpContext.Current.Session));
For<HttpContextBase>()
.Use(() => new HttpContextWrapper(HttpContext.Current));
@EfrainReyes
EfrainReyes / FizzBuzz.cs
Created November 28, 2014 13:42
Fizz Buzz using functional C#
Enumerable.Range(1, 30).Select(num =>
((Func<string[], string>)
(buzz => new string[]{
buzz[((num + 2) % 3) / 2] +
buzz[((num + 4) % 5) / 4 * 2],
""+num
}.First(r => r != "")))(new[] { null, "fizz", "buzz"})
).ToList().ForEach(s => Console.WriteLine(s));
@EfrainReyes
EfrainReyes / CustomerModel.cs
Last active August 29, 2015 14:11
Using INotifyPropertyChanged without having to pass the property name or an expression. Running Example: https://dotnetfiddle.net/4P0dhM
public class CustomerModel : ModelBase {
private string _customerName;
public string CustomerName {
get { return _customerName; }
set { SetProperty(ref _customerName, value); }
}
private int _orderCount;
public int OrderCount {
get { return _orderCount; }
@EfrainReyes
EfrainReyes / .gitconfig
Last active March 29, 2017 23:54
my global git config
#[user]
# name = Your Name
# email = youremail@example.com
[core]
autocrlf = true
excludesfile = C:\\Users\\Efrain\\Documents\\gitignore_global.txt
editor = 'C:/Program Files/Sublime Text 3/subl.exe' -n -w
ignorecase = false
[push]
default = simple
@EfrainReyes
EfrainReyes / make_the_string_great.py
Last active November 8, 2022 04:28
1544. Make The String Great
class Solution:
def makeGood(self, s: str) -> str:
if len(s) <= 1:
return s
stack = []
for char in s:
if (stack and stack[-1] != char
and stack[-1].lower() == char.lower()):