Skip to content

Instantly share code, notes, and snippets.

View mlaily's full-sized avatar

Melvyn Laïly mlaily

View GitHub Profile
@mlaily
mlaily / ToHumanReadableString.cs
Last active January 12, 2018 12:08
Convert a length in bytes to a human readable string with the appropriate unit.
//we can't shift more than 63 bits with a long, so we would need a big int to support ZB and YB...
static readonly string[] units = new string[] { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB" };
/// <summary>
/// Supports any non negative value up to long.MaxValue (~8EB)
/// </summary>
public static string ToHumanReadableString(long length)
{
if (length < 0) throw new ArgumentOutOfRangeException("length", "length cannot be negative!");
long shiftResult = 0;
long previousShiftResult = 0;
@mlaily
mlaily / NativeMembers.cs
Last active November 28, 2023 06:05
Find which process have a file opened using the Restart Manager API
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
// ReSharper disable InconsistentNaming
namespace RestartManager
#!/bin/bash
echo "Comparing current with remote:"
echo
git fetch --dry-run --prune
echo
read -p "Press enter to fetch the changes and prune the deleted branches..."
echo
git fetch --prune
echo
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp
{
    public static class Combinations
    {
        public static IEnumerable<IReadOnlyList<T>> GetAllCombinations<T>(IEnumerable<T> set, int combinationLength)
/*
* OutlookDataObject - Drag and drop of outlook messages and attachments - http://www.iwantedue.com
* Copyright (C) 2008 David Ewen
*
* Patched to take into account most of the remarks from the original project comments...
*
* == BEGIN LICENSE ==
*
* Licensed under the terms of following license:
*

Keybase proof

I hereby claim:

  • I am mlaily on github.
  • I am mlaily (https://keybase.io/mlaily) on keybase.
  • I have a public key whose fingerprint is FA26 96FF E5BB A99A FB01 0AF5 3A2E D6B3 9BAF 5555

To claim this, I am signing this object:

@mlaily
mlaily / RedirectingHandler.cs
Created November 22, 2020 18:24 — forked from joelverhagen/RedirectingHandler.cs
RedirectingHandler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace Knapcode.Http.Handlers
{