Skip to content

Instantly share code, notes, and snippets.

@sri-prasanna
sri-prasanna / MaxSubArray.cs
Created January 19, 2016 21:42
Divide and Conquer solution for MaxSubArray problem.
void Main()
{
// divide and conquer algorithm
// var A = new int [] {13, -3, -25, 20, -3, -16, -23, 18, 20, -7, 12, -5, -22, 15, -4, 7};
// var A = new int [] {-3, -25, -3, -16, -23, -7, -5, 22, -4};
var A = new int [] {12, -2};
var result = new int [3];
result = FindMaxSubArray(A, 0, A.Length - 1);
Console.WriteLine( result );
}
void InsertionSort(int [] A, int n)
{
int curr = A[n];
if (n != 0)
InsertionSort(A, (n-1));
PushIntoItsSpot(A, curr, (n-1));
}
void PushIntoItsSpot(int [] A, int val, int rpos)
{
while(rpos >= 0 && A[rpos] > val)
@sri-prasanna
sri-prasanna / PartOfZipFile.cs
Last active August 29, 2015 13:56
ZipFile.Delete on a folder entry fails #48
...
...
...
...
int FindExistingUpdate(ZipEntry entry)
{
int result = -1;
string convertedName = GetTransformedFileName(entry.Name);
if (updateIndex_.ContainsKey(convertedName))
@sri-prasanna
sri-prasanna / TestAssumptionAttribute.cs
Last active December 31, 2015 20:09
A very simple attribute that can be used to record assumptions (if any) for any nunit based tests; after adding this attribute with some assumption text, when the concerned nunit test is run. the assumption text is displayed in the console..
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true) ]
public class TestAssumptionAttribute : TestActionAttribute
{
private readonly string assumption;
public TestAssumptionAttribute(string assumption)
{
this.assumption = assumption;
}
public override void BeforeTest(TestDetails testDetails)
{
@sri-prasanna
sri-prasanna / powershell-samples-01.ps1
Last active December 19, 2015 09:59
A collection of powershell scripts that I create..
#script to list all eventlog entries with a specific text in the description
$regex_to_match=".*RoutingExtensions.*"
Get-EventLog -LogName "Application" | Where-Object {$_.Message -match $regex_to_match} | format-list -Property Source,EntryType,Message,TimeWritten
#filter eventlog entries based on date and regular expression
$regex_to_match=".*DfpLibrary.*"
$dateVal = (get-date 2013-07-01)