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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / character_swapping.py
Created January 4, 2013 03:40
Algorithms - Character Swapping
def CharacterSwap(inputString):
middle = len(inputString)/2
length = len(inputString)
inputList = list(inputString)
for i in range(middle):
temp = inputList[i]
inputList[i] = inputList[length - 1 -i]
inputList[length -1-i] = temp
return ''.join(inputList)