Skip to content

Instantly share code, notes, and snippets.

$job = $null;
function Start-MLVPN() {
$job = Start-Job -Name "Medialab VPN" -ScriptBlock {
for(;;) {
if (-not (Test-Connection -Quiet ssaquadev01.medialab.nl)) {
rasdial "Medialab VPN" /disconnect
rasdial "Medialab VPN" marcus XXXX;
}
@mjvh80
mjvh80 / ps clean
Created August 14, 2014 11:36
PowerShell cleanup
$cleanup = {}
trap { &$cleanup; }
# do stuff
$cleanup = add-cleanop { <# delete stuff #> } $cleanup;
function add-cleanop($cleanop, $existing = {}) {
{
// Task.WaitAll(_sProcesses.Select(p => _ReadFromConsoleAsync(p)).ToArray());
private static async Task _ReadFromConsoleAsync(Process p)
{
// Starst two tasks, waiting for any to complete and restarting one that just completed for next line.
Task<String> stdoutTask, stderrTask;
using (var stdoutReader = p.StandardOutput)
using (var stderrReader = p.StandardError)
{
@mjvh80
mjvh80 / gist:6201638
Last active August 4, 2018 21:00
Dynamic Interface Implementation for C# in F#
/*
// Example usage:
var inst = _Implement.Interface<ISomeInterface>(new
{
AMethod = new Func<String, Int32>(s => Int32.Parse(s)),
Foobar = new
{
get = "foobar",
set = new Action<String>(s => {})
}