Skip to content

Instantly share code, notes, and snippets.

View hclewk's full-sized avatar

Kurtis Welch hclewk

View GitHub Profile
@hclewk
hclewk / gzip.cs
Created December 31, 2016 18:05
Upload GZipped String to S3 - Fire and Forget
AmazonS3Client client = new AmazonS3Client(RegionEndpoint.USWest2);
MemoryStream mem = new MemoryStream();
using (GZipStream gz = new GZipStream(mem, CompressionLevel.Optimal, true))
{
var b = Encoding.UTF8.GetBytes(json);
gz.Write(b, 0, b.Length);
gz.Flush();
}
@hclewk
hclewk / HashUtil.cs
Created December 31, 2016 18:05
Get MD5 Hash
public static string GetHash(string str)
{
using (var md5 = MD5.Create())
{
return BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(str))).Replace("-", "").ToLower();
}
}
@hclewk
hclewk / HashtagUtil.cs
Created December 31, 2016 18:03
Turn any string into a hashtag in c#
//Input: "St. Patrick's Day: Awësöme tö-dö's"
//Output: "#StPatricksDayAwesomeToDos"
public static string MakeHashtag(string text)
{
text = RemoveDiacritics(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text));
text = Regex.Replace(text, @"[^a-zA-Z0-9]", "");
return "#" + text;
}
@hclewk
hclewk / Email.cs
Created December 31, 2016 18:01
Send Email from Gmail
public class Email
{
public string Subject { get; set; }
public string Body { get; set; }
public string To { get; set; }
public string From { get; set; }
public Email()
{
@hclewk
hclewk / ToDictionary.cs
Created December 31, 2016 18:00
Turn Anonymous Object into a Dictionary<string, string>
public static Dictionary<string, string> ToDictionary(this object values)
{
var result = new Dictionary<string, string>();
var type = values.GetType();
var properties = type.GetProperties();
foreach (var property in properties)
{
var name = property.Name;
var value = property.GetValue(values);
/// <summary>
/// Class used for conversion between byte array and Base32 notation
/// </summary>
internal sealed class Base32
{
/// <summary>
/// Size of the regular byte in bits
/// </summary>
private const int InByteSize = 8;