Skip to content

Instantly share code, notes, and snippets.

View morbidcamel101's full-sized avatar
🎯
Focusing

MorbidCamel morbidcamel101

🎯
Focusing
View GitHub Profile
@morbidcamel101
morbidcamel101 / SignatureUtil.cs
Last active August 29, 2015 14:09
.NET Signature Stream Utility class
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Signatures
{
/// <summary>
@morbidcamel101
morbidcamel101 / DrawingUtils.cs
Last active August 29, 2015 14:09
Drawing utilities. How to convert an image to a byte array
public static class DrawingUtils
{
// Extension method to convert an image into a byte array
public static byte[] ToBytes(this Bitmap image, ImageFormat imageFormat = null)
{
if (imageFormat != null)
{
using (MemoryStream stream = new MemoryStream())
@morbidcamel101
morbidcamel101 / JenkinsHash.cs
Created November 18, 2014 17:02
Jenkins Hash algorithm
public static int GetJenkinsHash(this int[] values)
{
unchecked
{
uint hash, i;
for (hash = i = 0; i < values.Length; ++i)
{
hash += (uint)(values[(int)i]);
hash += (hash << 10);
hash ^= (hash >> 6);
@morbidcamel101
morbidcamel101 / Plural.cs
Created November 18, 2014 17:10
Get a plural for the specified text. Works on 95% of english words.
public static string GetPlural(this string name)
{
if (string.IsNullOrEmpty(name))
{
return string.Empty;
}
name = name.Trim();
char lastChar = name[name.Length - 1];
switch (char.ToLower(lastChar))
{
@morbidcamel101
morbidcamel101 / LinqUtil.cs
Last active August 29, 2015 14:09
LINQ utility functions like IndexOf, ForEach, ItemAt that should have been included in LINQ
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public static class LinqUtil
{
public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T> items)
{
foreach (T item in items)
@morbidcamel101
morbidcamel101 / ServiceInstall.cs
Created November 24, 2014 15:58
Service API Calls
using System;
using System.Runtime.InteropServices;
namespace Service
{
#region Service Installer
/// <summary>
/// Windows service installer helper class.
/// </summary>
/// <remarks>
@morbidcamel101
morbidcamel101 / ServiceBoilerPlate.cs
Last active August 29, 2015 14:10
Interchangeable Service / Console app boiler plate code.
/// <summary>
/// Main entry point of the service.
/// </summary>
/// <param name="args">Arguments specified for the service.</param>
static void Main(string[] args)
{
if (args.Length > 0)
{
if (args[0].ToLower() == "/install")
{
@morbidcamel101
morbidcamel101 / 1.StandardResponse.cs
Last active August 29, 2015 14:10
JQuery MVC Standard Response Framework
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
namespace ResponseFramework
{
public interface IResponse<T>
{
@morbidcamel101
morbidcamel101 / DateExtensions.cs
Last active August 29, 2015 14:11
GMail and iCloud style Date Formatting
public enum TimeFormat
{
Auto,
IfPresent,
Always,
Today,
Never
}
public static class DateExtensions
var qsParm = new Array();
qsParm["viewMode"] = "Default";
qsParm["forMobile"] = "false";
function parseQueryString() {
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i = 0; i < parms.length; i++) {
var pos = parms[i].indexOf('=');
if (pos > 0) {