Skip to content

Instantly share code, notes, and snippets.

View leandrocustodio's full-sized avatar

Leandro Custodio leandrocustodio

  • TheoremOne
  • Brazil
View GitHub Profile
@leandrocustodio
leandrocustodio / NoCacheAttribute.cs
Created January 10, 2018 12:44
Avoid cache in user browser, this way when user click in back button the page will reload
public class NoCacheAttribute : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
filterContext.HttpContext.Response.Cache.SetNoStore();
@leandrocustodio
leandrocustodio / DropAll.SQL
Created May 4, 2017 11:56
Drop all views, procedures and tables on SQL Server
/* Drop all non-system stored procs */
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)
SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 ORDER BY [name])
WHILE @name is not null
BEGIN
SELECT @SQL = 'DROP PROCEDURE [dbo].[' + RTRIM(@name) +']'
EXEC (@SQL)
@leandrocustodio
leandrocustodio / placeholder.less
Created April 18, 2017 16:42
Mixin: Customize placeholder with less
.placeholder(@rules){
&::-webkit-input-placeholder{
@rules();
}
&:-moz-placeholder{
@rules();
}
&::-moz-placeholder{
@leandrocustodio
leandrocustodio / Contexto.cs
Last active April 4, 2017 12:24
Override entity framework savechanges method to automatically set include and modified dates
public override int SaveChanges()
{
//verificar adiciona a data atual em todos os elementos que forem adicionados no banco
foreach (var entry in ChangeTracker.Entries().Where(entry => entry.Entity.GetType().GetProperty("DataInclusao") != null))
{
if (entry.State == EntityState.Added)
{
entry.Property("DateCreated").CurrentValue = DateTime.Now;
}
else if (entry.State == EntityState.Modified)
@leandrocustodio
leandrocustodio / Web.config
Created April 3, 2017 17:17
Use web.config to redirect user to a HTTPS connection
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
@leandrocustodio
leandrocustodio / Email.cs
Created April 3, 2014 12:45
enviar e-mail com c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Net.Mail;
namespace Utilities
{
public static class Email
@leandrocustodio
leandrocustodio / app.cs
Created August 13, 2013 18:37
Header to Force Download witch C#
Response.AppendHeader("Content-Type", "application/force-download;");
Response.AppendHeader("Content-Disposition", "attachment; filename="+ FileName);
@leandrocustodio
leandrocustodio / mascara_telefone.js
Created August 7, 2013 11:56
Mascara de telefone com 9 digitos
$("#CidadeTelefone").keyup(function(){
var tel = $(this).val();
phone = tel.replace(/\D/g, '');
element = $(this);
element.unsetMask();
if(phone.length > 10) {
element.setMask("(99) 99999-9999");
} else {
element.setMask("(99) 9999-99999");
}
#region License
/* Copyright (C) 2009 Tim Coulter
*
* This file is part of ExtremeML.
*
* ExtremeML is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation either version
* 2 of the License, or (at your option) any later version.
*
@leandrocustodio
leandrocustodio / ContextHeader.cs
Created June 28, 2013 16:21
Confirgurações do HttpContext para gerar um arquivo do Excel
HttpContext.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Response.AddHeader("content-disposition", "attachment;filename=exportar.xls");
HttpContext.Response.Charset = "utf-8";
HttpContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");