Skip to content

Instantly share code, notes, and snippets.

View stanroze's full-sized avatar
😵‍💫

Stan Rozenberg stanroze

😵‍💫
View GitHub Profile
@stanroze
stanroze / etree_test.go
Created June 17, 2016 01:57
Benchmarking etree
package stanza
import (
"encoding/xml"
"testing"
"github.com/ThomsonReutersEikon/etree"
)
type Email struct {
@stanroze
stanroze / queue.go
Created May 17, 2016 21:39
Blocking Queue
package queue
type Element struct {
value interface{}
next chan *Element
}
type Queue struct{
elements <-chan *Element
appender chan<- interface{}
@stanroze
stanroze / builder.cs
Created May 4, 2016 15:01
Builder pattern
public class A {
public A() {
}
}
public class B : A {
public B(string param1){
}
class Program
{
static void Main(string[] args)
{
var t = new Test();
t.Daemon();
Console.WriteLine("end main");
string input = Console.ReadLine();
while (input != "x")
@stanroze
stanroze / mergesort<T>.cs
Created July 22, 2015 15:15
Converting my integer array mergesort to a generic merge sort extension
public static class Ext
{
private class ComparableToComparer<T> : Comparer<T> where T : IComparable<T>
{
public override int Compare(T x, T y)
{
return x.CompareTo(y);
}
}
static void msort(int[] arr)
{
if (arr.Length == 1)
return;
//get a half point
int mid = arr.Length/2;
int[] left = new int[mid];
int[] right = new int[arr.Length - mid]; //reason for length - mid is due to halfpoint of an odd length array
@stanroze
stanroze / stupiddict.cs
Last active August 29, 2015 14:25
Stupid dictionary implementation. Does not resize, does not implement anything other than Add.
public class StupidDictionary<T>
{
private readonly int _numOfBuckets = 3;
private readonly bool _quiet;
private readonly int _capacity;
private int _totalCollisions;
private int[] _buckets;
private Slot[] _slots;
private int _lastIndex;
private decimal _count;
@stanroze
stanroze / reversestr.cs
Last active August 29, 2015 14:16
Reverse string in place, wouldn't work for UTF-16
public string ReverseWords(string text)
{
var tarr = text.ToCharArray();
//reverse the whole string first
reverse(tarr, 0, tarr.Length-1);
//reverse parts of the string
int start = 0;
for(int i = 0; i<tarr.Length; i++)
{
@stanroze
stanroze / Program.cs
Created April 23, 2014 14:14
simple async server and client.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
@stanroze
stanroze / TaskTimeoutExtension.cs
Last active August 29, 2015 14:00
Task with TimeOut extension.
public static class TaskExtentions
{
public static async Task<T> WithTimeout<T>(this Task<T> task, int timeout)
{
if (await Task.WhenAny(task, Task.Delay(timeout)) == task)
return await task;
return default(T);
}
}