Skip to content

Instantly share code, notes, and snippets.

@johnmmoss
johnmmoss / gist:1531cd82b9a592aca9d5
Created April 7, 2015 19:21
PowerShell SQL script table
# The file that the script is written to
$file = "C:\scripts\ps\department.sql"
# declare variables and create path
$server = "localhost";
$instance = "default";
$database = "timesheet";
$path = "sqlserver:\sql\$server\$instance\databases\$database\tables" ;
# filter down to a particular table
@johnmmoss
johnmmoss / gist:589627f0a81b48bd8c4e
Created April 8, 2015 07:02
PowerShell Script SQL table create statements
# declare variables and create path
$server = "localhost";
$instance = "default";
$database = "timesheet";
$path = "sqlserver:\sql\$server\$instance\databases\$database\tables" ;
# We still have a filter, kind of..
$tables = "*";
# The output directory for our scripts
@johnmmoss
johnmmoss / gist:8c487b79974ee3dfbd3e
Last active August 29, 2015 14:19
ASP.NET Standard Edit Controller
// GET: /Department/Edit/5
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Department department = _context.Departments.Find(id);
if (department == null)
{
@johnmmoss
johnmmoss / gist:8ee16837513ab69de4f3
Last active June 9, 2017 03:48
ASP.NET MVC FileStreamResult Example
// /File/Stream
public FileStreamResult Stream()
{
var fileContent = new byte[] { Ascii.one, Ascii.Comma, Ascii.two, Ascii.Comma, Ascii.three };
var stream = new MemoryStream(fileContent);
var fileStreamResult = new FileStreamResult(stream, mimeType);
fileStreamResult.FileDownloadName = "FileStreamExample.csv";
return fileStreamResult;
}
@johnmmoss
johnmmoss / gist:bc134c1d59d85079f74b
Created April 20, 2015 18:49
HttpStatusCodeResult examples
public HttpStatusCodeResult Unavailable()
{
var status = HttpStatusCode.ServiceUnavailable;
var statusCode = new HttpStatusCodeResult(status);
return statusCode;
}
public HttpStatusCodeResult Found()
@johnmmoss
johnmmoss / gist:567cf474718beebba214
Created April 20, 2015 18:54
Specialized HttpStatus result classes
public HttpNotFoundResult NotFound()
{
var statusCode = new HttpNotFoundResult();
return statusCode;
}
public HttpUnauthorizedResult Unauthorized()
{
var statusCode = new HttpUnauthorizedResult();
@johnmmoss
johnmmoss / gist:0596a3e88e3f9b67d7fd
Created April 20, 2015 19:38
ASP.NET MVC Content type
public ContentResult Content()
{
var content = new ContentResult();
content.Content = "<html><body bgcolor=\"red\"><p>This is my HTML content</body></html>";
content.ContentType = "text/html";
return content;
}
@johnmmoss
johnmmoss / gist:eeedcc5f9c82502bc42e
Last active August 29, 2015 14:20
CSRF Html helper
@using (Html.BeginForm("Index", "Feedback"))
{
@Html.AntiForgeryToken()
<!-- form controls -->
}
@johnmmoss
johnmmoss / gist:be529d25125b4bd32d5c
Created May 2, 2015 14:35
CSRF Controller Attribute
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index(FeedbackModel model)
{
// Controller code
}
(function ($) {
$(document).ready(function () {
// JQuery code goes here
});
})(jQuery);