Skip to content

Instantly share code, notes, and snippets.

View bezzad's full-sized avatar
:octocat:
Hi

Behzad Khosravifar bezzad

:octocat:
Hi
View GitHub Profile
using System;
using System.IO;
using System.Threading;
using System.Diagnostics;
namespace Born2Code.Net
{
/// <summary>
/// Class for streaming data with throttling support.
/// </summary>
@kristopherjohnson
kristopherjohnson / SHA1Util.cs
Last active October 1, 2020 22:18
.NET/C# Generate SHA1 hex string for a string encoded as UTF8
using System.Security.Cryptography;
using System.Text;
namespace Snippets
{
public static class SHA1Util
{
/// <summary>
/// Compute hash for string encoded as UTF8
/// </summary>
@cuppster
cuppster / 1.cs
Created September 3, 2012 18:39
Promises for C# using Generics
/*
modified from original source: https://bitbucket.org/mattkotsenas/c-promises/overview
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Promises
@mauricedb
mauricedb / gist:5356933
Last active August 16, 2021 16:54
Return JSON data in a camelCase format from an ASP.NET WebAPI controller.
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
@cairey
cairey / VSSolutionInspection.tt
Created May 1, 2013 15:05
Inspect the Visual Studio solution and project settings using T4 template code gen.
<#@ template language="C#" debug="true" hostSpecific="true" #>
<#@ output extension=".cs" #>
<#@ Assembly Name="System.Core.dll" #>
<#@ assembly name="EnvDTE" #>
<#@ Assembly Name="System.Windows.Forms.dll" #>
<#@ Assembly name="System.Configuration"#>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Linq" #>
@cairey
cairey / gist:5501024
Last active August 20, 2021 12:07
Programmatically start IIS Express from code.
public static class IISExpress
{
private static readonly List<string> sites = new List<string>();
private static readonly List<string> paths = new List<string>();
public static void StartIISExpress(string site, int port = 7329)
{
if(!sites.Contains(site.ToLower()))
sites.Add(site.ToLower());
else return;
@andrewdavey
andrewdavey / app.ts
Created October 20, 2013 17:38
Example AngularJS application using TypeScript
/// <reference path="angular.d.ts"/>
class KittenController {
constructor(
private $scope: ng.IScope,
private debounce: IDebounce
) {
this.watchForSizeChanges();
}
@jogleasonjr
jogleasonjr / SlackClient.cs
Last active October 20, 2023 15:54
A simple C# class to post messages to a Slack channel. You must have the Incoming WebHooks Integration enabled. This class uses the Newtonsoft Json.NET serializer available via NuGet. Scroll down for an example test method and a LinqPad snippet. Enjoy!
using Newtonsoft.Json;
using System;
using System.Collections.Specialized;
using System.Net;
using System.Text;
//A simple C# class to post messages to a Slack channel
//Note: This class uses the Newtonsoft Json.NET serializer available via NuGet
public class SlackClient
{
@deanhume
deanhume / Bundle Extension
Last active December 29, 2016 05:54
An ASP.NET MVC bundle extension file to handle optional HTML attributes such as async, defer, and media for CSS links.
namespace Optimization.Custom
{
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
/// <summary>
@lmauri
lmauri / PromiseDeferredCSharp
Created February 19, 2014 11:15
Implementation of Promise/Deferred pattern with C#
public interface IPromise
{
/// <summary>
/// Attaches a callback to be executed when the Deferred is resolved
/// </summary>
IPromise Done(Action callback);
/// <summary>
/// Attaches a callback to be executed when the Deferred is rejected
/// </summary>
IPromise Fail(Action<Exception> callback);