Skip to content

Instantly share code, notes, and snippets.

View RyannosaurusRex's full-sized avatar

Ryan Hayes RyannosaurusRex

View GitHub Profile
@RyannosaurusRex
RyannosaurusRex / gist:3161385
Created July 22, 2012 23:30
Demonstrates JavaScript to click a send button on Enter keypress. Typical use case is a chat application where you want to auto-send when you hit Enter.
$("#textboxId").keyup(function (event) {
if (event.keyCode == 13) {
$("#sendId").click();
}
});
@RyannosaurusRex
RyannosaurusRex / ServiceDefinition.csdef
Last active October 8, 2015 01:58
Disable timeout of IIS on an Azure web role.
<!-- This is added under your WebRole section. The commandline should be the path to the file, which starts at the root of the project that is your WebRole. -->
<Startup>
<Task commandLine="startup\disableTimeout.cmd" executionContext="elevated" taskType="background"/>
</Startup>
@RyannosaurusRex
RyannosaurusRex / Error.cshtml
Created August 5, 2012 22:25
ASP.NET MVC adding error information to your error page for easier debugging during development.
@model System.Web.Mvc.HandleErrorInfo
@{
ViewBag.Title = "Error";
}
<h2>
Sorry, an error occurred while processing your request.
</h2>
@RyannosaurusRex
RyannosaurusRex / RouteConfig.cs
Last active January 19, 2018 02:18
ASP.NET MVC Subdomain Routing
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Sub", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "SubdomainController", action = "AnyActionYouLike", id = UrlParameter.Optional },
@RyannosaurusRex
RyannosaurusRex / index.cshtml
Created August 6, 2013 01:29
Html.BeginForm will cause unwanted breaking of styling on most pages, particularly if you're placing it in a nav or similar area. This gist demonstrates how to move the Logout link, which in the ASP.NET MVC starter project is implemented using a form, to somewhere else on the page. We then fire it using some javascript in a link somewhere else o…
<!--
This javascript code will find the logout form on your page and do the submit.
We do this separation so we can have total control over styling.
-->
<a href="javascript:document.getElementById('logoutForm').submit()">Logout!</a>
<!--
Put this form anywhere you want outside your content area so styling isn't jacked up.
-->
@using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-form pull-right" }))
@RyannosaurusRex
RyannosaurusRex / Javascript Notify
Created January 15, 2014 14:22
Notify a user who has minimized a window when a message or event has arrived. The blur/focus is to ensure that the javascript message is not fired when a user is on the screen, to minimize annoyances of closing the popup window.
var inFocus = true;
$(window).blur(function(){
inFocus = false;
});
$(window).focus(function(){
inFocus = true;
});
setTimeout(function(){
if (!inFocus) {
@RyannosaurusRex
RyannosaurusRex / Ember in ASP.NET MVC.md
Last active August 10, 2023 04:17
Adding an EmberJS app to an ASP.NET MVC app

How to set up an Ember app inside of an ASP.NET MVC app.

I love Ember. It helps me build fantastic UIs, but security isn't super straightforward and I suck at it. I love ASP.NET MVC. It help me build secure applications and solid APIs, but for some apps I need a great responsive UI with great interaction.

Together, these two technologies can be used together to create really amazing apps (and really quickly, too). So this guide is to show you how to set them up together.

Note: This article assumes you have created a stock new ASP.NET project within Visual Studio and included MVC and WebAPI options. It also assumes you have EMBER CLI installed and have run ember new my-ember-app into a directory in the root of your ASP.NET MVC project.

@RyannosaurusRex
RyannosaurusRex / mark-required.js
Created April 29, 2015 01:20
Mark Fields as Required
// Checks an element to see if the validation says it is required
// and if so, adds a '*' to the label using the 'for' semantic attribute.
function MarkAsRequired(element) {
var req = $(element).attr('data-val-required');
if (undefined != req) {
var label = $('label[for="' + $(element).attr('id') + '"]');
var text = label.text();
if (text.length > 0) {
label.append('<span style="color:red"> *</span>');
}
@RyannosaurusRex
RyannosaurusRex / package.bat
Created October 14, 2015 18:44
Recursively package all .nuspec files in a directory from a .bat file.
@ECHO OFF
SETLOCAL
SET VERSION=%1
SET NUGET=.\BuildAndPackageSupport\nuget.exe
FOR /r %%f IN (*.nuspec) DO (
echo "packing..."
%NUGET% pack %%f -Version %VERSION%
)
@RyannosaurusRex
RyannosaurusRex / email.csx
Created November 6, 2015 18:28
Send an email using ScriptCS
// This script sends an email using ScriptCS.
// Useful as an isolated, easy to configure email sender to debug SMTP
// issues that may be hard/impossible by running your production application
// over and over just to send an email.
// More Info: http://scriptcs.net/
using System.Net.Mail;
string from = "from@address.com";
string to = "to@address.com";