Skip to content

Instantly share code, notes, and snippets.

Amit Choudhary vendettamit

Block or report user

Report or block vendettamit

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ForEachVariations.cs
/// <summary>
/// Custom function to perform looping operation.
/// </summary>
/// <typeparam name="T">type of ienumerable</typeparam>
/// <param name="list">The list.</param>
/// <param name="action">The action.</param>
/// <returns>index value</returns>
/// <exception cref="System.ArgumentNullException"> if the supplied action is null</exception>
public static int ForEach<T>(this IEnumerable<T> list, Action<int, T> action)
{
View ApplicationLoderFromNTService.cs
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Security;
namespace Shared.ApplicationLoaderUtil
{
/// <summary>
@vendettamit
vendettamit / reflection.cs
Created May 24, 2013
Reflection miscelleneous
View reflection.cs
/// <summary>
/// Gets the error message attribute.
/// </summary>
/// <param name="memberName">Name of the member.</param>
/// <returns>
/// value of attribute from class
/// </returns>
public static string GetErrorMessageAttributeValue(string memberName)
{
string message = string.Empty;
@vendettamit
vendettamit / EventHandlerFetcher.cs
Created Jun 6, 2013
Check if the event is hooked with the Handler
View EventHandlerFetcher.cs
public static void Usage()
{
var instance = new Timer();
// check if the event is assigned a handler
if (GetEventHandler(instance, "Elapsed", "ElapsedEventHandler") == null)
{
throw new InvalidOperationException(string.Format("The Timer elapsed event must be assigned an event handler. Source: {0}", type.FullName));
}
View RhinoMockTutorialHints.txt
1. Stub() defines the behavior for stubbed object.
2. Expect() defines the behavior and the expectation for mocked object.
3. Follow the principle of "Test only one thing per test".
4. mockrepositoryObject doesn't stop recording until you call ReplayAll. Try using repositoryInstance.PlayBack();
sample:
using (repository.Playback())
{
}
5. Call repository.VerfiyAll() in the end.
@vendettamit
vendettamit / PartialDownloadController.cs
Last active Dec 18, 2015
WebApi controller to handle the single partial request for content
View PartialDownloadController.cs
using System;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Web;
using System.Web.Http;
@vendettamit
vendettamit / gist:5774450
Created Jun 13, 2013
Http client Downloader for Retry(Palmer lib)/Resume download requests enabled.
View gist:5774450
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using System.Text;
@vendettamit
vendettamit / AsyncMethodTemplate.cs
Created Jun 13, 2013
Async delegate template using tasks
View AsyncMethodTemplate.cs
/// <summary>
/// DoAsync is a method template to perform any task asynchronously.
/// </summary>
/// <typeparam name="T">type of argument</typeparam>
/// <param name="action">method</param>
/// <param name="argument">value of argument of type T</param>
public static void DoAsync<T>(Action<T> action, T argument)
{
// Invoke the task to execute the item
Task.Factory.StartNew(() => action.Invoke(argument),
View regex collections.cs
Testing websites:
http://www.regex101.com/r/yM3vL0
http://www.regexplanet.com/advanced/dotnet/index.html
UrlSourceOrLocalDriveWithRegex = @"(?i)\b^(https?|s?ftp)+:\/\/[aA-zZ]*[0-9]*|([aA-zZ]{1}:{1}\\{1}\b).*$";
Matches: Https://www.something.com, Ftp://somesource.com, sftp://securesource.com, http://moreurl.com, C:\path etc.
Unmatch: httpss://something.com, abcd://, c:, C,
SystemDriveOrUNCPathRegex = @"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*.*))+$"
Matches: c:\folder, \\server\folder
@vendettamit
vendettamit / tablemanipulator.js
Created Jul 29, 2013
Remove rowspan/colspan and split the cells with duplicate values
View tablemanipulator.js
var tempTable = $('#tbl').clone(true);
var tableBody = $(tempTable).children();
$(tableBody).children().each(function(index , item){
var currentRow = item;
$(currentRow).children().each(function(index1, item1){
if($(item1).attr("rowspan"))
{
// copy the cell
var item2 = $(item1).clone(true);
// Remove rowspan
You can’t perform that action at this time.