Skip to content

Instantly share code, notes, and snippets.

View jchandra74's full-sized avatar

Jimmy Chandra jchandra74

  • Sydney, NSW, Australia
View GitHub Profile
@jchandra74
jchandra74 / fingerprint.cs
Last active August 29, 2015 14:17
asp.net good config and practices
//Stolen from @mkristensen
//Use to bust static content like .js and .css when they changed.
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Web.Hosting;
namespace CHANGE_YOUR_NAMESPACE_HERE
{
public class Fingerprint
@jchandra74
jchandra74 / ObjectCopier.cs
Created April 13, 2015 23:52
Object Deep Copy via Serialization
namespace __NAMESPACE__
{
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public static class ObjectCopier
{
/// <summary>
@jchandra74
jchandra74 / GenericCollectionExtensions.cs
Created April 14, 2015 00:00
Generic LINQ Extension
namespace __NAMESPACE__
{
using System.Linq;
using System.Collections.Generic;
/// <summary>
/// Check if expected list items are all in master list
/// </summary>
/// <typeparam name="T">Generic Type</typeparam>
namespace __NAMESPACE__
{
using System.IO;
public static class StreamExtension
{
public static byte[] ToByteArray(this Stream input)
{
using (var memStream = new MemoryStream())
{
@jchandra74
jchandra74 / ObjectSerializer.cs
Created April 14, 2015 00:07
Serialization Helper
namespace __NAMESPACE__
{
using System;
using System.IO;
using System.Xml;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using Newtonsoft.Json;
using JsonSerializer = ServiceStack.Text.JsonSerializer;
using XmlSerializer = System.Xml.Serialization.XmlSerializer;
@jchandra74
jchandra74 / StringExtension.cs
Created April 14, 2015 00:10
String Helper
namespace __NAMESPACE__
{
using System.Text;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
public static class StringExtension
{
public static string StripInvalidUnicodeCharacters(this string str)
{
@jchandra74
jchandra74 / binary2hex.cs
Created April 14, 2015 00:12
Binary to Hex String Conversion
public static string BinaryToHex(byte[] data)
{
if (data == null)
{
return null;
}
var array = new char[checked(data.Length*2)];
for (var i = 0; i < data.Length; i++)
{
@jchandra74
jchandra74 / SHA1Util.cs
Last active April 3, 2019 17:20 — forked from kristopherjohnson/SHA1Util.cs
SHA1 Hash for Unicode string
//Forked from kristopherjohnson/SHA1Util.cs gist
using System.Security.Cryptography;
using System.Text;
namespace Snippets
{
public static class SHA1Util
{
/// <summary>
/// Compute hash for string encoded as UTF8
@jchandra74
jchandra74 / FileUtil.cs
Last active April 27, 2024 04:08
Detect MimeType and File Extension based on filename and falling back to fileStream for signature detection (specific to .binary extension)
//mimetypes: http://www.sitepoint.com/web-foundations/mime-types-complete-list/
//https://technet.microsoft.com/en-us/library/ee309278(office.12).aspx
public static class FileUtil
{
public static string DetectFileType(string filename, Stream fileStream)
{
var ext = Path.GetExtension(filename);
if (string.IsNullOrEmpty(ext))
{
@jchandra74
jchandra74 / index.html
Last active April 27, 2024 04:08
Angular Speech API Times Table Quiz for Kids
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
<link data-require="[email protected]" data-semver="3.3.6" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css" />
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container" ng-app="app" ng-controller="pageCtrl as page">