Skip to content

Instantly share code, notes, and snippets.

View gogsbread's full-sized avatar

Antony Thomas gogsbread

  • facebook
  • San Francisco Bay area,CA
View GitHub Profile
@gogsbread
gogsbread / learn_io.py
Created January 4, 2013 05:05
IO operations in python. Read and sum values in a file. Good practice problem for learning basic IO operations in python
def Sum(filePath):
total = 0
with open(filePath,'rU') as f:
line = f.readline()
while(line != ''):
value = int(line)
total+=value
line = f.readline()
return total
@gogsbread
gogsbread / numerical_algorithms.cs
Created January 4, 2013 05:21
Basic numerical algorithms IsPrime(n) and ToBinary(n) where n is Integer.
using System;
using System.Collections.Generic;
namespace RandomMusings
{
public class NumericalAlgorithms
{
static void Main(){
/*Console.WriteLine(IsPrime(13));
Console.WriteLine(IsPrime(7));
@gogsbread
gogsbread / binary_adder.py
Created January 5, 2013 04:48
Practical algorithms - Binary adder
def binaryAdder(arrayA,arrayB):
arrayC = [0] * (len(arrayA) + 1)
carry = 0
for i in range(len(arrayA)-1,-1,-1):
eA = arrayA[i]
eB = arrayB[i]
if eA == eB == 1:
if carry == 1:
arrayC[i+1] = 1
else:
@gogsbread
gogsbread / DetectPalidrome.cs
Created January 5, 2013 05:11
Interesting Algorithm - Detect if a string is Palindrome IsPaliDrome()
using System;
using System.Text.RegularExpressions;
namespace RandomMusings
{
public class DetectPalidrome
{
public DetectPalidrome ()
{
}
@gogsbread
gogsbread / EventDelegate.cs
Created January 5, 2013 05:22
Practical Event Delegate examples
using System;
namespace RandomMusings
{
public class Hospital
{
public event AlarmHandler Alarm;
public delegate void AlarmHandler(string message);
public Hospital ()
{
@gogsbread
gogsbread / FunctionPointers.cs
Created January 5, 2013 05:23
A poor mock of function pointers in c#
#define DEBUG
using System;
using System.Diagnostics;
namespace RandomMusings
{
public class FunctionPointers
{
public static Func<int,int[],int> Summer(Func<int,int,int> sumFunction)
@gogsbread
gogsbread / NonOverlapping.cs
Created January 5, 2013 05:28
Non-Overlapping algorithm
using System;
using System.Collections.Generic;
namespace RandomMusings
{
public struct Range
{
public int start;
public int end;
@gogsbread
gogsbread / VisualStudioMEF.cs
Created January 5, 2013 05:31
Demonstrating MEF through the plight of Visual Studio extensions
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
namespace RandomMusings
{
public interface IVSFeature
{
string Feature{get;}
@gogsbread
gogsbread / UnorderedSet.cs
Created January 5, 2013 05:32
UnorderedSet
using System;
using System.Collections.Generic;
namespace RandomMusings
{
public class UnOrderedSet:IEnumerable<int>
{
Dictionary<int,int> _set = null;
public UnOrderedSet ()
@gogsbread
gogsbread / SortTester.cs
Last active December 11, 2015 17:08
Testing Sort algorithms -Insertion & Quicksort . Tested with Sorted,ReverseSorted and Random suites of n=2^3 to 2^8. Results show that insertionsort beats quicksort for lower n and things change between n = 64 to 256
/*
Testing Sort algorithms -Insertion & Quicksort . Tested with Sorted,ReverseSorted and Random suites of n=2^3 to 2^8. Results show that insertionsort beats quicksort for lower n and things change between n = 64 to 256
---Testing with n=8---
QuickSort(sorted,reversesorted,random): 5322 11 6
InsertionSort(sorted,reversesorted,random): 1745 4 3
---Testing with n=16---
QuickSort(sorted,reversesorted,random): 30 19 19
InsertionSort(sorted,reversesorted,random): 13 11 8