Skip to content

Instantly share code, notes, and snippets.

View jarrettmeyer's full-sized avatar

Jarrett Meyer jarrettmeyer

View GitHub Profile
using System.Web.Mvc;
using System.Web.Routing;
namespace jarrettmeyer.Web.Lib
{
public static class RouteHelpers
{
/// <summary>
/// Connects a distinct path to a controller/action.
/// </summary>
/// <summary>
/// Get all HTTP POSTed Files that were uploaded as part of a
/// multipart form POST. This abstraction keeps the controller
/// from dealing with the Request object directly.
/// </summary>
public IEnumerable<HttpPostedFileBase> HttpPostedFiles
{
get
{
// _httpContext has been pre-assigned to be the current HttpContextBase
//
// jQuery UI combobox
// Based on the combobox example on the jQuery UI home page.
// Must load both jQuery and jQuery UI Widgets before loading this document.
// I use CSS to position the button inside the input element, so it looks just
// like a drop down box.
//
$.widget("ui.combobox", {
_create: function () {
var self = this;
// Because I am an idiot and keep on using 'append', instead of 'push'.
Array.prototype.append = function (item) {
this.push(item);
return this;
};
// Returns true if the given item is contained in the array.
Array.prototype.contains = function (item) {
for (var i = 0; i < this.length; i++) {
if (this[i] == item) return true;
@jarrettmeyer
jarrettmeyer / jquery.deleteLink.js
Created December 3, 2010 15:09
jQuery deleteLink plugin
@jarrettmeyer
jarrettmeyer / jquery.buildSelectList.js
Created December 6, 2010 15:01
jQuery buildSelectList plugin
(function ($) {
$.fn.buildSelectList = function (options) {
defaults = {
url: null, // URL for the select list options.
data: null, // Data to be passed to the URL.
value: null, // Currently selected option value.
valueProperty: "value", // JSON property for option value.
textProperty: "text", // JSON property for option text.
type: "GET", // JSON HTTP method.
useCache: false, // Allow outputs to be cached.
@jarrettmeyer
jarrettmeyer / ObjectToDictionaryHelper.cs
Created January 27, 2011 15:53
C# convert an object to a dictionary of its properties
public static class ObjectToDictionaryHelper
{
public static IDictionary<string, object> ToDictionary(this object source)
{
return source.ToDictionary<object>();
}
public static IDictionary<string, T> ToDictionary<T>(this object source)
{
if (source == null)
@jarrettmeyer
jarrettmeyer / Pluralize.cs
Created August 17, 2011 17:50
Pluralization
public static class Pluralization
{
private static readonly ConcurrentDictionary<string, string> dictionary;
private static Func<string, string> defaultPluralizationRule = (s) => s.EndsWith("s") ? "es" : "s";
static Pluralization()
{
dictionary = new ConcurrentDictionary<string, string>();
}
@jarrettmeyer
jarrettmeyer / email_validation.cs
Created May 16, 2012 12:05
Email validation - the point is to show that the extension method doesn't actually do anything. The real logic is in the validator class.
public class EmailValidator
{
private const string PATTERN = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$";
public static bool IsValid(string s)
{
if (string.IsNullOrEmpty(s))
return false;
// Regex from http://www.regular-expressions.info/email.html
@jarrettmeyer
jarrettmeyer / Gemfile.lock
Created May 24, 2012 13:40
working Gemfile.lock for Octopress issue 578
GEM
remote: http://rubygems.org/
specs:
RedCloth (4.2.9)
albino (1.3.3)
posix-spawn (>= 0.3.6)
blankslate (2.1.2.4)
chunky_png (1.2.5)
classifier (1.3.3)
fast-stemmer (>= 1.0.0)