Skip to content

Instantly share code, notes, and snippets.

View morbidcamel101's full-sized avatar
🎯
Focusing

MorbidCamel morbidcamel101

🎯
Focusing
View GitHub Profile
public class PdfFilter : Stream
{
private readonly Stream _oldFilter;
private readonly string _baseUrl;
private readonly MemoryStream _memStream;
public override bool CanSeek
{
get { return false; }
}
@morbidcamel101
morbidcamel101 / Perlin.cs
Created February 19, 2015 18:55
Perlin Noise
public class Perlin
{
// Original C code derived from
// http://astronomy.swin.edu.au/~pbourke/texture/perlin/perlin.c
// http://astronomy.swin.edu.au/~pbourke/texture/perlin/perlin.h
const int B = 0x100;
const int BM = 0xff;
const int N = 0x1000;
int[] p = new int[B + B + 2];
@morbidcamel101
morbidcamel101 / EnumLoop.cs
Created February 27, 2015 20:38
Example of how to loop an Enum
for (int index = 0; Enum.IsDefined(typeof(InteractionTypeEnum), index); index++) // Nice!
yield return new TaskItemType((InteractionTypeEnum)Enum.Parse(typeof(InteractionTypeEnum), index.ToString(CultureInfo.InvariantCulture)))
@morbidcamel101
morbidcamel101 / AsyncJsonResponse.cs
Last active August 29, 2015 14:16
Async JSON Response
public interface IResponse
{
bool IsSuccess { get; set; }
string ErrorMessage { get; set; }
}
...
public static Task<T> GetResponseAsync<T>(string url, string method = "POST") where T: IResponse, new()
{
try
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
@morbidcamel101
morbidcamel101 / ScrollExtensions.js
Created August 16, 2015 01:52
JQuery Scrolling Helpers
$.fn.scrollToY = function( target, options, callback ){
if(typeof options == 'function' && arguments.length == 2){ callback = options; options = target; }
var settings = $.extend({
scrollTarget : target,
offsetTop : 50,
duration : 500,
easing : 'swing'
}, options);
return this.each(function(){
// C# version
public static string AutoElipsis(this string text, int maxLength)
{
if (text == null || text.Length < maxLength)
return text;
return text.Substring(0, maxLength-3) + "...";
}
// JS version
@morbidcamel101
morbidcamel101 / ArraySplit.cs
Created September 2, 2015 21:43
Split Array
public static IEnumerable<T[]> Split<T>(this T[] array, int blockSize)
{
List<T> list = new List<T>();
for(int i = 0; i < array.Length; i++)
{
if (i % blockSize == 0)
{
if (list.Count > 0)
yield return list.ToArray();
list.Clear();
@morbidcamel101
morbidcamel101 / CorsModule.cs
Created November 23, 2015 16:43
Cors Module for ASP.NET MVC
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Cross-Origin Request handler.
/// </summary>
public class CorsModule : IHttpModule
{
@morbidcamel101
morbidcamel101 / CrossOriginSupportModule.cs
Created November 23, 2015 16:53 — forked from mmorton/CrossOriginSupportModule.cs
An IHttpModule for Enabling CORS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Sample
{
public class CrossOriginRequestInfo
{
public string Origin { get; set; }