Skip to content

Instantly share code, notes, and snippets.

View shawnmclean's full-sized avatar
🐭
:)

Shawn Mclean shawnmclean

🐭
:)
View GitHub Profile
@shawnmclean
shawnmclean / dynamicvalidation.html
Created August 10, 2011 04:11
Unobtrusive jquery validation with dynamic content in ASP.NET MVC
@using (Html.BeginForm())
{
<div id="RegBox" style="display: none;">
@Html.LabelFor(m => Model.Name)
@Html.TextBoxFor(m => Model.Name)
@Html.ValidationMessageFor(m => m.Name)
</div>
<div id="LoginBox">
@Html.LabelFor(m => Model.Email)
@shawnmclean
shawnmclean / convas2img.htm
Created August 23, 2011 00:43
Convert A canvas to image
<canvas id="MyCanvas" width="300" height="300">
</canvas>
<img id="MyImg"/>
<script>
function drawAndConvertStuff(canvas) {
var canvasContext = canvas.getContext('2d');
//draw a black box
@shawnmclean
shawnmclean / CountSorted.cs
Created November 13, 2011 23:20
Count Sorted Array
public static int CountSorted<T>(this List<T> list, T item) where T : IComparable
{
//find random index of the item
int index = list.BinarySearch(item);
//if item isn't found, just return -1
if (index < 0)
return -1;
@shawnmclean
shawnmclean / FormsAuthenticationService.cs
Created January 12, 2012 19:48
FormsAuthentication custom user data
public class FormsAuthenticationService : IFormsAuthenticationService
{
public void SignIn(UserIdentity user, bool createPersistentCookie)
{
//UserData is stored as json
string userData = JsonSerializer.SerializeToString<UserIdentity>(user);
FormsAuthenticationTicket authTicket = new
FormsAuthenticationTicket(1, //version
user.UserId.ToString(), // user name
@shawnmclean
shawnmclean / CustomIdentity.cs
Created January 12, 2012 19:53
Custom user data for asp.net forms authentication
/// <summary>
/// Extra user custom data
/// </summary>
public class UserIdentity
{
public int UserId { get; set; }
public string Username { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
@shawnmclean
shawnmclean / IdentityExtensions.cs
Created January 12, 2012 19:58
Custom Identity extention
public static class IdentityExtensions
{
public static CustomIdentity ToCustomIdentity(this IIdentity identity)
{
return (CustomIdentity) identity;
}
}
@shawnmclean
shawnmclean / layout.cshtml
Created January 12, 2012 20:01
Using the Custom Identity
Welcome back @(User.Identity.ToCustomIdentity().FirstName) @(User.Identity.ToCustomIdentity().LastName)
@shawnmclean
shawnmclean / img2canvas.html
Created February 8, 2012 01:41
Convert A canvas to image
<h2>Canvas to image</h2>
<canvas id="MyCanvas" width="300" height="300">
</canvas>
<img id="MyImg"/>
<script>
function drawAndConvertStuff(canvas) {
@shawnmclean
shawnmclean / gist:1937486
Created February 29, 2012 03:56 — forked from anonymous/gist:1937453
a guest on Feb 28th, 2012 - pastebin.com/5ciDhb6V
myObj = this;
someMethod = function(){
myObj.myProp;
}
@shawnmclean
shawnmclean / activity.js
Created March 3, 2012 20:41
Initializing an Activity.js module
var awayCallback = function(){
console.log(new Date().toTimeString() + ": away");
};
var awayBackCallback = function(){
console.log(new Date().toTimeString() + ": back");
};
var activity = new Activity({
onAway: awayCallback,