Skip to content

Instantly share code, notes, and snippets.

View woodss's full-sized avatar
💭
Compiling...

Steve Woods woodss

💭
Compiling...
View GitHub Profile
@woodss
woodss / QRCodeHelper.cs
Created July 8, 2015 14:53
C# Helper for generating QR Codes using the Google Charts API
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QRCode
{
/// <summary>
/// The valid encoding options able to be passed to the QR object
@woodss
woodss / Car.cs
Created June 22, 2015 15:51
How to use Constructors and Deconstructors
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConDecon
{
class Car
{
@woodss
woodss / EmailValidation.cs
Created December 14, 2014 00:44
How to validate an e-mail address in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
namespace MailChecking
{
class Program
@woodss
woodss / IPFreely.cs
Created December 13, 2014 02:07
IPFreely - Simple C# Console Application to get IP address from an external web service
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace IPfreely
{
class Program
@woodss
woodss / TimeSpanExtensions.cs
Created December 7, 2014 16:41
TimeSpan.ToFriendlyDisplay() i.e. "10 hours, 57 minutes, 37 seconds, 44 milliseconds"
public static class TimeSpanExtensions
{
private enum TimeSpanElement
{
Millisecond,
Second,
Minute,
Hour,
Day
}
@woodss
woodss / RequiresAuthenticationAttribute.cs
Last active August 29, 2015 14:10
Custom Authentication Attributes in ASP.NET MVC
namespace YourProject.Models
{
public class RequiresAuthenticationAttribute: ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
string LoginPath = "/Login"; // Path to your login page
// Check authentication
Authentication auth = new Authentication();
@woodss
woodss / GlobalController.cs
Created December 4, 2014 12:30
Global ViewData[] Across Controllers in C# MVC
public abstract class GlobalController : Controller {
public GlobalController() {
ViewData["AvailableEverywhere"] = "This information is available throughout the application!";
}
}
/* USAGE */
public class HomeController : GlobalController {
}
@woodss
woodss / ToStringWithSuffix.cs
Created December 4, 2014 12:21
Including a Day Suffix when formatting a Date in C#
namespace System {
/// <summary>
? /// Convert a day of the month into one with a suffix attached
/// </summary>
/// <requires>
/// A string representing the correct suffix for a given day of the month
/// </requires>
public static string ToStringWithSuffix(this DateTime dt, string format) {
// The format parameter MUST contain [$suffix] within it, which will be replaced.
int day = dt.Day; string suffix = "";
@woodss
woodss / PottyMouth.cs
Created December 4, 2014 11:59
PottyMouth.cs - Very simple C# Swear Word Filter Extension Method
public static class FormattableObject
{
/// Takes a string and applies a "cleanup" filter on it.
/// Returns a Family friendly string of text with any bad words replaced with
/// the same number of characters, only as asterisks.
/// Usage: myString.ToFamilyFriendlyString()
private static List FilteredWords()
{