Skip to content

Instantly share code, notes, and snippets.

View ChocoSmith's full-sized avatar

Lachlan Smith ChocoSmith

View GitHub Profile
@ChocoSmith
ChocoSmith / CompressionSQL_CLR
Last active August 29, 2015 14:19
UTF8 Compression C# and MsSql Clr
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlString Unzip(byte[] zipBytes, string encoding)
{
using (MemoryStream inputStream = new MemoryStream(zipBytes))
{
using (DeflateStream deflateStream = new DeflateStream(inputStream, CompressionMode.Decompress))
{
using (StreamReader reader = new StreamReader(deflateStream, System.Text.Encoding.GetEncoding(encoding)))
{
return new SqlString(reader.ReadToEnd());
Things to think about
Columns over 8000 character in total cannot be reindex without taking the table off line.
In our studies compression saved close to 70% versus not compressing
Xml can easily be used (replace the ISerilize implementation JsonSerialize with a XmlSerializer
public static class ConfigurationManagerExtension
{
public static int GetFromConfigurationFileWithDefaultHandling(string setting, int defaultIfNotFound)
{
try
{
var status = ConfigurationManager.AppSettings[setting];
int result;
if (int.TryParse(status, out result))
return result;
@ChocoSmith
ChocoSmith / BasicHttpAuthentication
Last active August 29, 2015 14:06
MVC/Web api Http authentication using basic authentication.
Simple MVC/WebApi authentication model using json authentication schema basic.
Simply create the files below to use and you are good to go. The only TODO section is the user and database call
Have provided a unit test to show the conversion to and from base 64 strings (json standard)
Also a example echo controller
@ChocoSmith
ChocoSmith / ISerialize
Created August 7, 2014 08:26
Serialization
public interface ISerialize
{
string Serialize<T>(T data, bool prettyPrint = false);
}
@ChocoSmith
ChocoSmith / HttpClient.cs
Last active August 29, 2015 14:02
Json HttpClient force Ensure and aggregate exception handling
using System;
using System.Net.Http.Headers;
namespace Choco.Common
{
public interface IHttpClient
{
string Post(Uri requestUri, string data, AuthenticationHeaderValue authenticationHeader, string applicationType);
string Get(Uri requestUri);
}
using System;
using System.Text;
using System.Web;
using NLog;
namespace Choco.Shared.Web.App_Start
{
public class LogSoapModule : IHttpModule
{
public void Init(HttpApplication context)