Skip to content

Instantly share code, notes, and snippets.

@rymoore99
rymoore99 / fiddle.html
Last active August 29, 2015 13:56
Function for creating a namespace equivalent in Javascript
<div id='result'></div>
@rymoore99
rymoore99 / HtmlHelperExtensions.cs
Created February 19, 2014 13:08
Helper method for serializing objects to JSON in Razor Views
public static class HtmlHelperExtensions
{
public static MvcHtmlString SerializeToJson(this HtmlHelper helper, string javascriptVariableName,
object objectToSerialize)
{
if (javascriptVariableName.Contains(" "))
throw new Exception("Invalid JS variable name");
return
MvcHtmlString.Create(String.Format("var {0}={1};", javascriptVariableName,
@rymoore99
rymoore99 / SendGridExample.cs
Last active September 6, 2016 18:16
Quick Example of how easy it is to send mail using SendGrid
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using SendGridMail;
public class SendGridEmailService
{
public bool Send(string toAddress, string fromAddress, string fromAddressAlias, string subject, string body)
@rymoore99
rymoore99 / StringExtension.cs
Last active August 29, 2015 13:56
Extension method to truncate a string to the last space after a specified length
public static class StringExtension
{
public static string SplitByCaps(this string value)
{
var r = new Regex(@"
(?<=[A-Z])(?=[A-Z][a-z]) |
(?<=[^A-Z])(?=[A-Z]) |
(?<=[A-Za-z])(?=[^A-Za-z])", RegexOptions.IgnorePatternWhitespace);
return r.Replace(value, " ");
@rymoore99
rymoore99 / IEnumerableExtension.cs
Last active August 29, 2015 13:56
IEnumerable Paging Extension
// Usage: myCollection.Page(pageNumber, pageSize);
public static class IEnumerableExtension {
public static IEnumerable<T> Page<T>(this IList<T> source, int pageNumber, int pageSize)
{
return source.Skip((pageNumber - 1) * pageSize).Take(pageSize);
}
}