Skip to content

Instantly share code, notes, and snippets.

@putridparrot
putridparrot / ThrottleWithBuffer.cs
Last active June 18, 2023 22:03
Extension to RX to add Throttling with a buffer
/*
* This code is licensed under the terms of the MIT license
*/
public static IObservable<TSource[]> ThrottleWithBuffer<TSource>(
this IObservable<TSource> source, TimeSpan timeout)
{
return source.ThrottleWithBuffer(timeout, TaskPoolScheduler.Default);
}
@putridparrot
putridparrot / MemoryInformation.cs
Created March 16, 2015 10:40
C# class to get a processes memory usage
public class MemoryInformation
{
[DllImport("KERNEL32.DLL")]
private static extern int OpenProcess(uint dwDesiredAccess, int bInheritHandle, uint dwProcessId);
[DllImport("KERNEL32.DLL")]
private static extern int CloseHandle(int handle);
[StructLayout(LayoutKind.Sequential)]
private class PROCESS_MEMORY_COUNTERS
{
@putridparrot
putridparrot / gist:0425fc9f8d88ee7ffac1
Created March 13, 2015 10:58
Change text within an xml document
// takes a string representing the XML and allows us to find a node and change the inner text, also shows
// how to set-up namespaces (note: For simplicity there's No error handling in this sample)
let changeValue xmlData =
let nameTable = NameTable()
let namespaceManager = XmlNamespaceManager(nameTable)
namespaceManager.AddNamespace("soap", "http://www.w3.org/2003/05/soap-envelope")
let xml = XmlDocument()
xml.LoadXml xmlData
let current = xml.SelectSingleNode("//soap:Envelope/soap:Body/someElement", namespaceManager)
@putridparrot
putridparrot / gist:39c1e173fbeec4aa92aa
Last active August 29, 2015 14:17
F# sample of POST-ing data to a web service
let readFile (filename : string) =
use sr = new StreamReader(filename)
Encoding.ASCII.GetBytes(sr.ReadToEnd())
[<EntryPoint>]
let main argv =
let byteArray = readFile argv.[0]
let request = WebRequest.Create("http://some-url:8080/MyService")
public class DelayBindingExtension : BindingBaseExtension
{
public DelayBindingExtension()
{
}
public DelayBindingExtension(PropertyPath path)
: base(path)
{
}
@putridparrot
putridparrot / BindingBaseExtension
Created February 19, 2015 11:31
Abstract class for implementing custom binding code (see http://putridparrot.com/blog/custom-binding-markupextension/)
[MarkupExtensionReturnType(typeof(object))]
public abstract class BindingBaseExtension : MarkupExtension
{
protected BindingBaseExtension()
{
}
protected BindingBaseExtension(PropertyPath path)
{
Path = path;
@putridparrot
putridparrot / getDirectories
Created February 17, 2015 21:09
F# functions to get directories all directories within a given path
let rec getDirectories' (di: DirectoryInfo) =
seq {
yield di
for sd in di.GetDirectories() do
yield! getDirectories' sd
}
let getDirectories path =
let di = new DirectoryInfo(path)
if not di.Exists then