Skip to content

Instantly share code, notes, and snippets.

View lfreneda's full-sized avatar
💙
Always deliver more than expected.

Luiz Freneda lfreneda

💙
Always deliver more than expected.
View GitHub Profile
@lfreneda
lfreneda / routes route parameters mvc contrib action post get
Created November 12, 2012 13:45
Extensions methods for testing routes - extending mvc contrib
public static class MVCTestExtensions {
public static RouteData WithParameters(this RouteData route, object parameters) {
foreach (var property in parameters.GetType().GetProperties()) {
var value = property.GetValue(parameters, null);
route.Values[property.Name] = value;
}
return route;
}
@lfreneda
lfreneda / closing browser window without confirmation dialog
Created November 26, 2012 13:20
javascript close window browser noconfirmation noalert
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Operação completa</title>
<script language="javascript" type="text/javascript">
function closeWindow() {
window.open('', '_self', '');
window.close();
}
</script>
@lfreneda
lfreneda / Elmah report over asp.net mvc
Created November 26, 2012 13:28
elmah filter user controller asp.net mvc adm report
public class ElmahUsersAttribute : ActionMethodSelectorAttribute {
public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) {
//validate current user ~ true or false?
}
}
public class ElmahController : Controller {
[ElmahUsers]public ActionResult Index() { return new ElmahResult(); }
[ElmahUsers]public ActionResult Stylesheet() { return new ElmahResult("stylesheet"); }
[ElmahUsers]public ActionResult Rss() { return new ElmahResult("rss"); }
@lfreneda
lfreneda / data tools
Created December 10, 2012 13:40
sql insert generation tool sqlserver data database migration script
"C:\Program Files (x86)\Microsoft SQL Server\90\Tools\Publishing\1.4\SqlPubWiz.exe"
@lfreneda
lfreneda / Mock comparation using Moq and MagicMoq
Created December 18, 2012 18:39
comparation using MagicMoq ~
//using Moq as usual
[Test]
public void EditItem_Post_WhenModelIsValid_ShouldRedirectToIndex() {
//Arrange
var shoppingCartStub = new Mock<IShoppingCartService>();
shoppingCartStub.Setup(c => c.Change(It.IsAny<Guid>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<string>()));
var wcfServiceFactoryStub = new Mock<IWCFServiceFactory>();
var controller = new BasketController(shoppingCartStub.Object, wcfServiceFactoryStub.Object);
[TestFixture]
public class EncryptingDecryptingTests {
static byte[] GetBytes(string str) {
byte[] bytes = new byte[str.Length * sizeof(char)];
System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
return bytes;
}
static string GetString(byte[] bytes) {
@lfreneda
lfreneda / gist:4740186
Created February 8, 2013 16:37
getting branch name on post-receive :) git post receive hudson url branch name branch current
if ! [ -t 0 ]; then
read -a ref
fi
IFS='/' read -ra REF <<< "${ref[2]}"
branch="${REF[2]}"
if [ "lfreneda_novo_b2c" == "$branch" ]; then
URL='http://10.30.0.51:8081/job/dev.ecommerce.newb2c/build?delay=0sec'
wget.exe $URL
fi
@lfreneda
lfreneda / gist:5134190
Created March 11, 2013 13:25
FilterAttibutes nocache asp.net mvc
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();
base.OnResultExecuting(filterContext);
}
}
@lfreneda
lfreneda / gist:5356481
Last active December 16, 2015 01:39
all.js plugin widget jsonp
(function () {
var jQuery;
// If not present, load jquery
if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.4.2') {
createScriptReference("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", function () {
// Restore $ and window.jQuery to their previous values and store the
// new jQuery in our local jQuery variable
jQuery = window.jQuery.noConflict(true);
main();
});
@lfreneda
lfreneda / gist:5533177
Created May 7, 2013 14:49
bcp utility extract table to file sql server
bcp "SELECT Line from db_WF_Log.dbo.tbLogs where Type = 'anticheat_report' and Processed = 0" queryout 'C:\temp\queryout.txt' -c -t, -S 10.30.0.51,1220 -T